123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476 |
- #ifndef BOOST_LOG_ATTRIBUTES_NAMED_SCOPE_HPP_INCLUDED_
- #define BOOST_LOG_ATTRIBUTES_NAMED_SCOPE_HPP_INCLUDED_
- #include <ostream>
- #include <memory>
- #include <iterator>
- #include <cstddef>
- #include <boost/current_function.hpp>
- #include <boost/type_traits/conditional.hpp>
- #include <boost/log/detail/config.hpp>
- #include <boost/log/utility/string_literal.hpp>
- #include <boost/log/utility/unique_identifier_name.hpp>
- #include <boost/log/utility/unused_variable.hpp>
- #include <boost/log/attributes/attribute.hpp>
- #include <boost/log/attributes/attribute_cast.hpp>
- #include <boost/log/detail/allocator_traits.hpp>
- #include <boost/log/detail/header.hpp>
- #ifdef BOOST_HAS_PRAGMA_ONCE
- #pragma once
- #endif
- namespace boost {
- BOOST_LOG_OPEN_NAMESPACE
- namespace attributes {
- namespace aux {
-
- struct named_scope_list_node
- {
- mutable named_scope_list_node* _m_pPrev;
- mutable named_scope_list_node* _m_pNext;
- named_scope_list_node() BOOST_NOEXCEPT { _m_pPrev = _m_pNext = this; }
- };
- }
- struct named_scope_entry
- //! \cond
- : public aux::named_scope_list_node
-
- {
-
- enum scope_name_type
- {
- general,
- function
- };
-
- string_literal scope_name;
-
- string_literal file_name;
-
- unsigned int line;
-
- scope_name_type type;
-
- named_scope_entry(string_literal const& sn, string_literal const& fn, unsigned int ln, scope_name_type t = general) BOOST_NOEXCEPT :
- scope_name(sn),
- file_name(fn),
- line(ln),
- type(t)
- {
- }
- };
- class named_scope_list
- //! \cond
- : protected std::allocator< named_scope_entry >
-
- {
- public:
-
- typedef std::allocator< named_scope_entry > allocator_type;
-
- typedef log::aux::allocator_traits< allocator_type >::value_type value_type;
- typedef log::aux::allocator_traits< allocator_type >::size_type size_type;
- typedef log::aux::allocator_traits< allocator_type >::difference_type difference_type;
- typedef log::aux::allocator_traits< allocator_type >::pointer pointer;
- typedef log::aux::allocator_traits< allocator_type >::const_pointer const_pointer;
- typedef value_type& reference;
- typedef value_type const& const_reference;
- #ifndef BOOST_LOG_DOXYGEN_PASS
- protected:
-
- #ifndef BOOST_LOG_NO_MEMBER_TEMPLATE_FRIENDS
- template< bool fConstV > class iter;
- template< bool fConstV > friend class iter;
- #endif
- template< bool fConstV >
- class iter
- {
- friend class iter< !fConstV >;
- public:
-
- typedef named_scope_list::difference_type difference_type;
- typedef named_scope_list::value_type value_type;
- typedef typename boost::conditional<
- fConstV,
- named_scope_list::const_reference,
- named_scope_list::reference
- >::type reference;
- typedef typename boost::conditional<
- fConstV,
- named_scope_list::const_pointer,
- named_scope_list::pointer
- >::type pointer;
- typedef std::bidirectional_iterator_tag iterator_category;
- public:
-
- iter() : m_pNode(NULL) {}
- explicit iter(aux::named_scope_list_node* pNode) : m_pNode(pNode) {}
- iter(iter< false > const& that) : m_pNode(that.m_pNode) {}
-
- template< bool f >
- iter& operator= (iter< f > const& that)
- {
- m_pNode = that.m_pNode;
- return *this;
- }
-
- template< bool f >
- bool operator== (iter< f > const& that) const { return (m_pNode == that.m_pNode); }
- template< bool f >
- bool operator!= (iter< f > const& that) const { return (m_pNode != that.m_pNode); }
-
- iter& operator++ ()
- {
- m_pNode = m_pNode->_m_pNext;
- return *this;
- }
- iter& operator-- ()
- {
- m_pNode = m_pNode->_m_pPrev;
- return *this;
- }
- iter operator++ (int)
- {
- iter tmp(*this);
- m_pNode = m_pNode->_m_pNext;
- return tmp;
- }
- iter operator-- (int)
- {
- iter tmp(*this);
- m_pNode = m_pNode->_m_pPrev;
- return tmp;
- }
-
- pointer operator-> () const { return static_cast< pointer >(m_pNode); }
- reference operator* () const { return *static_cast< pointer >(m_pNode); }
- private:
- aux::named_scope_list_node* m_pNode;
- };
- public:
- typedef iter< true > const_iterator;
- typedef iter< false > iterator;
- typedef std::reverse_iterator< const_iterator > const_reverse_iterator;
- typedef std::reverse_iterator< iterator > reverse_iterator;
- protected:
-
- aux::named_scope_list_node m_RootNode;
-
- size_type m_Size;
-
- bool m_fNeedToDeallocate;
- #else
-
- typedef implementation_defined const_iterator;
-
- typedef implementation_defined iterator;
-
- typedef implementation_defined const_reverse_iterator;
-
- typedef implementation_defined reverse_iterator;
- #endif
- public:
-
- named_scope_list() : m_Size(0), m_fNeedToDeallocate(false) {}
-
- BOOST_LOG_API named_scope_list(named_scope_list const& that);
-
- BOOST_LOG_API ~named_scope_list();
-
- named_scope_list& operator= (named_scope_list const& that)
- {
- if (this != &that)
- {
- named_scope_list tmp(that);
- swap(tmp);
- }
- return *this;
- }
-
- const_iterator begin() const { return const_iterator(m_RootNode._m_pNext); }
-
- const_iterator end() const { return const_iterator(const_cast< aux::named_scope_list_node* >(&m_RootNode)); }
-
- const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
-
- const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
-
- size_type size() const { return m_Size; }
-
- bool empty() const { return (m_Size == 0); }
-
- BOOST_LOG_API void swap(named_scope_list& that);
-
- const_reference back() const { return *rbegin(); }
-
- const_reference front() const { return *begin(); }
- };
- template< typename CharT, typename TraitsT >
- inline std::basic_ostream< CharT, TraitsT >& operator<< (std::basic_ostream< CharT, TraitsT >& strm, named_scope_list const& sl)
- {
- if (strm.good())
- {
- named_scope_list::const_iterator it = sl.begin(), end = sl.end();
- if (it != end)
- {
- strm << it->scope_name.c_str();
- for (++it; it != end; ++it)
- strm << "->" << it->scope_name.c_str();
- }
- }
- return strm;
- }
- class BOOST_LOG_API named_scope :
- public attribute
- {
- public:
-
- typedef named_scope_list value_type;
-
- typedef value_type::value_type scope_entry;
-
- struct sentry
- {
-
- sentry(string_literal const& sn, string_literal const& fn, unsigned int ln, scope_entry::scope_name_type t = scope_entry::general) BOOST_NOEXCEPT :
- m_Entry(sn, fn, ln, t)
- {
- named_scope::push_scope(m_Entry);
- }
-
- ~sentry() BOOST_NOEXCEPT
- {
- named_scope::pop_scope();
- }
- BOOST_DELETED_FUNCTION(sentry(sentry const&))
- BOOST_DELETED_FUNCTION(sentry& operator= (sentry const&))
- private:
- scope_entry m_Entry;
- };
- private:
-
- struct BOOST_SYMBOL_VISIBLE impl;
- public:
-
- named_scope();
-
- explicit named_scope(cast_source const& source);
-
- static void push_scope(scope_entry const& entry) BOOST_NOEXCEPT;
-
- static void pop_scope() BOOST_NOEXCEPT;
-
- static value_type const& get_scopes();
- };
- }
- BOOST_LOG_CLOSE_NAMESPACE
- }
- #ifndef BOOST_LOG_DOXYGEN_PASS
- #define BOOST_LOG_NAMED_SCOPE_INTERNAL(var, name, file, line, type)\
- BOOST_LOG_UNUSED_VARIABLE(::boost::log::attributes::named_scope::sentry, var, (name, file, line, type));
- #endif
- #define BOOST_LOG_NAMED_SCOPE(name)\
- BOOST_LOG_NAMED_SCOPE_INTERNAL(BOOST_LOG_UNIQUE_IDENTIFIER_NAME(_boost_log_named_scope_sentry_), name, __FILE__, __LINE__, ::boost::log::attributes::named_scope_entry::general)
- #define BOOST_LOG_FUNCTION()\
- BOOST_LOG_NAMED_SCOPE_INTERNAL(BOOST_LOG_UNIQUE_IDENTIFIER_NAME(_boost_log_named_scope_sentry_), BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, ::boost::log::attributes::named_scope_entry::function)
- #if defined(_MSC_VER) || defined(__GNUC__)
- #define BOOST_LOG_FUNC() BOOST_LOG_NAMED_SCOPE(__FUNCTION__)
- #else
- #define BOOST_LOG_FUNC() BOOST_LOG_FUNCTION()
- #endif
- #include <boost/log/detail/footer.hpp>
- #endif
|