Boost C++ Libraries

PrevUpHomeNext

Class template mutable_constant

boost::log::attributes::mutable_constant — A class of an attribute that holds a single constant value with ability to change it.

Synopsis

// In header: <boost/log/attributes/mutable_constant.hpp>

template<typename T, typename MutexT = void, typename ScopedWriteLockT = void, 
         typename ScopedReadLockT = ScopedWriteLockT> 
class mutable_constant : public attribute {
public:
  // types
  typedef MutexT           mutex_type;         // Mutex type. 
  typedef ScopedReadLockT  scoped_read_lock;   // Shared lock type. 
  typedef ScopedWriteLockT scoped_write_lock;  // Exclusive lock type. 
  typedef T                held_type;          // A held constant type. 

  // construct/copy/destruct
  explicit mutable_constant(held_type const &);

  // public member functions
  shared_ptr< attribute_value > get_value();
  void set_value(held_type const &);
};

Description

The mutable_constant attribute stores a single value of type, specified as the first template argument. A copy of this value is returned on each attribute value acquision.

The attribute also allows to modify the stored value, even if the attibute is registered in an attribute set. In order to ensure thread safety of such modifications the mutable_constant class is also parametrized with three additional template arguments: mutex type, scoped write and scoped read lock types. By default no synchronization is done.

mutable_constant public construct/copy/destruct

  1. explicit mutable_constant(held_type const & value);

    Constructor with the stored value initialization

mutable_constant public member functions

  1. shared_ptr< attribute_value > get_value();

    The method returns the actual attribute value. It shall not return NULL. The implementation acquires a shared lock of the mutex in order to protect the copying of the stored object into the attribute value.

  2. void set_value(held_type const & v);

    The method sets a new attribute value. The implementation exclusively locks the mutex in order to protect the value assignment.


PrevUpHomeNext