File indexing completed on 2025-01-18 09:39:18
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef BOOST_LOG_ATTRIBUTE_SET_HPP_INCLUDED_
0016 #define BOOST_LOG_ATTRIBUTE_SET_HPP_INCLUDED_
0017
0018 #include <cstddef>
0019 #include <utility>
0020 #include <iterator>
0021 #include <boost/move/core.hpp>
0022 #include <boost/core/enable_if.hpp>
0023 #include <boost/type_traits/conditional.hpp>
0024 #include <boost/log/detail/config.hpp>
0025 #include <boost/log/detail/sfinae_tools.hpp>
0026 #include <boost/log/attributes/attribute_name.hpp>
0027 #include <boost/log/attributes/attribute.hpp>
0028 #include <boost/log/detail/header.hpp>
0029
0030 #ifdef BOOST_HAS_PRAGMA_ONCE
0031 #pragma once
0032 #endif
0033
0034 namespace boost {
0035
0036 BOOST_LOG_OPEN_NAMESPACE
0037
0038 class attribute_set;
0039 class attribute_value_set;
0040
0041 namespace aux {
0042
0043
0044 class attribute_set_reference_proxy
0045 {
0046 private:
0047
0048 typedef attribute_name key_type;
0049
0050 typedef attribute mapped_type;
0051
0052 private:
0053 attribute_set* const m_pContainer;
0054 const key_type m_key;
0055
0056 public:
0057
0058 explicit attribute_set_reference_proxy(attribute_set* pContainer, key_type const& key) BOOST_NOEXCEPT :
0059 m_pContainer(pContainer),
0060 m_key(key)
0061 {
0062 }
0063
0064
0065 BOOST_FORCEINLINE operator mapped_type() const BOOST_NOEXCEPT
0066 {
0067 return read_mapped_value();
0068 }
0069
0070 mapped_type& operator= (mapped_type const& val) const;
0071
0072 private:
0073
0074 mapped_type read_mapped_value() const BOOST_NOEXCEPT;
0075 };
0076
0077 }
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089 class attribute_set
0090 {
0091 BOOST_COPYABLE_AND_MOVABLE_ALT(attribute_set)
0092
0093 friend class attribute_value_set;
0094 friend class aux::attribute_set_reference_proxy;
0095
0096 public:
0097
0098 typedef attribute_name key_type;
0099
0100 typedef attribute mapped_type;
0101
0102
0103 typedef std::pair< const key_type, mapped_type > value_type;
0104
0105 typedef value_type& reference;
0106
0107 typedef value_type const& const_reference;
0108
0109 typedef value_type* pointer;
0110
0111 typedef value_type const* const_pointer;
0112
0113 typedef std::size_t size_type;
0114
0115 typedef std::ptrdiff_t difference_type;
0116
0117 private:
0118
0119
0120
0121 struct implementation;
0122 friend struct implementation;
0123
0124
0125 struct node_base
0126 {
0127 node_base* m_pPrev;
0128 node_base* m_pNext;
0129
0130 node_base();
0131
0132 BOOST_DELETED_FUNCTION(node_base(node_base const&))
0133 BOOST_DELETED_FUNCTION(node_base& operator= (node_base const&))
0134 };
0135
0136
0137 struct node;
0138 friend struct node;
0139 struct node :
0140 public node_base
0141 {
0142 value_type m_Value;
0143
0144 node(key_type const& key, mapped_type const& data);
0145 };
0146
0147
0148 #ifndef BOOST_LOG_NO_MEMBER_TEMPLATE_FRIENDS
0149 template< bool fConstV > class iter;
0150 template< bool fConstV > friend class iter;
0151 #endif
0152 template< bool fConstV >
0153 class iter
0154 {
0155 friend class iter< !fConstV >;
0156 friend class attribute_set;
0157
0158 public:
0159
0160 typedef attribute_set::difference_type difference_type;
0161 typedef attribute_set::value_type value_type;
0162 typedef typename boost::conditional<
0163 fConstV,
0164 attribute_set::const_reference,
0165 attribute_set::reference
0166 >::type reference;
0167 typedef typename boost::conditional<
0168 fConstV,
0169 attribute_set::const_pointer,
0170 attribute_set::pointer
0171 >::type pointer;
0172 typedef std::bidirectional_iterator_tag iterator_category;
0173
0174 public:
0175
0176 BOOST_CONSTEXPR iter() BOOST_NOEXCEPT : m_pNode(NULL) {}
0177 explicit iter(node_base* pNode) BOOST_NOEXCEPT : m_pNode(pNode) {}
0178 #if !defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS)
0179 template< bool fOtherConstV, typename = typename boost::enable_if_c< !fOtherConstV && fOtherConstV != fConstV >::type >
0180 iter(iter< fOtherConstV > const& that) BOOST_NOEXCEPT : m_pNode(that.m_pNode) {}
0181 #else
0182 template< bool fOtherConstV >
0183 iter(iter< fOtherConstV > const& that, typename boost::enable_if_c< !fOtherConstV && fOtherConstV != fConstV, boost::log::aux::sfinae_dummy >::type = boost::log::aux::sfinae_dummy()) BOOST_NOEXCEPT :
0184 m_pNode(that.m_pNode)
0185 {
0186 }
0187 #endif
0188
0189
0190 template< bool fOtherConstV >
0191 typename boost::enable_if_c< !fOtherConstV && fOtherConstV != fConstV, iter& >::type operator= (iter< fOtherConstV > const& that) BOOST_NOEXCEPT
0192 {
0193 m_pNode = that.m_pNode;
0194 return *this;
0195 }
0196
0197
0198 template< bool fOtherConstV >
0199 typename boost::enable_if_c< !fOtherConstV || fOtherConstV == fConstV, bool >::type operator== (iter< fOtherConstV > const& that) const BOOST_NOEXCEPT { return (m_pNode == that.m_pNode); }
0200 template< bool fOtherConstV >
0201 typename boost::enable_if_c< !fOtherConstV || fOtherConstV == fConstV, bool >::type operator!= (iter< fOtherConstV > const& that) const BOOST_NOEXCEPT { return (m_pNode != that.m_pNode); }
0202
0203
0204 iter& operator++ () BOOST_NOEXCEPT
0205 {
0206 m_pNode = m_pNode->m_pNext;
0207 return *this;
0208 }
0209 iter& operator-- () BOOST_NOEXCEPT
0210 {
0211 m_pNode = m_pNode->m_pPrev;
0212 return *this;
0213 }
0214 iter operator++ (int) BOOST_NOEXCEPT
0215 {
0216 iter tmp(*this);
0217 m_pNode = m_pNode->m_pNext;
0218 return tmp;
0219 }
0220 iter operator-- (int) BOOST_NOEXCEPT
0221 {
0222 iter tmp(*this);
0223 m_pNode = m_pNode->m_pPrev;
0224 return tmp;
0225 }
0226
0227
0228 pointer operator-> () const BOOST_NOEXCEPT { return &(static_cast< node* >(m_pNode)->m_Value); }
0229 reference operator* () const BOOST_NOEXCEPT { return static_cast< node* >(m_pNode)->m_Value; }
0230
0231 node_base* base() const BOOST_NOEXCEPT { return m_pNode; }
0232
0233 private:
0234 node_base* m_pNode;
0235 };
0236
0237
0238
0239 public:
0240 #ifndef BOOST_LOG_DOXYGEN_PASS
0241
0242 typedef iter< false > iterator;
0243
0244 typedef iter< true > const_iterator;
0245 #else
0246
0247
0248
0249 typedef implementation_defined iterator;
0250
0251
0252
0253 typedef implementation_defined const_iterator;
0254 #endif
0255
0256 private:
0257
0258 implementation* m_pImpl;
0259
0260 public:
0261
0262
0263
0264
0265
0266 BOOST_LOG_API attribute_set();
0267
0268
0269
0270
0271
0272
0273 BOOST_LOG_API attribute_set(attribute_set const& that);
0274
0275
0276
0277
0278 attribute_set(BOOST_RV_REF(attribute_set) that) BOOST_NOEXCEPT : m_pImpl(that.m_pImpl)
0279 {
0280 that.m_pImpl = NULL;
0281 }
0282
0283
0284
0285
0286 BOOST_LOG_API ~attribute_set() BOOST_NOEXCEPT;
0287
0288
0289
0290
0291
0292
0293 attribute_set& operator= (attribute_set that) BOOST_NOEXCEPT
0294 {
0295 this->swap(that);
0296 return *this;
0297 }
0298
0299
0300
0301
0302
0303
0304 void swap(attribute_set& that) BOOST_NOEXCEPT
0305 {
0306 implementation* const p = m_pImpl;
0307 m_pImpl = that.m_pImpl;
0308 that.m_pImpl = p;
0309 }
0310
0311
0312
0313
0314 BOOST_LOG_API iterator begin() BOOST_NOEXCEPT;
0315
0316
0317
0318 BOOST_LOG_API iterator end() BOOST_NOEXCEPT;
0319
0320
0321
0322 BOOST_LOG_API const_iterator begin() const BOOST_NOEXCEPT;
0323
0324
0325
0326 BOOST_LOG_API const_iterator end() const BOOST_NOEXCEPT;
0327
0328
0329
0330
0331 BOOST_LOG_API size_type size() const BOOST_NOEXCEPT;
0332
0333
0334
0335 bool empty() const BOOST_NOEXCEPT { return (this->size() == 0); }
0336
0337
0338
0339
0340
0341
0342
0343 BOOST_LOG_API iterator find(key_type key) BOOST_NOEXCEPT;
0344
0345
0346
0347
0348
0349
0350 const_iterator find(key_type key) const BOOST_NOEXCEPT
0351 {
0352 return const_iterator(const_cast< attribute_set* >(this)->find(key));
0353 }
0354
0355
0356
0357
0358
0359
0360
0361 size_type count(key_type key) const BOOST_NOEXCEPT { return size_type(this->find(key) != this->end()); }
0362
0363
0364
0365
0366
0367
0368
0369
0370
0371
0372
0373
0374
0375
0376 aux::attribute_set_reference_proxy operator[] (key_type key) BOOST_NOEXCEPT
0377 {
0378 return aux::attribute_set_reference_proxy(this, key);
0379 }
0380
0381
0382
0383
0384
0385
0386
0387 mapped_type operator[] (key_type key) const BOOST_NOEXCEPT
0388 {
0389 const_iterator it = this->find(key);
0390 if (it != end())
0391 return it->second;
0392 else
0393 return mapped_type();
0394 }
0395
0396
0397
0398
0399
0400
0401
0402
0403
0404 BOOST_LOG_API std::pair< iterator, bool > insert(key_type key, mapped_type const& data);
0405
0406
0407
0408
0409
0410
0411
0412
0413 std::pair< iterator, bool > insert(const_reference value)
0414 {
0415 return this->insert(value.first, value.second);
0416 }
0417
0418
0419
0420
0421
0422
0423
0424 template< typename FwdIteratorT >
0425 void insert(FwdIteratorT begin, FwdIteratorT end)
0426 {
0427 for (; begin != end; ++begin)
0428 this->insert(*begin);
0429 }
0430
0431
0432
0433
0434
0435
0436
0437
0438 template< typename FwdIteratorT, typename OutputIteratorT >
0439 void insert(FwdIteratorT begin, FwdIteratorT end, OutputIteratorT out)
0440 {
0441 for (; begin != end; ++begin, ++out)
0442 *out = this->insert(*begin);
0443 }
0444
0445
0446
0447
0448
0449
0450
0451
0452 BOOST_LOG_API size_type erase(key_type key) BOOST_NOEXCEPT;
0453
0454
0455
0456
0457
0458
0459
0460 BOOST_LOG_API void erase(iterator it) BOOST_NOEXCEPT;
0461
0462
0463
0464
0465
0466
0467
0468
0469 BOOST_LOG_API void erase(iterator begin, iterator end) BOOST_NOEXCEPT;
0470
0471
0472
0473
0474
0475
0476 BOOST_LOG_API void clear() BOOST_NOEXCEPT;
0477 };
0478
0479
0480
0481
0482 inline void swap(attribute_set& left, attribute_set& right) BOOST_NOEXCEPT
0483 {
0484 left.swap(right);
0485 }
0486
0487 namespace aux {
0488
0489
0490 inline attribute_set_reference_proxy::mapped_type attribute_set_reference_proxy::read_mapped_value() const BOOST_NOEXCEPT
0491 {
0492 attribute_set::iterator it = m_pContainer->find(m_key);
0493 if (it != m_pContainer->end())
0494 return it->second;
0495 else
0496 return mapped_type();
0497 }
0498
0499
0500 inline attribute_set_reference_proxy::mapped_type& attribute_set_reference_proxy::operator= (mapped_type const& val) const
0501 {
0502 std::pair< attribute_set::iterator, bool > res = m_pContainer->insert(m_key, val);
0503 if (!res.second)
0504 res.first->second = val;
0505 return res.first->second;
0506 }
0507
0508 }
0509
0510 #ifndef BOOST_LOG_DOXYGEN_PASS
0511 inline attribute& attribute::operator= (aux::attribute_set_reference_proxy const& that) BOOST_NOEXCEPT
0512 {
0513 attribute attr = that;
0514 this->swap(attr);
0515 return *this;
0516 }
0517 #endif
0518
0519 BOOST_LOG_CLOSE_NAMESPACE
0520
0521 }
0522
0523 #include <boost/log/detail/footer.hpp>
0524
0525 #endif