Scope Reference

_images/ditaa-cf1fdabe695096f964f7fa15d992fbd4abaac538.png
#include <xo/indentlog/scope.hpp>

Convenience Macros

XO_SCOPE(varname, lvl)

Classes

class scope_setup

Collect code-location information.

Typically used with logging macros like XO_SCOPE Application code isn’t expected to interact with this class directly

Application code isn’t expected to interact with this class directly

group scope_setup instance variables

Variables

log_level log_level_ = log_level::error

minimum severity level for logging &#8212; write messages with severity >= this level

function_style style_ = function_style::pretty

FS_Pretty | FS_Streamlined | FS_Simple

std::string_view name1_ = "<.name1>"

name extracted from left-hand side of symbol split (e.g. foo in method foo::bar)

std::string_view name2_ = "<.name2>"

name extracted from right-hand side of symbol split (e.g. bar in method foo::bar)

std::string_view file_ = "<.file>"

captured value of __FILE__

std::uint32_t line_ = 0

captured value of __LINE__

Basic Scope

template<typename CharT, typename Traits = std::char_traits<CharT>>
class basic_scope

Track nesting level across participating function calls use to drive indentation.

Example:

  using xo::scope;

  void myfunc() {
    XO_SCOPE(log);  //or scope x("myfunc")
    log(a,b,c);
    anotherfunc();
    log(d,e,f);
  }

  void anotherfunc() {
    XO_SCOPE(x); // or scope x("anotherfunc").
    x.log(y);
  }

or:
  void myfunc() {
    bool log_flag = true;
    XO_SCOPE2(log, log_flag);    // create local variable 'log'
    log && log(a,b,c);           // log iff enabled
    log.end_scope();             // optional protection against compiler destroying 'log' early
  }

output like:
   +myfunc:
    a,b,c
    +anotherfunc:
     y
    -anotherfunc:
    d,e,f
   -myfunc:

Template Parameters:
  • CharT – character representation type. Usually char

  • Traits – character traits, usually std::char_traits<ChartT>