JayBeams  0.1
Another project to have fun coding.
Public Types | Public Member Functions | Private Attributes | Friends | List of all members
jb::config_attribute< C, T > Class Template Reference

Helper class to easily define configuration attributes. More...

#include <config_attribute.hpp>

Inheritance diagram for jb::config_attribute< C, T >:
jb::config_object::attribute_base

Public Types

typedef C container_type
 
typedef T value_type
 

Public Member Functions

void swap (config_attribute< container_type, value_type > &rhs)
 Swap values, containers are not changed. More...
 
value_type const & operator() () const
 Accessor. More...
 
container_typeoperator() (value_type const &x)
 Modify value. More...
 
container_typeoperator() (value_type &&x)
 Modify value with move semantics. More...
 
- Public Member Functions inherited from jb::config_object::attribute_base
virtual ~attribute_base ()=0
 Destructor. More...
 
attribute_descriptor const & descriptor () const
 
std::string const & name () const
 
std::string const & class_name () const
 
std::string const & help () const
 
bool positional () const
 

Private Member Functions

Configuration object recursion functions.
void apply_overrides (YAML::Node const &by_name, class_overrides const &by_class) override
 Call the right version of jb::apply_overrides for the contained value. More...
 
void add_options (boost::program_options::options_description &options, std::string const &prefix, config_object::attribute_descriptor const &d) const override
 Call the right version of jb::add_options for the contained value. More...
 
void apply_cmdline_values (boost::program_options::variables_map const &vm, std::string const &name) override
 Call the right version of jb::apply_cmdline_values. More...
 
void validate () const override
 Call the right version of jb::validate. More...
 
YAML::Node to_yaml () const override
 Print out the configuration settings in YAML format. More...
 

Private Attributes

container_type *const container_
 
value_type value_
 

Friends

struct config_recurse
 

Constructors

friend container_type
 
 config_attribute (container_type *container)
 
 config_attribute (config_object::attribute_descriptor const &d, container_type *container)
 
 config_attribute (container_type *container, value_type const &t)
 
 config_attribute (config_object::attribute_descriptor const &d, container_type *container, value_type const &t)
 
 config_attribute (container_type *container, value_type &&t)
 
 config_attribute (config_object::attribute_descriptor const &d, container_type *container, value_type &&t)
 
template<typename... Args>
 config_attribute (container_type *container, Args &&... args)
 
template<typename... Args>
 config_attribute (config_object::attribute_descriptor const &d, container_type *container, Args &&... args)
 
 config_attribute (container_type *container, config_attribute< container_type, value_type > &&rhs)
 
 config_attribute (container_type *container, config_attribute< container_type, value_type > const &rhs)
 
 config_attribute (config_attribute< container_type, value_type > &&)=delete
 
 config_attribute (config_attribute< container_type, value_type > const &)=delete
 
config_attributeoperator= (config_attribute< container_type, value_type > &&rhs)
 
config_attributeoperator= (config_attribute< container_type, value_type > const &rhs)
 

Additional Inherited Members

- Protected Member Functions inherited from jb::config_object::attribute_base
 attribute_base (attribute_descriptor const &d, config_object *container)
 Constructor. More...
 
template<typename container_type >
 attribute_base (container_type *)
 

Detailed Description

template<typename C, typename T>
class jb::config_attribute< C, T >

Helper class to easily define configuration attributes.

The Jaybeams configuration framework requires all configuration objects to define accessors and modifiers for each attribute that follow this pattern:

class Config {
public:
Config(); // default constructor sets to compile-time defaults.
int attribute() const; // return current attribute value
Config& attribute(int x); // set current value, chainable
};
Config cfg;
cfg.attribute(1).another(2);

This is a helper class to create such attributes easily.

Template Parameters
Cthe type of the object that contains the attribute
Tthe type of the object contained in this attribute

Definition at line 54 of file config_attribute.hpp.

Member Typedef Documentation

◆ container_type

template<typename C, typename T>
typedef C jb::config_attribute< C, T >::container_type

Definition at line 56 of file config_attribute.hpp.

◆ value_type

template<typename C, typename T>
typedef T jb::config_attribute< C, T >::value_type

Definition at line 57 of file config_attribute.hpp.

Constructor & Destructor Documentation

◆ config_attribute() [1/12]

template<typename C, typename T>
jb::config_attribute< C, T >::config_attribute ( container_type container)
inlineexplicitprivate

◆ config_attribute() [2/12]

template<typename C, typename T>
jb::config_attribute< C, T >::config_attribute ( config_object::attribute_descriptor const &  d,
container_type container 
)
inlineprivate

Definition at line 94 of file config_attribute.hpp.

◆ config_attribute() [3/12]

template<typename C, typename T>
jb::config_attribute< C, T >::config_attribute ( container_type container,
value_type const &  t 
)
inlineprivate

Definition at line 101 of file config_attribute.hpp.

◆ config_attribute() [4/12]

template<typename C, typename T>
jb::config_attribute< C, T >::config_attribute ( config_object::attribute_descriptor const &  d,
container_type container,
value_type const &  t 
)
inlineprivate

Definition at line 107 of file config_attribute.hpp.

◆ config_attribute() [5/12]

template<typename C, typename T>
jb::config_attribute< C, T >::config_attribute ( container_type container,
value_type &&  t 
)
inlineprivate

Definition at line 115 of file config_attribute.hpp.

◆ config_attribute() [6/12]

