1 #ifndef jb_config_object_hpp 2 #define jb_config_object_hpp 7 #include <boost/program_options/options_description.hpp> 8 #include <boost/program_options/variables_map.hpp> 9 #include <yaml-cpp/yaml.h> 17 struct config_recurse;
97 int& argc,
char* argv[], std::string
const& filename,
98 char const* environment_variable_name);
112 void load_overrides(
int& argc,
char* argv[], std::string
const& filename);
143 std::ostream&
to_stream(std::ostream& os)
const;
187 template <
typename container_type>
202 boost::program_options::options_description& options,
207 boost::program_options::variables_map
const& vm,
208 std::string
const&
name) = 0;
215 virtual YAML::Node
to_yaml()
const = 0;
221 std::string
const&
name()
const {
222 return descriptor_.name;
225 return descriptor_.class_name;
227 std::string
const&
help()
const {
228 return descriptor_.helpmsg;
231 return descriptor_.is_positional;
294 boost::program_options::options_description& options,
301 boost::program_options::variables_map
const& vm,
302 std::string
const& prefix);
318 #define config_object_constructors(NAME) \ 321 operator=(std::move(rhs)); \ 323 NAME(NAME const& rhs) \ 327 NAME& operator=(NAME const& rhs) = default; \ 328 NAME& operator=(NAME&& rhs) = default 332 #endif // jb_config_object_hpp config_object(config_object const &rhs)
Copy constructor.
void swap(config_object &rhs)
Derived classes should implement member by member swap.
attribute_descriptor(std::string const &n)
Base class for all configuration objects.
friend class generic_config_attribute
virtual void validate() const
Validate the settings.
std::ostream & operator<<(std::ostream &os, as_hhmmssu const &x)
Format as_hhmmssu into an iostream.
void validate_attributes() const
Run validate() on each attribute contained by this config_object.
Breakout some of the helper classes from jb/config_object.hpp.
std::map< std::string, YAML::Node > class_overrides
Store the overrides for each class.
std::string const & name() const
attribute_descriptor const & descriptor() const
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.
attribute_descriptor const descriptor_
std::string const & class_name() const
config_object()
Default constructor.
config_object & operator=(config_object rhs)
Copy & swap assignment.
std::vector< attribute_base * > attributes_
The list of attributes.
static attribute_descriptor desc(std::string const &name, std::string const &class_name)
Convenience function to create attribute descriptors with less typing.
attribute_base(container_type *)
std::ostream & to_stream(std::ostream &os) const
Print out the settings.
void auto_register(attribute_base *a)
std::string const & help() const
Define the interface to manipulate and access configuration attributes embedded in a config_object...
virtual ~config_object()
Destructor.
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.
config_object(config_object &&rhs)
Move constructor.
Recursively apply functions to config_object, attributes, and sequences of config objects...
void process_cmdline(int &argc, char *argv[])
Process the command line.
YAML::Node to_yaml() const
Print out the configuration settings in YAML format.
static attribute_descriptor desc(std::string const &name)
Convenience function to create attribute descriptors with less typing.
void apply_overrides(YAML::Node const &by_name)
Apply the overrides contained in the YAML document, compute the initial by_class overrides.
attribute_descriptor(std::string const &n, std::string const &c)
void validate_all() const
attribute_descriptor & help(std::string const &h)
attribute_descriptor & positional()
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.
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.
The top-level namespace for the JayBeams library.