conf::ConfValue< T > Class Template Reference

Template class implementing basics of value-setting directives. More...

#include <directives.h>

Inheritance diagram for conf::ConfValue< T >:

conf::ConfDir conf::ConfArray< ConfStrChar > conf::ConfEnum< T > conf::ConfHostname conf::ConfInt< T > conf::ConfSet< T > modules::LoadModule conf::ConfIntNZ< T > conf::ConfUint< T >

List of all members.

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

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 ?
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?
m_oldvalue
 The old value (valid only on reload, set in begin()).
std::string m_label
 The label of the value.


Detailed Description

template<class T>
class conf::ConfValue< T >

This template class is used as a base class for value-setting directive types. The template parameter is the type of the value, default value and old value that will be aggregated in the class. It must have a default constructor and a compatible operator==() function.

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.


Member Function Documentation

template<class T>
bool conf::ConfValue< T >::begin ( Conf conf  )  [inline, virtual]

Sets the old value.

Returns:
Always true.

Reimplemented from conf::ConfDir.

template<class T>
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.

template<class T>
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.

Returns:
true if successful, false otherwise.

Reimplemented from conf::ConfDir.

template<class T>
T const& conf::ConfValue< T >::value (  )  const [inline]

Gets the current value the directive is set to. Beware that it is not meaningful unless begin() and end() were called successfully.

Returns:
The value the directive is set to.

template<class T>
T const& conf::ConfValue< T >::old_value (  )  const [inline]

Returns the previous value the directive was set to. Beware that it is not meaningful unless begin() and end() were called and the configuration was reloaded.

Returns:
The previous value.

template<class T>
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).

Parameters:
[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).
Returns:
true if the function is successful, false otherwise (conf.error() should have be called with an appropriate error message in that case).

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 >.

template<class T>
virtual bool conf::ConfValue< T >::check ( Conf conf,
T const &  value 
) [inline, protected, virtual]

Checks that the given value is valid.

Parameters:
[in] conf Conf object that called set().
[in] value The value to check.
Returns:
true if the value is valid, false otherwise (conf.error() should have be called with an appropriate error message in that case).

template<class T>
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.

Returns:
true or false; the latter value will make the end() function return false too (conf.error() should have been called with an appropriate error message in that case).

template<class T>
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().

Returns:
true or false; the latter value will make the end() function return false too (conf.error() should have been called with an appropriate error message in that case).


The documentation for this class was generated from the following file:
Generated on Fri Apr 18 22:03:28 2008 for Epona API by  doxygen 1.5.3