• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *          Copyright Andrey Semashev 2007 - 2015.
3  * Distributed under the Boost Software License, Version 1.0.
4  *    (See accompanying file LICENSE_1_0.txt or copy at
5  *          http://www.boost.org/LICENSE_1_0.txt)
6  */
7 /*!
8  * \file   attribute_set.cpp
9  * \author Andrey Semashev
10  * \date   19.04.2007
11  *
12  * \brief  This header is the Boost.Log library implementation, see the library documentation
13  *         at http://www.boost.org/doc/libs/release/libs/log/doc/html/index.html.
14  */
15 
16 #include <boost/log/detail/config.hpp>
17 #include <deque>
18 #include <boost/assert.hpp>
19 #include <boost/intrusive/options.hpp>
20 #include <boost/intrusive/list.hpp>
21 #include <boost/intrusive/link_mode.hpp>
22 #include <boost/intrusive/derivation_value_traits.hpp>
23 #include <boost/log/attributes/attribute.hpp>
24 #include <boost/log/attributes/attribute_set.hpp>
25 #include "attribute_set_impl.hpp"
26 #include "stateless_allocator.hpp"
27 #include <boost/log/detail/header.hpp>
28 
29 namespace boost {
30 
31 BOOST_LOG_OPEN_NAMESPACE
32 
operator new(std::size_t size)33 BOOST_LOG_API void* attribute::impl::operator new (std::size_t size)
34 {
35     return aux::stateless_allocator< unsigned char >().allocate(size);
36 }
37 
operator delete(void * p,std::size_t size)38 BOOST_LOG_API void attribute::impl::operator delete (void* p, std::size_t size) BOOST_NOEXCEPT
39 {
40     aux::stateless_allocator< unsigned char >().deallocate(static_cast< unsigned char* >(p), size);
41 }
42 
node_base()43 inline attribute_set::node_base::node_base() :
44     m_pPrev(NULL),
45     m_pNext(NULL)
46 {
47 }
48 
node(key_type const & key,mapped_type const & data)49 inline attribute_set::node::node(key_type const& key, mapped_type const& data) :
50     node_base(),
51     m_Value(key, data)
52 {
53 }
54 
55 //! Default constructor
attribute_set()56 BOOST_LOG_API attribute_set::attribute_set() :
57     m_pImpl(new implementation())
58 {
59 }
60 
61 //! Copy constructor
attribute_set(attribute_set const & that)62 BOOST_LOG_API attribute_set::attribute_set(attribute_set const& that) :
63     m_pImpl(new implementation(*that.m_pImpl))
64 {
65 }
66 
67 //! Destructor
~attribute_set()68 BOOST_LOG_API attribute_set::~attribute_set() BOOST_NOEXCEPT
69 {
70     delete m_pImpl;
71 }
72 
73 //  Iterator generators
begin()74 BOOST_LOG_API attribute_set::iterator attribute_set::begin() BOOST_NOEXCEPT
75 {
76     return m_pImpl->begin();
77 }
end()78 BOOST_LOG_API attribute_set::iterator attribute_set::end() BOOST_NOEXCEPT
79 {
80     return m_pImpl->end();
81 }
begin() const82 BOOST_LOG_API attribute_set::const_iterator attribute_set::begin() const BOOST_NOEXCEPT
83 {
84     return const_iterator(m_pImpl->begin());
85 }
end() const86 BOOST_LOG_API attribute_set::const_iterator attribute_set::end() const BOOST_NOEXCEPT
87 {
88     return const_iterator(m_pImpl->end());
89 }
90 
91 //! The method returns number of elements in the container
size() const92 BOOST_LOG_API attribute_set::size_type attribute_set::size() const BOOST_NOEXCEPT
93 {
94     return m_pImpl->size();
95 }
96 
97 //! Insertion method
98 BOOST_LOG_API std::pair< attribute_set::iterator, bool >
insert(key_type key,mapped_type const & data)99 attribute_set::insert(key_type key, mapped_type const& data)
100 {
101     return m_pImpl->insert(key, data);
102 }
103 
104 //! The method erases all attributes with the specified name
erase(key_type key)105 BOOST_LOG_API attribute_set::size_type attribute_set::erase(key_type key) BOOST_NOEXCEPT
106 {
107     iterator it = m_pImpl->find(key);
108     if (it != end())
109     {
110         m_pImpl->erase(it);
111         return 1;
112     }
113     else
114         return 0;
115 }
116 
117 //! The method erases the specified attribute
erase(iterator it)118 BOOST_LOG_API void attribute_set::erase(iterator it) BOOST_NOEXCEPT
119 {
120     m_pImpl->erase(it);
121 }
122 
123 //! The method erases all attributes within the specified range
erase(iterator begin,iterator end)124 BOOST_LOG_API void attribute_set::erase(iterator begin, iterator end) BOOST_NOEXCEPT
125 {
126     while (begin != end)
127     {
128         m_pImpl->erase(begin++);
129     }
130 }
131 
132 //! The method clears the container
clear()133 BOOST_LOG_API void attribute_set::clear() BOOST_NOEXCEPT
134 {
135     m_pImpl->clear();
136 }
137 
138 //! Internal lookup implementation
find(key_type key)139 BOOST_LOG_API attribute_set::iterator attribute_set::find(key_type key) BOOST_NOEXCEPT
140 {
141     return m_pImpl->find(key);
142 }
143 
144 BOOST_LOG_CLOSE_NAMESPACE // namespace log
145 
146 } // namespace boost
147 
148 #include <boost/log/detail/footer.hpp>
149