template<typename C, typename T>
jb::config_attribute< C, T >::config_attribute ( config_object::attribute_descriptor const &  d,
container_type container,
value_type &&  t 
)
inlineprivate

Definition at line 121 of file config_attribute.hpp.

◆ config_attribute() [7/12]

template<typename C, typename T>
template<typename... Args>
jb::config_attribute< C, T >::config_attribute ( container_type container,
Args &&...  args 
)
inlineprivate

Definition at line 130 of file config_attribute.hpp.

◆ config_attribute() [8/12]

template<typename C, typename T>
template<typename... Args>
jb::config_attribute< C, T >::config_attribute ( config_object::attribute_descriptor const &  d,
container_type container,
Args &&...  args 
)
inlineprivate

Definition at line 137 of file config_attribute.hpp.

◆ config_attribute() [9/12]

template<typename C, typename T>
jb::config_attribute< C, T >::config_attribute ( container_type container,
config_attribute< container_type, value_type > &&  rhs 
)
inlineprivate

Definition at line 145 of file config_attribute.hpp.

◆ config_attribute() [10/12]

template<typename C, typename T>
jb::config_attribute< C, T >::config_attribute ( container_type container,
config_attribute< container_type, value_type > const &  rhs 
)
inlineprivate

Definition at line 153 of file config_attribute.hpp.

◆ config_attribute() [11/12]

template<typename C, typename T>
jb::config_attribute< C, T >::config_attribute ( config_attribute< container_type, value_type > &&  )
privatedelete

◆ config_attribute() [12/12]

template<typename C, typename T>
jb::config_attribute< C, T >::config_attribute ( config_attribute< container_type, value_type > const &  )
privatedelete

Member Function Documentation

◆ add_options()

template<typename C, typename T>
void jb::config_attribute< C, T >::add_options ( boost::program_options::options_description &  options,
std::string const &  prefix,
config_object::attribute_descriptor const &  d 
) const
inlineoverrideprivatevirtual

Call the right version of jb::add_options for the contained value.

Implements jb::config_object::attribute_base.

Definition at line 189 of file config_attribute.hpp.

◆ apply_cmdline_values()

template<typename C, typename T>
void jb::config_attribute< C, T >::apply_cmdline_values ( boost::program_options::variables_map const &  vm,
std::string const &  name 
)
inlineoverrideprivatevirtual

Call the right version of jb::apply_cmdline_values.

Implements jb::config_object::attribute_base.

Definition at line 197 of file config_attribute.hpp.

Referenced by jb::config_recurse::apply_cmdline_values().

◆ apply_overrides()

template<typename C, typename T>
void jb::config_attribute< C, T >::apply_overrides ( YAML::Node const &  by_name,
class_overrides const &  by_class 
)
inlineoverrideprivatevirtual

Call the right version of jb::apply_overrides for the contained value.

Implements jb::config_object::attribute_base.

Definition at line 183 of file config_attribute.hpp.

Referenced by jb::config_recurse::apply_overrides().

◆ operator()() [1/3]

template<typename C, typename T>
value_type const& jb::config_attribute< C, T >::operator() ( ) const
inline

Accessor.

Definition at line 65 of file config_attribute.hpp.

◆ operator()() [2/3]

template<typename C, typename T>
container_type& jb::config_attribute< C, T >::operator() ( value_type const &  x)
inline

Modify value.

Definition at line 70 of file config_attribute.hpp.

◆ operator()() [3/3]

template<typename C, typename T>
container_type& jb::config_attribute< C, T >::operator() ( value_type &&  x)
inline

Modify value with move semantics.

Definition at line 76 of file config_attribute.hpp.

◆ operator=() [1/2]

template<typename C, typename T>
config_attribute& jb::config_attribute< C, T >::operator= ( config_attribute< container_type, value_type > &&  rhs)
inlineprivate

Definition at line 166 of file config_attribute.hpp.

◆ operator=() [2/2]

template<typename C, typename T>
config_attribute& jb::config_attribute< C, T >::operator= ( config_attribute< container_type, value_type > const &  rhs)
inlineprivate

Definition at line 171 of file config_attribute.hpp.

◆ swap()

template<typename C, typename T>
void jb::config_attribute< C, T >::swap ( config_attribute< container_type, value_type > &  rhs)
inline

Swap values, containers are not changed.

Definition at line 60 of file config_attribute.hpp.

◆ to_yaml()

template<typename C, typename T>
YAML::Node jb::config_attribute< C, T >::to_yaml ( ) const
inlineoverrideprivatevirtual

Print out the configuration settings in YAML format.

Implements jb::config_object::attribute_base.

Definition at line 209 of file config_attribute.hpp.

Referenced by jb::config_recurse::to_yaml().

◆ validate()

template<typename C, typename T>
void jb::config_attribute< C, T >::validate ( ) const
inlineoverrideprivatevirtual

Call the right version of jb::validate.

Implements jb::config_object::attribute_base.

Definition at line 204 of file config_attribute.hpp.

Referenced by jb::config_recurse::validate().

Friends And Related Function Documentation

◆ config_recurse

template<typename C, typename T>
friend struct config_recurse
friend

Definition at line 177 of file config_attribute.hpp.

Member Data Documentation

◆ container_

template<typename C, typename T>
container_type* const jb::config_attribute< C, T >::container_
private

◆ container_type

template<typename C, typename T>
friend jb::config_attribute< C, T >::container_type
private

Definition at line 88 of file config_attribute.hpp.

◆ value_

template<typename C, typename T>
value_type jb::config_attribute< C, T >::value_
private

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