#include <directives.h>
Public Types | |
typedef T | value_type |
The value type. | |
Public Member Functions | |
ConfValue (std::string const &name, bool reloadable, unsigned short min_params=1, unsigned short max_params=1) | |
Constructor setting directive name, reloadability and min./max. | |
ConfValue (std::string const &name, T const &defval, bool reloadable, unsigned short min_params=1, unsigned short max_params=1) | |
Constructor also setting the default value... | |
ConfValue (ConfValue const &cd) | |
Copy constructor. | |
virtual ConfValue< T > & | operator= (ConfValue< T > const &right) |
Assignment operator. | |
virtual bool | begin (Conf &conf) |
Begin parsing. | |
virtual bool | set (Conf &conf, unsigned short count, std::string const params[]) |
Sets the value. | |
virtual bool | end (Conf &conf) |
End parsing. | |
T const & | value () const |
Gets the value. | |
bool | has_value_changed () const |
Returns whether the value was changed by a configuration reload. | |
bool | has_default () const |
Returns whether a default value is available. | |
T const & | old_value () const |
Returns the old value. | |
virtual char const * | label (size_t index) const |
Implements ConfDir::label(). | |
virtual size_t | label_count () const |
Implements ConfDir::label_count(). | |
Protected Member Functions | |
virtual bool | assign (Conf &conf, unsigned short count, std::string const params[])=0 |
Sets the value. | |
virtual bool | check (Conf &conf, T const &value) |
Checks that a value is valid. | |
virtual bool | apply (Conf &conf) |
Does stuff based on the directive new value. | |
virtual bool | apply_change (Conf &conf) |
Lets the directive apply change. | |
Protected Attributes | |
T | m_value |
The value. | |
bool | m_value_set |
Has m_value been set? (Set to false again by end()). | |
bool | m_value_changed |
Is m_value different from m_oldvalue ? | |
T | m_defvalue |
The default value (don't use if m_has_default is false!). | |
bool | m_has_default |
Is m_default a valid default value? | |
T | m_oldvalue |
The old value (valid only on reload, set in begin()). | |
std::string | m_label |
The label of the value. |
Each of these directives have a value and an optional default value to which the value will be set if the set() function is not called before the end() function is (i.e. when the parser did not encounter the directive). If there is no default value, then setting the directive is REQUIRED and end() will yield false if it isn't the case.
On reload, the old value will saved so that you can do changes that would require you to know the old value easily.
bool conf::ConfValue< T >::begin | ( | Conf & | conf | ) | [inline, virtual] |
bool conf::ConfValue< T >::set | ( | Conf & | conf, | |
unsigned short | count, | |||
std::string const | params[] | |||
) | [inline, virtual] |
Just calls assign to set the value... What a lazy function. ;)
Reimplemented from conf::ConfDir.
bool conf::ConfValue< T >::end | ( | Conf & | conf | ) | [inline, virtual] |
Ensures a value has been set by the set() function. If so, calls apply_change() if the conf.reloading() is true and value changed; else sets it to the default value if available or sends an error message.
Reimplemented from conf::ConfDir.
T const& conf::ConfValue< T >::value | ( | ) | const [inline] |
T const& conf::ConfValue< T >::old_value | ( | ) | const [inline] |
virtual bool conf::ConfValue< T >::assign | ( | Conf & | conf, | |
unsigned short | count, | |||
std::string const | params[] | |||
) | [protected, pure virtual] |
Transforms the string array passed by the parser into the directive's value. This function must ensure that the value is valid through a call to check() before setting it (you don't need to set m_value_set to true, this will be handled by set() when the function returns successfully).
[in] | conf | The Conf object that called set(). |
[in] | count | Number of parameters in params. |
[in] | params | Parameters passed to the directive (NULL if count is 0). |
Implemented in conf::ConfBool, conf::ConfDuration, conf::ConfEnum< T >, conf::ConfHostname, conf::ConfInt< T >, conf::ConfRatio, conf::ConfSet< T >, conf::ConfStr, conf::ConfURI, conf::ConfArray< ValueT, ContainerT >, conf::ConfInt< uint16_t >, conf::ConfArray< modules::ConfModule, std::vector< modules::ConfModule > >, and conf::ConfArray< ConfStrChar >.
virtual bool conf::ConfValue< T >::check | ( | Conf & | conf, | |
T const & | value | |||
) | [inline, protected, virtual] |
virtual bool conf::ConfValue< T >::apply | ( | Conf & | conf | ) | [inline, protected, virtual] |
Does arbitrary stuff based on the directive new value. This is guaranteed to be called by the end() function when the directive is successfully loaded or reloaded.
virtual bool conf::ConfValue< T >::apply_change | ( | Conf & | conf | ) | [inline, protected, virtual] |
Like apply(), but will only be called after the directive has been reloaded, if and only if the new value is different than the old. This function is called before apply().