...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::log::attribute_set — An attribute set class.
// 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; };
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
construct/copy/destructattribute_set();
Default constructor.
Postconditions: |
|
attribute_set(attribute_set const & that);
Copy constructor.
Postconditions: |
|
attribute_set(attribute_set && that) noexcept;
Move constructor
attribute_set & operator=(attribute_set that) noexcept;
Copy assignment operator.
Postconditions: |
|
~attribute_set();
Destructor. All stored references to attributes are released.
attribute_set
public member functionsvoid swap(attribute_set & that) noexcept;
Swaps two instances of the container.
Throws: Nothing.
iterator begin() noexcept;
Returns: |
Iterator to the first element of the container. |
iterator end() noexcept;
Returns: |
Iterator to the after-the-last element of the container. |
const_iterator begin() const noexcept;
Returns: |
Constant iterator to the first element of the container. |
const_iterator end() const noexcept;
Returns: |
Constant iterator to the after-the-last element of the container. |
size_type size() const noexcept;
Returns: |
Number of elements in the container. |
bool empty() const noexcept;
Returns: |
true if there are no elements in the container, false otherwise. |
iterator find(key_type key) noexcept;
The method finds the attribute by name.
Parameters: |
|
||
Returns: |
Iterator to the found element or end() if the attribute with such name is not found. |
const_iterator find(key_type key) const noexcept;
The method finds the attribute by name.
Parameters: |
|
||
Returns: |
Iterator to the found element or |
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: |
|
||
Returns: |
The number of times the attribute is found in the container. |
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: |
|
||
Returns: |
A smart reference object of unspecified type. |
mapped_type operator[](key_type key) const noexcept;
Lookup operator
Parameters: |
|
||
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. |
std::pair< iterator, bool > insert(key_type key, mapped_type const & data);
Insertion method
Parameters: |
|
||||
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. |
std::pair< iterator, bool > insert(const_reference value);
Insertion method
Parameters: |
|
||
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. |
template<typename FwdIteratorT> void insert(FwdIteratorT begin, FwdIteratorT end);
Mass insertion method.
Parameters: |
|
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: |
|
size_type erase(key_type key) noexcept;
The method erases all attributes with the specified name
Parameters: |
|
||
Postconditions: |
All iterators to the erased elements become invalid. |
||
Returns: |
Tne number of erased elements |
void erase(iterator it) noexcept;
The method erases the specified attribute
Parameters: |
|
||
Postconditions: |
All iterators to the erased element become invalid. |
||
Returns: |
Tne number of erased elements |
void erase(iterator begin, iterator end) noexcept;
The method erases all attributes within the specified range
Parameters: |
|
||||
Requires: |
end is reachable from begin with a finite number of increments. |
||||
Postconditions: |
All iterators to the erased elements become invalid. |
void clear() noexcept;
The method removes all elements from the container
Postconditions: |
|