annotate DEPENDENCIES/generic/include/boost/log/attributes/named_scope.hpp @ 46:d572322e2efe

Fix to .cat file check (was susceptible to DOS line-endings) and subrepo update
author Chris Cannam
date Thu, 07 Aug 2014 14:39:38 +0100
parents 2665513ce2d3
children c530137014c0
rev   line source
Chris@16 1 /*
Chris@16 2 * Copyright Andrey Semashev 2007 - 2013.
Chris@16 3 * Distributed under the Boost Software License, Version 1.0.
Chris@16 4 * (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 5 * http://www.boost.org/LICENSE_1_0.txt)
Chris@16 6 */
Chris@16 7 /*!
Chris@16 8 * \file
Chris@16 9 * \author Andrey Semashev
Chris@16 10 * \date 24.06.2007
Chris@16 11 *
Chris@16 12 * The header contains implementation of named scope container and an attribute that allows to
Chris@16 13 * put the named scope to log. A number of convenience macros are also provided.
Chris@16 14 */
Chris@16 15
Chris@16 16 #ifndef BOOST_LOG_ATTRIBUTES_NAMED_SCOPE_HPP_INCLUDED_
Chris@16 17 #define BOOST_LOG_ATTRIBUTES_NAMED_SCOPE_HPP_INCLUDED_
Chris@16 18
Chris@16 19 #include <ostream>
Chris@16 20 #include <memory>
Chris@16 21 #include <iterator>
Chris@16 22 #include <cstddef>
Chris@16 23 #include <boost/log/detail/config.hpp>
Chris@16 24 #include <boost/current_function.hpp>
Chris@16 25 #include <boost/mpl/if.hpp>
Chris@16 26 #include <boost/log/utility/string_literal.hpp>
Chris@16 27 #include <boost/log/utility/unique_identifier_name.hpp>
Chris@16 28 #include <boost/log/utility/unused_variable.hpp>
Chris@16 29 #include <boost/log/attributes/attribute.hpp>
Chris@16 30 #include <boost/log/attributes/attribute_cast.hpp>
Chris@16 31 #include <boost/log/detail/header.hpp>
Chris@16 32
Chris@16 33 #ifdef BOOST_HAS_PRAGMA_ONCE
Chris@16 34 #pragma once
Chris@16 35 #endif
Chris@16 36
Chris@16 37 namespace boost {
Chris@16 38
Chris@16 39 BOOST_LOG_OPEN_NAMESPACE
Chris@16 40
Chris@16 41 namespace attributes {
Chris@16 42
Chris@16 43 namespace aux {
Chris@16 44
Chris@16 45 //! Double-linked list node
Chris@16 46 struct named_scope_list_node
Chris@16 47 {
Chris@16 48 mutable named_scope_list_node* _m_pPrev;
Chris@16 49 mutable named_scope_list_node* _m_pNext;
Chris@16 50
Chris@16 51 named_scope_list_node() BOOST_NOEXCEPT { _m_pPrev = _m_pNext = this; }
Chris@16 52 };
Chris@16 53
Chris@16 54 } // namespace aux
Chris@16 55
Chris@16 56 /*!
Chris@16 57 * \brief The structure contains all information about a named scope
Chris@16 58 *
Chris@16 59 * The named scope entries are stored as elements of \c basic_named_scope_list container, which
Chris@16 60 * in turn can be acquired either from the \c basic_named_scope attribute value or from a thread-local
Chris@16 61 * instance.
Chris@16 62 */
Chris@16 63 struct named_scope_entry
Chris@16 64 //! \cond
Chris@16 65 : public aux::named_scope_list_node
Chris@16 66 //! \endcond
Chris@16 67 {
Chris@16 68 /*!
Chris@16 69 * The scope name (e.g. a function signature)
Chris@16 70 */
Chris@16 71 string_literal scope_name;
Chris@16 72 /*!
Chris@16 73 * The source file name
Chris@16 74 */
Chris@16 75 string_literal file_name;
Chris@16 76 /*!
Chris@16 77 * The line number in the source file
Chris@16 78 */
Chris@16 79 unsigned int line;
Chris@16 80
Chris@16 81 /*!
Chris@16 82 * Initializing constructor
Chris@16 83 *
Chris@16 84 * \post <tt>scope_name == sn && file_name == fn && line == ln</tt>
Chris@16 85 *
Chris@16 86 * \b Throws: Nothing.
Chris@16 87 */
Chris@16 88 named_scope_entry(string_literal const& sn, string_literal const& fn, unsigned int ln) BOOST_NOEXCEPT :
Chris@16 89 scope_name(sn),
Chris@16 90 file_name(fn),
Chris@16 91 line(ln)
Chris@16 92 {
Chris@16 93 }
Chris@16 94 };
Chris@16 95
Chris@16 96 /*!
Chris@16 97 * \brief The class implements the list of scopes
Chris@16 98 *
Chris@16 99 * The scope list provides a read-only access to a doubly-linked list of scopes.
Chris@16 100 */
Chris@16 101 class named_scope_list
Chris@16 102 //! \cond
Chris@16 103 : protected std::allocator< named_scope_entry >
Chris@16 104 //! \endcond
Chris@16 105 {
Chris@16 106 public:
Chris@16 107 //! Allocator type
Chris@16 108 typedef std::allocator< named_scope_entry > allocator_type;
Chris@16 109
Chris@16 110 // Standard types
Chris@16 111 typedef allocator_type::value_type value_type;
Chris@16 112 typedef allocator_type::reference reference;
Chris@16 113 typedef allocator_type::const_reference const_reference;
Chris@16 114 typedef allocator_type::pointer pointer;
Chris@16 115 typedef allocator_type::const_pointer const_pointer;
Chris@16 116 typedef allocator_type::size_type size_type;
Chris@16 117 typedef allocator_type::difference_type difference_type;
Chris@16 118
Chris@16 119 #ifndef BOOST_LOG_DOXYGEN_PASS
Chris@16 120
Chris@16 121 protected:
Chris@16 122 //! Iterator class
Chris@16 123 #ifndef BOOST_LOG_NO_MEMBER_TEMPLATE_FRIENDS
Chris@16 124 template< bool fConstV > class iter;
Chris@16 125 template< bool fConstV > friend class iter;
Chris@16 126 #endif
Chris@16 127 template< bool fConstV >
Chris@16 128 class iter
Chris@16 129 {
Chris@16 130 friend class iter< !fConstV >;
Chris@16 131
Chris@16 132 public:
Chris@16 133 // Standard typedefs
Chris@16 134 typedef named_scope_list::difference_type difference_type;
Chris@16 135 typedef named_scope_list::value_type value_type;
Chris@16 136 typedef typename mpl::if_c<
Chris@16 137 fConstV,
Chris@16 138 named_scope_list::const_reference,
Chris@16 139 named_scope_list::reference
Chris@16 140 >::type reference;
Chris@16 141 typedef typename mpl::if_c<
Chris@16 142 fConstV,
Chris@16 143 named_scope_list::const_pointer,
Chris@16 144 named_scope_list::pointer
Chris@16 145 >::type pointer;
Chris@16 146 typedef std::bidirectional_iterator_tag iterator_category;
Chris@16 147
Chris@16 148 public:
Chris@16 149 // Constructors
Chris@16 150 iter() : m_pNode(NULL) {}
Chris@16 151 explicit iter(aux::named_scope_list_node* pNode) : m_pNode(pNode) {}
Chris@16 152 iter(iter< false > const& that) : m_pNode(that.m_pNode) {}
Chris@16 153
Chris@16 154 //! Assignment
Chris@16 155 template< bool f >
Chris@16 156 iter& operator= (iter< f > const& that)
Chris@16 157 {
Chris@16 158 m_pNode = that.m_pNode;
Chris@16 159 return *this;
Chris@16 160 }
Chris@16 161
Chris@16 162 // Comparison
Chris@16 163 template< bool f >
Chris@16 164 bool operator== (iter< f > const& that) const { return (m_pNode == that.m_pNode); }
Chris@16 165 template< bool f >
Chris@16 166 bool operator!= (iter< f > const& that) const { return (m_pNode != that.m_pNode); }
Chris@16 167
Chris@16 168 // Modification
Chris@16 169 iter& operator++ ()
Chris@16 170 {
Chris@16 171 m_pNode = m_pNode->_m_pNext;
Chris@16 172 return *this;
Chris@16 173 }
Chris@16 174 iter& operator-- ()
Chris@16 175 {
Chris@16 176 m_pNode = m_pNode->_m_pPrev;
Chris@16 177 return *this;
Chris@16 178 }
Chris@16 179 iter operator++ (int)
Chris@16 180 {
Chris@16 181 iter tmp(*this);
Chris@16 182 m_pNode = m_pNode->_m_pNext;
Chris@16 183 return tmp;
Chris@16 184 }
Chris@16 185 iter operator-- (int)
Chris@16 186 {
Chris@16 187 iter tmp(*this);
Chris@16 188 m_pNode = m_pNode->_m_pPrev;
Chris@16 189 return tmp;
Chris@16 190 }
Chris@16 191
Chris@16 192 // Dereferencing
Chris@16 193 pointer operator-> () const { return static_cast< pointer >(m_pNode); }
Chris@16 194 reference operator* () const { return *static_cast< pointer >(m_pNode); }
Chris@16 195
Chris@16 196 private:
Chris@16 197 aux::named_scope_list_node* m_pNode;
Chris@16 198 };
Chris@16 199
Chris@16 200 public:
Chris@16 201 typedef iter< true > const_iterator;
Chris@16 202 typedef iter< false > iterator;
Chris@16 203 typedef std::reverse_iterator< const_iterator > const_reverse_iterator;
Chris@16 204 typedef std::reverse_iterator< iterator > reverse_iterator;
Chris@16 205
Chris@16 206 protected:
Chris@16 207 //! The root node of the container
Chris@16 208 aux::named_scope_list_node m_RootNode;
Chris@16 209 //! The size of the container
Chris@16 210 size_type m_Size;
Chris@16 211 //! The flag shows if the contained elements are dynamically allocated
Chris@16 212 bool m_fNeedToDeallocate;
Chris@16 213
Chris@16 214 #else // BOOST_LOG_DOXYGEN_PASS
Chris@16 215
Chris@16 216 /*!
Chris@16 217 * A constant iterator to the sequence of scopes. Complies to bidirectional iterator requirements.
Chris@16 218 */
Chris@16 219 typedef implementation_defined const_iterator;
Chris@16 220 /*!
Chris@16 221 * An iterator to the sequence of scopes. Complies to bidirectional iterator requirements.
Chris@16 222 */
Chris@16 223 typedef implementation_defined iterator;
Chris@16 224 /*!
Chris@16 225 * A constant reverse iterator to the sequence of scopes. Complies to bidirectional iterator requirements.
Chris@16 226 */
Chris@16 227 typedef implementation_defined const_reverse_iterator;
Chris@16 228 /*!
Chris@16 229 * A reverse iterator to the sequence of scopes. Complies to bidirectional iterator requirements.
Chris@16 230 */
Chris@16 231 typedef implementation_defined reverse_iterator;
Chris@16 232
Chris@16 233 #endif // BOOST_LOG_DOXYGEN_PASS
Chris@16 234
Chris@16 235 public:
Chris@16 236 /*!
Chris@16 237 * Default constructor
Chris@16 238 *
Chris@16 239 * \post <tt>empty() == true</tt>
Chris@16 240 */
Chris@16 241 named_scope_list() : m_Size(0), m_fNeedToDeallocate(false) {}
Chris@16 242 /*!
Chris@16 243 * Copy constructor
Chris@16 244 *
Chris@16 245 * \post <tt>std::equal(begin(), end(), that.begin()) == true</tt>
Chris@16 246 */
Chris@16 247 BOOST_LOG_API named_scope_list(named_scope_list const& that);
Chris@16 248 /*!
Chris@16 249 * Destructor. Destroys the stored entries.
Chris@16 250 */
Chris@16 251 BOOST_LOG_API ~named_scope_list();
Chris@16 252
Chris@16 253 /*!
Chris@16 254 * Assignment operator
Chris@16 255 *
Chris@16 256 * \post <tt>std::equal(begin(), end(), that.begin()) == true</tt>
Chris@16 257 */
Chris@16 258 named_scope_list& operator= (named_scope_list const& that)
Chris@16 259 {
Chris@16 260 if (this != &that)
Chris@16 261 {
Chris@16 262 named_scope_list tmp(that);
Chris@16 263 swap(tmp);
Chris@16 264 }
Chris@16 265 return *this;
Chris@16 266 }
Chris@16 267
Chris@16 268 /*!
Chris@16 269 * \return Constant iterator to the first element of the container.
Chris@16 270 */
Chris@16 271 const_iterator begin() const { return const_iterator(m_RootNode._m_pNext); }
Chris@16 272 /*!
Chris@16 273 * \return Constant iterator to the after-the-last element of the container.
Chris@16 274 */
Chris@16 275 const_iterator end() const { return const_iterator(const_cast< aux::named_scope_list_node* >(&m_RootNode)); }
Chris@16 276 /*!
Chris@16 277 * \return Constant iterator to the last element of the container.
Chris@16 278 */
Chris@16 279 const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
Chris@16 280 /*!
Chris@16 281 * \return Constant iterator to the before-the-first element of the container.
Chris@16 282 */
Chris@16 283 const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
Chris@16 284
Chris@16 285 /*!
Chris@16 286 * \return The number of elements in the container
Chris@16 287 */
Chris@16 288 size_type size() const { return m_Size; }
Chris@16 289 /*!
Chris@16 290 * \return true if the container is empty and false otherwise
Chris@16 291 */
Chris@16 292 bool empty() const { return (m_Size == 0); }
Chris@16 293
Chris@16 294 /*!
Chris@16 295 * Swaps two instances of the container
Chris@16 296 */
Chris@16 297 BOOST_LOG_API void swap(named_scope_list& that);
Chris@16 298
Chris@16 299 /*!
Chris@16 300 * \return Last pushed scope entry
Chris@16 301 */
Chris@16 302 const_reference back() const { return *rbegin(); }
Chris@16 303 /*!
Chris@16 304 * \return First pushed scope entry
Chris@16 305 */
Chris@16 306 const_reference front() const { return *begin(); }
Chris@16 307 };
Chris@16 308
Chris@16 309 //! Stream output operator
Chris@16 310 template< typename CharT, typename TraitsT >
Chris@16 311 inline std::basic_ostream< CharT, TraitsT >& operator<< (std::basic_ostream< CharT, TraitsT >& strm, named_scope_list const& sl)
Chris@16 312 {
Chris@16 313 if (strm.good())
Chris@16 314 {
Chris@16 315 named_scope_list::const_iterator it = sl.begin(), end = sl.end();
Chris@16 316 if (it != end)
Chris@16 317 {
Chris@16 318 strm << it->scope_name.c_str();
Chris@16 319 for (++it; it != end; ++it)
Chris@16 320 strm << "->" << it->scope_name.c_str();
Chris@16 321 }
Chris@16 322 }
Chris@16 323 return strm;
Chris@16 324 }
Chris@16 325
Chris@16 326 /*!
Chris@16 327 * \brief A class of an attribute that holds stack of named scopes of the current thread
Chris@16 328 *
Chris@16 329 * The basic_named_scope attribute is essentially a hook to the thread-specific instance of
Chris@16 330 * scope list. This means that the attribute will generate different values if get_value is
Chris@16 331 * called in different threads. The attribute generates value with stored type
Chris@16 332 * <tt>basic_named_scope_list< CharT ></tt>.
Chris@16 333 *
Chris@16 334 * The attribute class can also be used to gain access to the scope stack instance, e.g. to
Chris@16 335 * get its copy or to push or pop a scope entry. However, it is highly not recommended to
Chris@16 336 * maintain scope list manually. Use \c BOOST_LOG_NAMED_SCOPE or \c BOOST_LOG_FUNCTION macros instead.
Chris@16 337 */
Chris@16 338 class BOOST_LOG_API named_scope :
Chris@16 339 public attribute
Chris@16 340 {
Chris@16 341 public:
Chris@16 342 //! Scope names stack (the attribute value type)
Chris@16 343 typedef named_scope_list value_type;
Chris@16 344 //! Scope entry
Chris@16 345 typedef value_type::value_type scope_entry;
Chris@16 346
Chris@16 347 //! Sentry object class to automatically push and pop scopes
Chris@16 348 struct sentry
Chris@16 349 {
Chris@16 350 /*!
Chris@16 351 * Constructor. Pushes the specified scope to the end of the thread-local list of scopes.
Chris@16 352 *
Chris@16 353 * \param sn Scope name.
Chris@16 354 * \param fn File name, in which the scope is located.
Chris@16 355 * \param ln Line number in the file.
Chris@16 356 */
Chris@16 357 sentry(string_literal const& sn, string_literal const& fn, unsigned int ln) BOOST_NOEXCEPT :
Chris@16 358 m_Entry(sn, fn, ln)
Chris@16 359 {
Chris@16 360 named_scope::push_scope(m_Entry);
Chris@16 361 }
Chris@16 362
Chris@16 363 /*!
Chris@16 364 * Destructor. Removes the last pushed scope from the thread-local list of scopes.
Chris@16 365 */
Chris@16 366 ~sentry() BOOST_NOEXCEPT
Chris@16 367 {
Chris@16 368 named_scope::pop_scope();
Chris@16 369 }
Chris@16 370
Chris@16 371 BOOST_DELETED_FUNCTION(sentry(sentry const&))
Chris@16 372 BOOST_DELETED_FUNCTION(sentry& operator= (sentry const&))
Chris@16 373
Chris@16 374 private:
Chris@16 375 scope_entry m_Entry;
Chris@16 376 };
Chris@16 377
Chris@16 378 private:
Chris@16 379 //! Attribute implementation class
Chris@16 380 struct BOOST_SYMBOL_VISIBLE impl;
Chris@16 381
Chris@16 382 public:
Chris@16 383 /*!
Chris@16 384 * Constructor. Creates an attribute.
Chris@16 385 */
Chris@16 386 named_scope();
Chris@16 387 /*!
Chris@16 388 * Constructor for casting support
Chris@16 389 */
Chris@16 390 explicit named_scope(cast_source const& source);
Chris@16 391
Chris@16 392 /*!
Chris@16 393 * The method pushes the scope to the back of the current thread's scope list
Chris@16 394 *
Chris@16 395 * \b Throws: Nothing.
Chris@16 396 */
Chris@16 397 static void push_scope(scope_entry const& entry) BOOST_NOEXCEPT;
Chris@16 398 /*!
Chris@16 399 * The method pops the last pushed scope from the current thread's scope list
Chris@16 400 *
Chris@16 401 * \b Throws: Nothing.
Chris@16 402 */
Chris@16 403 static void pop_scope() BOOST_NOEXCEPT;
Chris@16 404
Chris@16 405 /*!
Chris@16 406 * \return The current thread's list of scopes
Chris@16 407 *
Chris@16 408 * \note The returned reference is only valid until the current thread ends. The scopes in the
Chris@16 409 * returned container may change if the execution scope is changed (i.e. either \c push_scope
Chris@16 410 * or \c pop_scope is called). User has to copy the stack if he wants to keep it intact regardless
Chris@16 411 * of the execution scope.
Chris@16 412 */
Chris@16 413 static value_type const& get_scopes();
Chris@16 414 };
Chris@16 415
Chris@16 416 } // namespace attributes
Chris@16 417
Chris@16 418 BOOST_LOG_CLOSE_NAMESPACE // namespace log
Chris@16 419
Chris@16 420 } // namespace boost
Chris@16 421
Chris@16 422 #ifndef BOOST_LOG_DOXYGEN_PASS
Chris@16 423
Chris@16 424 #define BOOST_LOG_NAMED_SCOPE_INTERNAL(var, name, file, line)\
Chris@16 425 BOOST_LOG_UNUSED_VARIABLE(::boost::log::attributes::named_scope::sentry, var, (name, file, line));
Chris@16 426
Chris@16 427 #endif // BOOST_LOG_DOXYGEN_PASS
Chris@16 428
Chris@16 429 /*!
Chris@16 430 * Macro for scope markup. The specified scope name is pushed to the end of the current thread scope list.
Chris@16 431 */
Chris@16 432 #define BOOST_LOG_NAMED_SCOPE(name)\
Chris@16 433 BOOST_LOG_NAMED_SCOPE_INTERNAL(BOOST_LOG_UNIQUE_IDENTIFIER_NAME(_boost_log_named_scope_sentry_), name, __FILE__, __LINE__)
Chris@16 434
Chris@16 435 /*!
Chris@16 436 * Macro for function scope markup. The scope name is constructed with help of compiler and contains current function name.
Chris@16 437 * The scope name is pushed to the end of the current thread scope list.
Chris@16 438 *
Chris@16 439 * Not all compilers have support for this macro. The exact form of the scope name may vary from one compiler to another.
Chris@16 440 */
Chris@16 441 #define BOOST_LOG_FUNCTION() BOOST_LOG_NAMED_SCOPE(BOOST_CURRENT_FUNCTION)
Chris@16 442
Chris@16 443 #include <boost/log/detail/footer.hpp>
Chris@16 444
Chris@16 445 #endif // BOOST_LOG_ATTRIBUTES_NAMED_SCOPE_HPP_INCLUDED_