Flow 1.0.2
Flow project: Full implementation reference.
Public Types | Public Member Functions | Static Public Attributes | Private Attributes | Related Functions | List of all members
flow::log::Verbosity_config Class Reference

Optional-use structure encapsulating a full set of verbosity config, such that one can parse it from a config source (like an options file) in concise form and apply it to a log::Config object. More...

#include <verbosity_config.hpp>

Collaboration diagram for flow::log::Verbosity_config:
[legend]

Public Types

using Component_sev_pair_seq = std::vector< std::pair< std::string, Sev > >
 Short-hand for the configuration capable of being encapsulated by Verbosity_config. More...
 

Public Member Functions

 Verbosity_config ()
 Constructor a Verbosity_config that resets all severity config and sets the default/catch-all to Config::S_MOST_VERBOSE_SEV_DEFAULT. More...
 
bool parse (std::istream &is)
 Deserializes *this from a standard input stream. More...
 
bool apply_to_config (Config *target_config)
 Applies *this to to the given log::Config. More...
 
const std::string & last_result_message () const
 To be used after parse() or operator<< or apply_to_config(), returns "" on success or a message describing the problem on failure. More...
 
const Component_sev_pair_seqcomponent_sev_pairs () const
 Read-only access to encapsulated config; specifies the verbosity-setting calls to make on a Config in order, given as component-name-to-severity pairs, with an empty component name specifying the default severity used when no component name is given. More...
 

Static Public Attributes

static const std::string S_ALL_COMPONENT_NAME_ALIAS
 String that Verbosity_config::parse() treats as the default/catch-all verbosity's "component" specifier. More...
 
static const char S_TOKEN_SEPARATOR
 Separates component/severity pairs in a Verbosity_config specifier string. More...
 
static const char S_PAIR_SEPARATOR
 Separates component and severity within each pair in a Verbosity_config specifier string. More...
 

Private Attributes

Component_sev_pair_seq m_component_sev_pairs
 See component_sev_pairs(). More...
 
std::string m_last_result_message
 See last_result_message(). More...
 

Related Functions

(Note that these are not member functions.)

std::istream & operator>> (std::istream &is, Verbosity_config &val)
 Deserializes a Verbosity_config from a standard input stream by invoking val.parse(is). More...
 
std::ostream & operator<< (std::ostream &os, const Verbosity_config &val)
 Serializes a Verbosity_config to a standard output stream. More...
 
bool operator== (const Verbosity_config &val1, const Verbosity_config &val2)
 Checks for exact equality of two Verbosity_config objects. More...
 
bool operator!= (const Verbosity_config &val1, const Verbosity_config &val2)
 Returns !(val1 == val2). More...
 

Detailed Description

Optional-use structure encapsulating a full set of verbosity config, such that one can parse it from a config source (like an options file) in concise form and apply it to a log::Config object.

Put simply, one can read a string like "ALL:2;COOL_COMPONENT:4;ANOTHER_COMPONENT:TRACE" from an istream via >>; then this->apply_to_config(&cfg), where cfg is a log::Config; resulting in the necessary Config::configure_default_verbosity() and Config::configure_component_verbosity_by_name() calls that will set the default verbosity to INFO and those specific components' verbosities to DATA and TRACE respectively in order.

Definition at line 41 of file verbosity_config.hpp.

Member Typedef Documentation

◆ Component_sev_pair_seq

using flow::log::Verbosity_config::Component_sev_pair_seq = std::vector<std::pair<std::string, Sev> >

Short-hand for the configuration capable of being encapsulated by Verbosity_config.

Definition at line 47 of file verbosity_config.hpp.

Constructor & Destructor Documentation

◆ Verbosity_config()

flow::log::Verbosity_config::Verbosity_config ( )

Constructor a Verbosity_config that resets all severity config and sets the default/catch-all to Config::S_MOST_VERBOSE_SEV_DEFAULT.

Definition at line 34 of file verbosity_config.cpp.

References m_component_sev_pairs, and flow::log::Config::S_MOST_VERBOSE_SEV_DEFAULT.

Member Function Documentation

◆ apply_to_config()

bool flow::log::Verbosity_config::apply_to_config ( Config target_config)

Applies *this to to the given log::Config.

Typically one would parse into *this first.

Returns true if this succeeded; else false. last_result_message() can then be invoked to get further details suitable for display to the user in the case of false. Typically this would only occur, as of this writing, on an unknown component name according to what has been registered on *target_config.

If true returned, the Config verbosity config is completely overwritten; otherwise it is reset and completely overwritten but may represent only a partial application (valid but typically not advisable to use).

Parameters
target_configThe log::Config to reset.
Returns
true if and only if successfully applied. See also last_result_message().

Definition at line 157 of file verbosity_config.cpp.

References m_component_sev_pairs, m_last_result_message, and flow::util::ostream_op_string().

Here is the call graph for this function:

◆ component_sev_pairs()

const Verbosity_config::Component_sev_pair_seq & flow::log::Verbosity_config::component_sev_pairs ( ) const

Read-only access to encapsulated config; specifies the verbosity-setting calls to make on a Config in order, given as component-name-to-severity pairs, with an empty component name specifying the default severity used when no component name is given.

The assumed semantics as applied to a given log::Config cfg are as follows:

  1. If empty, or the first pair's component name is not "", then act as-if there was an additional front-inserted pair ("", Config::S_MOST_VERBOSE_SEV_DEFAULT).
  2. For the first pair: cfg.configure_default_verbosity(v, true);, where v is the log::Sev in that slot. In other words the config is reset, and the catch-all default verbosity is initialized to that severity.
  3. For each subsequent pair (name, v):
    • If the name is "": cfg.configure_default_verbosity(v, false);.
    • Otherwise: cfg.configure_component_verbosity_by_name(v, name);.
