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 for the latest Boost documentation.
PrevUpHomeNext

Class attribute_set

boost::log::attribute_set — An attribute set class.

Synopsis

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


class attribute_set {
public:
  // types
  typedef attribute_name                           key_type;         // Key type. 
  typedef attribute                                mapped_type;      // Mapped attribute type. 
  typedef std::pair< const key_type, mapped_type > value_type;       // Value type. 
  typedef value_type &                             reference;        // Reference type. 
  typedef value_type const  &                      const_reference;  // Const reference type. 
  typedef value_type *                             pointer;          // Pointer type. 
  typedef value_type const  *                      const_pointer;    // Const pointer type. 
  typedef std::size_t                              size_type;        // Size type. 
  typedef std::ptrdiff_t                           difference_type;  // Difference type. 
  typedef implementation_defined                   iterator;       
  typedef implementation_defined                   const_iterator; 

  // construct/copy/destruct
  attribute_set();
  attribute_set(attribute_set const &);
  attribute_set(attribute_set &&) noexcept;
  attribute_set & operator=(attribute_set) noexcept;
  ~attribute_set();

  // public member functions
  void swap(attribute_set &) noexcept;
  iterator begin() noexcept;
  iterator end() noexcept;
  const_iterator begin() const noexcept;
  const_iterator end() const noexcept;
  size_type size() const noexcept;
  bool empty() const noexcept;
  iterator find(key_type) noexcept;
  const_iterator find(key_type) const noexcept;
  size_type count(key_type) const noexcept;
  unspecified operator[](key_type) noexcept;
  mapped_type operator[](key_type) const noexcept;
  std::pair< iterator, bool > insert(key_type, mapped_type const &);
  std::pair< iterator, bool > insert(const_reference);
  template<typename FwdIteratorT> void insert(FwdIteratorT, FwdIteratorT);
  template<typename FwdIteratorT, typename OutputIteratorT> 
    void insert(FwdIteratorT, FwdIteratorT, OutputIteratorT);
  size_type erase(key_type) noexcept;
  void erase(iterator) noexcept;
  void erase(iterator, iterator) noexcept;
  void clear() noexcept;
};

Description

An attribute set is an associative container with attribute name as a key and pointer to the attribute as a mapped value. The container allows storing only one element for each distinct key value. In most regards attribute set container provides interface similar to std::unordered_map. However, there are differences in operator[] semantics and a number of optimizations with regard to iteration. Besides, attribute names are stored as a read-only attribute_name's instead of std::string, which saves memory and CPU time.

attribute_set public types

  1. typedef implementation_defined iterator;

    Iterator type. The iterator complies to the bidirectional iterator requirements.

  2. typedef implementation_defined const_iterator;

    Constant iterator type. The iterator complies to the bidirectional iterator requirements with read-only capabilities.

attribute_set public construct/copy/destruct

  1. attribute_set();

    Default constructor.

    Postconditions:

    empty() == true

  2. attribute_set(attribute_set const & that);

    Copy constructor.

    Postconditions:

    size() == that.size() && std::equal(begin(), end(), that.begin()) == true

  3. attribute_set(attribute_set && that) noexcept;

    Move constructor

  4. attribute_set & operator=(attribute_set that) noexcept;

    Copy assignment operator.

    Postconditions:

    size() == that.size() && std::equal(begin(), end(), that.begin()) == true

  5. ~attribute_set();

    Destructor. All stored references to attributes are released.

