JayBeams
0.1
Another project to have fun coding.
|
Base class for all configuration objects. More...
#include <config_object.hpp>
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_object & | operator= (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... | |
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
Definition at line 30 of file config_object.hpp.
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.
|
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.
|
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.
|
inlinevirtual |
Destructor.
Definition at line 65 of file config_object.hpp.
|
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().
|
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().
|
private |
Apply the overrides contained in the YAML document, compute the initial by_class overrides.
by_name | a 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().
|
private |
Apply the overrides contained in the YAML document.
by_name | a YAML document describing what values (and classes) to override. |
by_class | the 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().
|
private |
Definition at line 156 of file config_object.cpp.
References attributes_.
Referenced by jb::config_object::attribute_base::attribute_base().
|
staticprivate |
Compute the full name of a command-line argument, given its prefix and short name.
prefix | the prefix for the argument |
name | the 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().
|
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().
|
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.
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.
argc | the number of command-line arguments |
argv | the command-line arguments |
filename | the basename of the file to load |
environment_variable_name | the 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().
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.
argc | the number of command-line arguments |
argv | the command-line arguments |
filename | the 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().
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.
argc | the number of command-line arguments |
argv | the command-line arguments |
is | the stream to load the configuration from. |
Definition at line 62 of file config_object.cpp.
References apply_overrides(), and process_cmdline().
|
inline |
void jb::config_object::process_cmdline | ( | int & | argc, |
char * | argv[] | ||
) |
Process the command line.
Definition at line 95 of file config_object.cpp.
References add_options(), apply_cmdline_values(), attributes_, and validate_all().
Referenced by BOOST_AUTO_TEST_CASE(), load_overrides(), main(), jb::testing::microbenchmark_group_main(), and swap().
|
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=().
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().
|
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().
|
virtual |
Validate the settings.
jb::usage | if a problem is detected. |
Reimplemented in jb::offline_feed_statistics::config, jb::itch5::array_based_order_book::config, jb::book_depth_statistics::config, jb::log::config, jb::itch5::map_based_order_book::config, jb::itch5::udp_receiver_config, and jb::itch5::mold_udp_pacer_config.
Definition at line 130 of file config_object.cpp.
Referenced by jb::config_object::attribute_base::attribute_base(), swap(), jb::itch5::udp_receiver_config::validate(), and validate_all().
|
private |
Definition at line 160 of file config_object.cpp.
References validate(), and validate_attributes().
Referenced by process_cmdline().
|
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().
|
friend |
Validate both the config_object and each attribute.
Definition at line 287 of file config_object.hpp.
|
friend |
Definition at line 280 of file config_object.hpp.
|
private |
The list of attributes.
Definition at line 309 of file config_object.hpp.
Referenced by add_options(), apply_cmdline_values(), apply_overrides(), auto_register(), process_cmdline(), to_yaml(), and validate_attributes().