conf::ConfArray< ValueT, ContainerT > Class Template Reference

Class implementing an array of values directive type. More...

#include <directives.h>

Inheritance diagram for conf::ConfArray< ValueT, ContainerT >:

conf::ConfValue< ContainerT > conf::ConfDir List of all members.

Public Types

typedef ValueT value_type
 The value type.
typedef ContainerT container_type

Public Member Functions

 ConfArray (std::string const &name, bool reloadable=true, typename ContainerT::size_type max=INT_MAX)
 Constructor.
 ConfArray (std::string const &name, ContainerT const &defval, bool reloadable=true, typename ContainerT::size_type max=INT_MAX)
 Constructor setting a default value.
 ConfArray (ConfArray const &cd)
 Copy constructor.
virtual ConfArray< ValueT,
ContainerT > & 
operator= (ConfArray< ValueT, ContainerT > const &right)
 Assignment operator.
 operator ContainerT const & () const
 Conversion operator.
ContainerT const & operator * () const
 Provides access to the underlying container.
ContainerT const * operator-> () const
 Provides access to the underlying container.
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[])
 Sets the value.
virtual ContainerT::iterator insert ()
 Inserts a new ValueT object in the container.

Protected Attributes

ContainerT::size_type m_max_values

Detailed Description

template<class ValueT, class ContainerT = std::vector<ValueT>>
class conf::ConfArray< ValueT, ContainerT >

This class is a metaclass implementing an array of values. To achieve that, it creates new ConfDir (or derived) objects on the fly, giving them a name in the form name[n] where name is the directive name and n is their index, and calls begin(), set() and end() to set them accordingly.

The template also lets you choose the container type you want to use to implement the array (it will work as long as the container has insert(iterator pos, T const &value), clear() and size() functions -- which is the case of all containers of the C++ STL.

Operators * and -> are overloaded so you can easily access the internal container object. A conversion operator to the container type is also provided.

Example of use:

ConfArray<ConfBool, std::vector<ConfBool> > array;

Caveat:


Constructor & Destructor Documentation

template<class ValueT, class ContainerT = std::vector<ValueT>>
conf::ConfArray< ValueT, ContainerT >::ConfArray std::string const &  name,
bool  reloadable = true,
typename ContainerT::size_type  max = INT_MAX
[inline, explicit]
 

This constructor sets the directive name and the maximum number of values that can be added to the container.

Parameters:
[in] name The directive name.
[in] reloadable Whether the directive can be reloaded or not.
[in] max The maximum number of values.

template<class ValueT, class ContainerT = std::vector<ValueT>>
conf::ConfArray< ValueT, ContainerT >::ConfArray std::string const &  name,
ContainerT const &  defval,
bool  reloadable = true,
typename ContainerT::size_type  max = INT_MAX
[inline]
 

This constructor sets the directive name, default value and the maximum number of values that can be added to the container.

Parameters:
[in] name The directive name.
[in] defval The default value.
[in] reloadable Whether the directive can be reloaded or not.
[in] max The maximum number of values.


Member Function Documentation

template<class ValueT, class ContainerT>
bool conf::ConfArray< ValueT, ContainerT >::assign Conf conf,
unsigned short  count,
std::string const   params[]
[protected, 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).

Implements conf::ConfValue< ContainerT >.

template<class ValueT, class ContainerT>
ContainerT::iterator conf::ConfArray< ValueT, ContainerT >::insert  )  [protected, virtual]
 

Inserts a new ValueT directive (that the function is responsible to create) in the container, through a call to the ContainerT::insert(iterator, ValueT) function. It must name the new directive as the name[n] where name is this directive name and n is ContainerT::size().

Returns:
An iterator pointing to the newly-added directive.


The documentation for this class was generated from the following file:
Generated on Sun May 20 21:32:18 2007 for Epona API by  doxygen 1.4.6