attribute_set public member functions

  1. void swap(attribute_set & that) noexcept;

    Swaps two instances of the container.

    Throws: Nothing.

  2. iterator begin() noexcept;

    Returns:

    Iterator to the first element of the container.

  3. iterator end() noexcept;

    Returns:

    Iterator to the after-the-last element of the container.

  4. const_iterator begin() const noexcept;

    Returns:

    Constant iterator to the first element of the container.

  5. const_iterator end() const noexcept;

    Returns:

    Constant iterator to the after-the-last element of the container.

  6. size_type size() const noexcept;

    Returns:

    Number of elements in the container.

  7. bool empty() const noexcept;

    Returns:

    true if there are no elements in the container, false otherwise.

  8. iterator find(key_type key) noexcept;

    The method finds the attribute by name.

    Parameters:

    key

    Attribute name.

    Returns:

    Iterator to the found element or end() if the attribute with such name is not found.

  9. const_iterator find(key_type key) const noexcept;

    The method finds the attribute by name.

    Parameters:

    key

    Attribute name.

    Returns:

    Iterator to the found element or end() if the attribute with such name is not found.

  10. size_type count(key_type key) const noexcept;

    The method counts the number of the attribute occurrences in the container. Since there can be only one attribute with a particular key, the method always return 0 or 1.

    Parameters:

    key

    Attribute name.

    Returns:

    The number of times the attribute is found in the container.

  11. unspecified operator[](key_type key) noexcept;

    Combined lookup/insertion operator. The operator semantics depends on the further usage of the returned reference.

    • If the reference is used as an assignment target, the assignment expression is equivalent to element insertion, where the element is composed of the second argument of the operator[] as a key and the second argument of assignment as a mapped value.

    • If the returned reference is used in context where a conversion to the mapped type is required, the result of the conversion is equivalent to the mapped value found with the second argument of the operator[] as a key, if such an element exists in the container, or a default-constructed mapped value, if an element does not exist in the container.

    Parameters:

    key

    Attribute name.

    Returns:

    A smart reference object of unspecified type.

  12. mapped_type operator[](key_type key) const noexcept;

    Lookup operator

    Parameters:

    key

    Attribute name.

    Returns:

    If an element with the corresponding attribute name is found in the container, its mapped value is returned. Otherwise a default-constructed mapped value is returned.

  13. std::pair< iterator, bool > insert(key_type key, mapped_type const & data);

    Insertion method

    Parameters:

    data

    Pointer to the attribute. Must not be NULL.

    key

    Attribute name.

    Returns:

    A pair of values. If second is true, the insertion succeeded and the first component points to the inserted element. Otherwise the first component points to the element that prevents insertion.

  14. std::pair< iterator, bool > insert(const_reference value);

    Insertion method

    Parameters:

    value

    An element to be inserted.

    Returns:

    A pair of values. If second is true, the insertion succeeded and the first component points to the inserted element. Otherwise the first component points to the element that prevents insertion.

  15. template<typename FwdIteratorT> 
      void insert(FwdIteratorT begin, FwdIteratorT end);

    Mass insertion method.

    Parameters:

    begin

    A forward iterator that points to the first element to be inserted.

    end

    A forward iterator that points to the after-the-last element to be inserted.

  16. template<typename FwdIteratorT, typename OutputIteratorT> 
      void insert(FwdIteratorT begin, FwdIteratorT end, OutputIteratorT out);

    Mass insertion method with ability to acquire iterators to the inserted elements.

    Parameters:

    begin

    A forward iterator that points to the first element to be inserted.

    end

    A forward iterator that points to the after-the-last element to be inserted.

    out

    An output iterator that receives results of insertion of the elements

  17. size_type erase(key_type key) noexcept;

    The method erases all attributes with the specified name

    Parameters:

    key

    Attribute name.

    Postconditions:

    All iterators to the erased elements become invalid.

    Returns:

    Tne number of erased elements

  18. void erase(iterator it) noexcept;

    The method erases the specified attribute

    Parameters:

    it

    A valid iterator to the element to be erased.

    Postconditions:

    All iterators to the erased element become invalid.

    Returns:

    Tne number of erased elements

  19. void erase(iterator begin, iterator end) noexcept;

    The method erases all attributes within the specified range

    Parameters:

    begin

    An iterator that points to the first element to be erased.

    end

    An iterator that points to the after-the-last element to be erased.

    Requires:

    end is reachable from begin with a finite number of increments.

    Postconditions:

    All iterators to the erased elements become invalid.

  20. void clear() noexcept;

    The method removes all elements from the container

    Postconditions:

    empty() == true


PrevUpHomeNext