Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

PrevUpHomeNext

Class named_scope

boost::log::attributes::named_scope — A class of an attribute that holds stack of named scopes of the current thread.

Synopsis

// In header: <boost/log/attributes/named_scope.hpp>


class named_scope : public attribute {
public:
  // types
  typedef named_scope_list       value_type;   // Scope names stack (the attribute value type) 
  typedef value_type::value_type scope_entry;  // Scope entry. 

  // member classes/structs/unions

  // Sentry object class to automatically push and pop scopes.

  struct sentry {

    // public member functions
    sentry(string_literal const &, string_literal const &, unsigned int, 
           scope_entry::scope_name_type = scope_entry::general) noexcept;
    ~sentry() noexcept;
    sentry(sentry const &) = delete;
    sentry & operator=(sentry const &) = delete;
  };

  // public member functions
  named_scope();
  explicit named_scope(cast_source const &);

  // public static functions
  static void push_scope(scope_entry const &) noexcept;
  static void pop_scope() noexcept;
  static value_type const & get_scopes();
};

Description

The basic_named_scope attribute is essentially a hook to the thread-specific instance of scope list. This means that the attribute will generate different values if get_value is called in different threads. The attribute generates value with stored type basic_named_scope_list< CharT >.

The attribute class can also be used to gain access to the scope stack instance, e.g. to get its copy or to push or pop a scope entry. However, it is highly not recommended to maintain scope list manually. Use BOOST_LOG_NAMED_SCOPE or BOOST_LOG_FUNCTION macros instead.

named_scope public member functions

  1. named_scope();

    Constructor. Creates an attribute.

  2. explicit named_scope(cast_source const & source);

    Constructor for casting support

named_scope public static functions

  1. static void push_scope(scope_entry const & entry) noexcept;

    The method pushes the scope to the back of the current thread's scope list

    Throws: Nothing.

  2. static void pop_scope() noexcept;

    The method pops the last pushed scope from the current thread's scope list

    Throws: Nothing.

  3. static value_type const & get_scopes();

    [Note] Note

    The returned reference is only valid until the current thread ends. The scopes in the returned container may change if the execution scope is changed (i.e. either push_scope or pop_scope is called). User has to copy the stack if he wants to keep it intact regardless of the execution scope.

    Returns:

    The current thread's list of scopes


PrevUpHomeNext