Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
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 = auto, 
         typename ScopedReadLockT = auto> 
class mutable_constant : public attribute {
public:
  // types
  typedef T value_type;  // The attribute value type. 

  // member classes/structs/unions

  // Factory implementation.

  class impl : public attribute::impl {
  public:
    // construct/copy/destruct
    explicit impl(value_type const &);
    explicit impl(value_type &&);

    // public member functions
    virtual attribute_value get_value();
    void set(value_type const &);
    void set(value_type &&);
    value_type get() const;
  };

  // construct/copy/destruct
  explicit mutable_constant(value_type const &);
  explicit mutable_constant(value_type &&);
  explicit mutable_constant(cast_source const &);

  // public member functions
  void set(value_type const &);
  void set(value_type &&);
  value_type get() const;

  // protected member functions
  impl * get_impl() const;
};

Description

The mutable_constant attribute stores a single value of type, specified as the first template argument. This value is returned on each attribute value acquisition.

The attribute also allows to modify the stored value, even if the attribute 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. If not specified, the lock types are automatically deduced based on the mutex type.

The implementation may avoid using these types to actually create and use the mutex, if a more efficient synchronization method is available (such as atomic operations on the value type). By default no synchronization is done.

mutable_constant public construct/copy/destruct

  1. explicit mutable_constant(value_type const & value);

    Constructor with the stored value initialization

  2. explicit mutable_constant(value_type && value);

    Constructor with the stored value initialization

  3. explicit mutable_constant(cast_source const & source);

    Constructor for casting support

mutable_constant public member functions

  1. void set(value_type const & value);

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

  2. void set(value_type && value);

    The method sets a new attribute value.

  3. value_type get() const;

    The method acquires the current attribute value. The implementation non-exclusively locks the mutex in order to protect the value acquisition.

mutable_constant protected member functions

  1. impl * get_impl() const;

    Returns:

    Pointer to the factory implementation


PrevUpHomeNext