| 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 | |
| 33 | BOOST_LOG_API void* attribute::impl::operator new (std::size_t size) |
| 34 | { |
| 35 | return aux::stateless_allocator< unsigned char >().allocate(n: size); |
| 36 | } |
| 37 | |
| 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(p: static_cast< unsigned char* >(p), size); |
| 41 | } |
| 42 | |
| 43 | inline attribute_set::node_base::node_base() : |
| 44 | m_pPrev(NULL), |
| 45 | m_pNext(NULL) |
| 46 | { |
| 47 | } |
| 48 | |
| 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 |
| 56 | BOOST_LOG_API attribute_set::attribute_set() : |
| 57 | m_pImpl(new implementation()) |
| 58 | { |
| 59 | } |
| 60 | |
| 61 | //! Copy constructor |
| 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 |
| 68 | BOOST_LOG_API attribute_set::~attribute_set() BOOST_NOEXCEPT |
| 69 | { |
| 70 | delete m_pImpl; |
| 71 | } |
| 72 | |
| 73 | // Iterator generators |
| 74 | BOOST_LOG_API attribute_set::iterator attribute_set::begin() BOOST_NOEXCEPT |
| 75 | { |
| 76 | return m_pImpl->begin(); |
| 77 | } |
| 78 | BOOST_LOG_API attribute_set::iterator attribute_set::end() BOOST_NOEXCEPT |
| 79 | { |
| 80 | return m_pImpl->end(); |
| 81 | } |
| 82 | BOOST_LOG_API attribute_set::const_iterator attribute_set::begin() const BOOST_NOEXCEPT |
| 83 | { |
| 84 | return const_iterator(m_pImpl->begin()); |
| 85 | } |
| 86 | 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 |
| 92 | 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 > |
| 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 |
| 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 |
| 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 |
| 124 | BOOST_LOG_API void attribute_set::erase(iterator begin, iterator end) BOOST_NOEXCEPT |
| 125 | { |
| 126 | while (begin != end) |
| 127 | { |
| 128 | m_pImpl->erase(it: begin++); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | //! The method clears the container |
| 133 | BOOST_LOG_API void attribute_set::clear() BOOST_NOEXCEPT |
| 134 | { |
| 135 | m_pImpl->clear(); |
| 136 | } |
| 137 | |
| 138 | //! Internal lookup implementation |
| 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 | |