Returns
See above.

Definition at line 199 of file verbosity_config.cpp.

References m_component_sev_pairs.

Referenced by operator<<(), and operator==().

Here is the caller graph for this function:

◆ last_result_message()

const std::string & flow::log::Verbosity_config::last_result_message ( ) const

To be used after parse() or operator<< or apply_to_config(), returns "" on success or a message describing the problem on failure.

Returns
See above.

Definition at line 194 of file verbosity_config.cpp.

References m_last_result_message.

◆ parse()

bool flow::log::Verbosity_config::parse ( std::istream &  is)

Deserializes *this from a standard input stream.

Reads a single space-delimited token from the given stream. Separates that into a sequence of S_TOKEN_SEPARATOR-delimited pairs, each representing an element of what will be returnable via component_sev_pairs(), in order. Each pair is to be in one of the following forms:

  • No S_PAIR_SEPARATOR; just a Severity readable via its istream<< operator (as of this writing, a number "1", "2", ... or a string "WARNING", "INFO", etc.). Then this is taken to be the severity, and the component name for component_sev_pairs() is taken to be as-if "" (the default).
  • ":sev" (where the colon stands for S_PAIR_SEPARATOR): As-if simply "sev" (previous bullet point).
  • "ALL:sev" (ditto re. colon): ALL is S_ALL_COMPONENT_NAME_ALIAS: Same meaning as previous bullet point.
  • "name:sev" (ditto re. colon): name is the component name; sev is the Severity readable via its istream<< operator.

Returns true if the token was legal; else false. last_result_message() can then be invoked to get further details suitable for display to the user in the case of false.

If true returned, the existing payload is completely overwritten. Otherwise it is untouched.

Parameters
isInput stream.
Returns
true if and only if successfully deserialized. See also last_result_message().

Definition at line 44 of file verbosity_config.cpp.

References m_component_sev_pairs, m_last_result_message, flow::util::ostream_op_string(), S_ALL_COMPONENT_NAME_ALIAS, flow::log::Config::S_MOST_VERBOSE_SEV_DEFAULT, S_PAIR_SEPARATOR, and S_TOKEN_SEPARATOR.

Referenced by operator>>().

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ operator!=()

bool operator!= ( const Verbosity_config val1,
const Verbosity_config val2 
)
related

Returns !(val1 == val2).

Parameters
val1Object to compare.
val2Object to compare.
Returns
See above.

Definition at line 236 of file verbosity_config.cpp.

References flow::log::operator==().

Here is the call graph for this function:

◆ operator<<()

std::ostream & operator<< ( std::ostream &  os,
const Verbosity_config val 
)
related

Serializes a Verbosity_config to a standard output stream.

Parameters
osStream to which to serialize.
valValue to serialize.
Returns
os.

Definition at line 210 of file verbosity_config.cpp.

References component_sev_pairs(), S_ALL_COMPONENT_NAME_ALIAS, S_PAIR_SEPARATOR, and S_TOKEN_SEPARATOR.

Here is the call graph for this function:

◆ operator==()

bool operator== ( const Verbosity_config val1,
const Verbosity_config val2 
)
related

Checks for exact equality of two Verbosity_config objects.

(Note that this is not maximally clever, in that if (val1 == val2), then they definitely produce the same Config all else being equal; but if the reverse is true, then it is possible they differently expressed values producing the same actual result. E.g., something like ALL:INFO differs from ALL:WARN;ALL:INFO – yet they have the same effect. However component names are normalized internally when parsing, so that won't produce false inequality.)

Only Verbosity_config::component_sev_pairs() is significant in this comparison; last_result_message() is not.

Parameters
val1Object to compare.
val2Object to compare.
Returns
true if definitely equal; false if possibly not equal.

Definition at line 231 of file verbosity_config.cpp.

References component_sev_pairs().

Here is the call graph for this function:

◆ operator>>()

std::istream & operator>> ( std::istream &  is,
Verbosity_config val 
)
related

Deserializes a Verbosity_config from a standard input stream by invoking val.parse(is).

val.last_result_message() can be used to glean the success or failure of this operation.

Parameters
isStream from which to deserialize.
valValue to set.
Returns
is.

Definition at line 204 of file verbosity_config.cpp.

References parse().

Here is the call graph for this function:

Member Data Documentation

◆ m_component_sev_pairs

Component_sev_pair_seq flow::log::Verbosity_config::m_component_sev_pairs
private

◆ m_last_result_message

std::string flow::log::Verbosity_config::m_last_result_message
private

See last_result_message().

Definition at line 143 of file verbosity_config.hpp.

Referenced by apply_to_config(), last_result_message(), and parse().

◆ S_ALL_COMPONENT_NAME_ALIAS

const std::string flow::log::Verbosity_config::S_ALL_COMPONENT_NAME_ALIAS
static

String that Verbosity_config::parse() treats as the default/catch-all verbosity's "component" specifier.

Definition at line 52 of file verbosity_config.hpp.

Referenced by operator<<(), and parse().

◆ S_PAIR_SEPARATOR

const char flow::log::Verbosity_config::S_PAIR_SEPARATOR
static

Separates component and severity within each pair in a Verbosity_config specifier string.

Definition at line 58 of file verbosity_config.hpp.

Referenced by operator<<(), and parse().

◆ S_TOKEN_SEPARATOR

const char flow::log::Verbosity_config::S_TOKEN_SEPARATOR
static

Separates component/severity pairs in a Verbosity_config specifier string.

Definition at line 55 of file verbosity_config.hpp.

Referenced by operator<<(), and parse().


The documentation for this class was generated from the following files: