JayBeams  0.1
Another project to have fun coding.
Classes | Public Member Functions | Static Protected Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
jb::config_object Class Reference

Base class for all configuration objects. More...

#include <config_object.hpp>

Inheritance diagram for jb::config_object:
jb::book_depth_statistics::config jb::itch5::array_based_order_book::config jb::itch5::map_based_order_book::config jb::itch5::mold_udp_pacer_config jb::itch5::udp_config_common jb::log::config jb::offline_feed_statistics::config jb::opencl::config jb::opencl::microbenchmark_config jb::testing::microbenchmark_config jb::thread_config program_config thread_config worker_config

Classes

class  attribute_base
 Define the interface to manipulate and access configuration attributes embedded in a config_object. More...
 
struct  attribute_descriptor
 An attribute descriptor. More...
 

Public Member Functions

 config_object ()
 Default constructor. More...
 
 config_object (config_object const &rhs)
 Copy constructor. More...
 
 config_object (config_object &&rhs)
 Move constructor. More...
 
virtual ~config_object ()
 Destructor. More...
 
config_objectoperator= (config_object rhs)
 Copy & swap assignment. More...
 
void swap (config_object &rhs)
 Derived classes should implement member by member swap. More...
 
void load_overrides (int &argc, char *argv[], std::string const &filename, char const *environment_variable_name)
 Read the configuration file and load the overrides defined therein. More...
 
void load_overrides (int &argc, char *argv[], std::string const &filename)
 Read the configuration file and load the overrides defined therein. More...
 
void load_overrides (int &argc, char *argv[], std::istream &is)
 Read the configuration file and load the overrides defined therein. More...
 
void process_cmdline (int &argc, char *argv[])
 Process the command line. More...
 
virtual void validate () const
 Validate the settings. More...
 
std::ostream & to_stream (std::ostream &os) const
 Print out the settings. More...
 

Static Protected Member Functions

static attribute_descriptor desc (std::string const &name)
 Convenience function to create attribute descriptors with less typing. More...
 
static attribute_descriptor desc (std::string const &name, std::string const &class_name)
 Convenience function to create attribute descriptors with less typing. More...
 

Private Member Functions

void apply_overrides (YAML::Node const &by_name)
 Apply the overrides contained in the YAML document, compute the initial by_class overrides. More...
 
void apply_overrides (YAML::Node const &by_name, class_overrides const &by_class)
 Apply the overrides contained in the YAML document. More...
 
void auto_register (attribute_base *a)
 
void validate_attributes () const
 Run validate() on each attribute contained by this config_object. More...
 
void validate_all () const
 
void add_options (boost::program_options::options_description &options, std::string const &prefix, attribute_descriptor const &d) const
 Add the attributes of this config_object as command-line options. More...
 
void apply_cmdline_values (boost::program_options::variables_map const &vm, std::string const &prefix)
 Apply the values from the cmdline to this configuration object. More...
 
YAML::Node to_yaml () const
 Print out the configuration settings in YAML format. More...
 

Static Private Member Functions

static std::string cmdline_arg_name (std::string const &prefix, std::string const &name)
 Compute the full name of a command-line argument, given its prefix and short name. More...
 

Private Attributes

std::vector< attribute_base * > attributes_
 The list of attributes. More...
 

Friends

class generic_config_attribute
 
struct config_recurse
 Validate both the config_object and each attribute. More...
 

Detailed Description

Base class for all configuration objects.

A configuration object is a class derived from jb::config_object and having only members of jb::config_attribute type. Configuration objects can read overrides to their defaults from a YAML file.

Please

See also
listing:examples:configurations for some examples.

Definition at line 30 of file config_object.hpp.

Constructor & Destructor Documentation

◆ config_object() [1/3]

jb::config_object::config_object ( )

Default constructor.

Derived classes should initialize all their member attributes to their default values.

Definition at line 27 of file config_object.cpp.

◆ config_object() [2/3]

jb::config_object::config_object ( config_object const &  rhs)
inline

Copy constructor.

Derived classes should implement member-by-member copying using the config_attribute(container*, config_attribute const&) constructor.

Definition at line 50 of file config_object.hpp.

◆ config_object() [3/3]

jb::config_object::config_object ( config_object &&  rhs)
inline

Move constructor.

Derived classes should implement member-by-member move using the config_attribute(container*, config_attribute&&) constructor.

Definition at line 60 of file config_object.hpp.

◆ ~config_object()

virtual jb::config_object::~config_object ( )
inlinevirtual

Destructor.

Definition at line 65 of file config_object.hpp.

Member Function Documentation

◆ add_options()

void jb::config_object::add_options ( boost::program_options::options_description &  options,
std::string const &  prefix,
attribute_descriptor const &  d 
) const
private

Add the attributes of this config_object as command-line options.

Definition at line 138 of file config_object.cpp.

References attributes_, and jb::config_object::attribute_descriptor::helpmsg.

Referenced by jb::config_object::attribute_base::attribute_base(), and process_cmdline().

◆ apply_cmdline_values()

void jb::config_object::apply_cmdline_values ( boost::program_options::variables_map const &  vm,
std::string const &  prefix 
)
private

Apply the values from the cmdline to this configuration object.

Definition at line 149 of file config_object.cpp.

References attributes_, and cmdline_arg_name().

Referenced by jb::config_object::attribute_base::attribute_base(), and process_cmdline().

◆ apply_overrides() [1/2]

void jb::config_object::apply_overrides ( YAML::Node const &  by_name)
private

Apply the overrides contained in the YAML document, compute the initial by_class overrides.

Parameters
by_namea YAML document describing what values (and classes) to override.

Definition at line 69 of file config_object.cpp.

References jb::yaml::merge().

Referenced by jb::config_object::attribute_base::attribute_base(), desc(), and load_overrides().

◆ apply_overrides() [2/2]

void jb::config_object::apply_overrides ( YAML::Node const &  by_name,
class_overrides const &  by_class 
)
private

Apply the overrides contained in the YAML document.

Parameters
by_namea YAML document describing what values (and classes) to override.
by_classthe set of per-class overrides to apply

Definition at line 75 of file config_object.cpp.

References attributes_, jb::yaml::clone(), and jb::yaml::merge().

◆ auto_register()

void jb::config_object::auto_register ( attribute_base a)
private

Definition at line 156 of file config_object.cpp.

References attributes_.

Referenced by jb::config_object::attribute_base::attribute_base().

◆ cmdline_arg_name()

std::string jb::config_object::cmdline_arg_name ( std::string const &  prefix,
std::string const &  name 
)
staticprivate

Compute the full name of a command-line argument, given its prefix and short name.

Parameters
prefixthe prefix for the argument
namethe name of the argument

Definition at line 171 of file config_object.cpp.

Referenced by jb::config_recurse::add_options(), jb::config_recurse::apply_cmdline_values(), apply_cmdline_values(), and desc().

◆ desc() [1/2]

static attribute_descriptor jb::config_object::desc ( std::string const &  name)
inlinestaticprotected

Convenience function to create attribute descriptors with less typing.

Definition at line 240 of file config_object.hpp.

References jb::config_object::attribute_descriptor::attribute_descriptor().

Referenced by main().

◆ desc() [2/2]

static attribute_descriptor jb::config_object::desc ( std::string const &  name,
std::string const &  class_name 
)
inlinestaticprotected

Convenience function to create attribute descriptors with less typing.

Definition at line 246 of file config_object.hpp.

References apply_overrides(), jb::config_object::attribute_descriptor::attribute_descriptor(), cmdline_arg_name(), and jb::config_object::attribute_descriptor::name.

◆ load_overrides() [1/3]

void jb::config_object::load_overrides ( int &  argc,
char *  argv[],
std::string const &  filename,
char const *  environment_variable_name 
)

Read the configuration file and load the overrides defined therein.

Find the correct configuration file to load using jb::config_files_locations, then load the configuration file and apply the overrides from that file.

Parameters
argcthe number of command-line arguments
argvthe command-line arguments
filenamethe basename of the file to load
environment_variable_namethe name of the *_ROOT to use when searching for the configuration file.

Definition at line 31 of file config_object.cpp.

References jb::debug, JB_LOG, and process_cmdline().

Referenced by BOOST_AUTO_TEST_CASE(), load_overrides(), main(), and swap().

◆ load_overrides() [2/3]

void jb::config_object::load_overrides ( int &  argc,
char *  argv[],
std::string const &  filename 
)

Read the configuration file and load the overrides defined therein.

Find the correct configuration file to load using jb::config_files_locations, then load the configuration file and apply the overrides from that file.

Parameters
argcthe number of command-line arguments
argvthe command-line arguments
filenamethe basename of the file to load

Definition at line 47 of file config_object.cpp.

References jb::debug, JB_LOG, load_overrides(), and process_cmdline().

◆ load_overrides() [3/3]

void jb::config_object::load_overrides ( int &  argc,
char *  argv[],
std::istream &  is 
)

Read the configuration file and load the overrides defined therein.

Find the correct configuration file to load using jb::config_files_locations, then load the configuration file and apply the overrides from that file.

Parameters
argcthe number of command-line arguments
argvthe command-line arguments
isthe stream to load the configuration from.

Definition at line 62 of file config_object.cpp.

References apply_overrides(), and process_cmdline().

◆ operator=()

config_object& jb::config_object::operator= ( config_object  rhs)
inline

Copy & swap assignment.

Definition at line 71 of file config_object.hpp.

References swap().

◆ process_cmdline()

void jb::config_object::process_cmdline ( int &  argc,
char *  argv[] 
)

◆ swap()

void jb::config_object::swap ( config_object rhs)
inline

Derived classes should implement member by member swap.

Definition at line 79 of file config_object.hpp.

References load_overrides(), process_cmdline(), to_stream(), and validate().

Referenced by operator=().

◆ to_stream()

std::ostream & jb::config_object::to_stream ( std::ostream &  os) const

Print out the settings.

Definition at line 133 of file config_object.cpp.

References to_yaml().

Referenced by jb::operator<<(), and swap().

◆ to_yaml()

YAML::Node jb::config_object::to_yaml ( ) const
private

Print out the configuration settings in YAML format.

Definition at line 182 of file config_object.cpp.

References attributes_.

Referenced by jb::config_object::attribute_base::attribute_base(), and to_stream().

◆ validate()

void jb::config_object::validate ( ) const
virtual

◆ validate_all()

void jb::config_object::validate_all ( ) const
private

Definition at line 160 of file config_object.cpp.

References validate(), and validate_attributes().

Referenced by process_cmdline().

◆ validate_attributes()

void jb::config_object::validate_attributes ( ) const
private

Run validate() on each attribute contained by this config_object.

Definition at line 165 of file config_object.cpp.

References attributes_.

Referenced by validate_all().

Friends And Related Function Documentation

◆ config_recurse

friend struct config_recurse
friend

Validate both the config_object and each attribute.

Definition at line 287 of file config_object.hpp.

◆ generic_config_attribute

friend class generic_config_attribute
friend

Definition at line 280 of file config_object.hpp.

Member Data Documentation

◆ attributes_

std::vector<attribute_base*> jb::config_object::attributes_
private

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