OBT::ConfigurationItem Class Reference

#include <OBTConfigurationItem.h>

Collaboration diagram for OBT::ConfigurationItem:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 ConfigurationItem (const char *name)
virtual ~ConfigurationItem ()
const char * getName () const
const ConfigurationItemgetChild (unsigned int childNumber) const
std::vector< const
ConfigurationItem * > 
getChildren (const char *name) const
void addChild (const ConfigurationItem &child)
unsigned int getChildrenCount () const
const char * getArgument (const char *key) const
std::pair< const
char *, const char * > 
getArgument (unsigned int argument) const
void addArgument (const char *key, const char *value)
unsigned int getArgumentsCount () const
std::string traceConfigurationItems () const

Private Member Functions

ConfigurationItemtouchChild (unsigned int childNumber)
std::vector
< ConfigurationItem * > 
touchChildren (const char *name)

Private Attributes

std::string _name
 configuration item name
std::map
< std::string,
std::string > 
_arguments
 arguments
std::vector
< ConfigurationItem
_children
 children

Friends

class AbstractConfigurationFileParser


Detailed Description

Node of the configuration items tree.

Author:
Michaël Rouillé <michael.rouille@gmail.com>
This class is used to fill the configuration tree. Each configuration item is defined by :

Definition at line 21 of file OBTConfigurationItem.h.


Constructor & Destructor Documentation

ConfigurationItem::ConfigurationItem ( const char *  name  ) 

constructor

Definition at line 8 of file OBTConfigurationItem.cpp.

00009 :
00010 _name( name )
00011 {
00012    
00013 }

ConfigurationItem::~ConfigurationItem (  )  [virtual]

destructor

Definition at line 18 of file OBTConfigurationItem.cpp.

00019 {  
00020 }


Member Function Documentation

const char * OBT::ConfigurationItem::getName (  )  const [inline]

accessor to the configuration item name

Returns:
the configuration item name

Definition at line 131 of file OBTConfigurationItem.h.

References _name.

Referenced by traceConfigurationItems().

00132         {
00133                 return _name.c_str() ;
00134         }

const ConfigurationItem & OBT::ConfigurationItem::getChild ( unsigned int  childNumber  )  const [inline]

accessor to a child

Parameters:
childNumber number of the child to retrieve
Returns:
a const reference to the child childNumber
Exceptions:
TVN_Exception [DEBUG only] if childNumber is out of bounds.

Definition at line 140 of file OBTConfigurationItem.h.

References _children.

Referenced by traceConfigurationItems().

00141         {
00142                 return _children.at( childNumber ) ;
00143         }

std::vector< const ConfigurationItem * > ConfigurationItem::getChildren ( const char *  name  )  const

accessor to the configuration items childrem named name

Parameters:
name of the children to return
Returns:
a vector of children named name

Definition at line 26 of file OBTConfigurationItem.cpp.

References _children, and _name.

00027 {
00028         std::vector<const ConfigurationItem*> configItems ;
00029         if ( name == _name )
00030         {
00031                 configItems.push_back( this ) ;
00032         }
00033         std::vector<const ConfigurationItem*> returnedItems ;
00034         std::string str( name ) ;
00035         std::vector<ConfigurationItem>::const_iterator ite( _children.begin() ) ;
00036         std::vector<ConfigurationItem>::const_iterator iteE( _children.end() ) ;
00037         for ( ; ite != iteE ; ++ite )
00038         {
00039                 returnedItems = ite->getChildren( name ) ;
00040                 if ( returnedItems.size() != 0 )
00041                 {
00042                         configItems.insert( configItems.end(), returnedItems.begin(), returnedItems.end() ) ;
00043                 }
00044         }
00045         return configItems ;
00046 }

void OBT::ConfigurationItem::addChild ( const ConfigurationItem child  )  [inline]

add a child to the configuration item

Parameters:
child const reference to the child to add

Definition at line 158 of file OBTConfigurationItem.h.

References _children.

Referenced by OBT::ConfigurationTree::addChild(), and OBT::XMLConfigurationFileParser::AddChildren().

00159         {
00160                 _children.push_back( child ) ;
00161         }

unsigned int OBT::ConfigurationItem::getChildrenCount (  )  const [inline]

accessor to the children count

Returns:
the children count

Definition at line 167 of file OBTConfigurationItem.h.

References _children.

Referenced by traceConfigurationItems().

00168         {
00169                 return static_cast<unsigned int>( _children.size() ) ;
00170         }

const char * OBT::ConfigurationItem::getArgument ( const char *  key  )  const [inline]

accessor to the value of an argument

Parameters:
key of the argument
Returns:
the value of the argument referenced by key

Definition at line 176 of file OBTConfigurationItem.h.

References _arguments.

Referenced by traceConfigurationItems().

00177         {
00178                 std::map<std::string, std::string>::const_iterator ite( _arguments.find( key ) ) ;
00179                 if ( ite != _arguments.end() )
00180                 {
00181                         return ite->second.c_str() ;
00182                 }
00183                 else
00184                 {
00185                         return NULL ;
00186                 }
00187         }

std::pair< const char *, const char * > OBT::ConfigurationItem::getArgument ( unsigned int  argument  )  const [inline]

accessor to the key and value of an argument

Parameters:
argument number of the argument to retrieve
Returns:
a pair of the key and value of the argument

Definition at line 202 of file OBTConfigurationItem.h.

References _arguments.

00203         {
00204                 std::map<std::string, std::string>::const_iterator ite( _arguments.begin() ) ;
00205                 for ( ; argument != 0; --argument )
00206                 {
00207                         ++ite ;
00208                 }
00209                 return std::pair< const char*, const char* >( ite->first.c_str(), ite->second.c_str() ) ;
00210         }

void OBT::ConfigurationItem::addArgument ( const char *  key,
const char *  value 
) [inline]

add an argument to the configuration item

Parameters:
key of the argument
value of the argument

Definition at line 216 of file OBTConfigurationItem.h.

References _arguments.

00217         {
00218                 _arguments.insert( std::make_pair( key, value ) ) ;
00219         }

unsigned int OBT::ConfigurationItem::getArgumentsCount (  )  const [inline]

accessor to the arguments count

Returns:
the arguments count

Definition at line 193 of file OBTConfigurationItem.h.

References _arguments.

Referenced by traceConfigurationItems().

00194         {
00195                 return static_cast< unsigned int >( _arguments.size( ) ) ;
00196         }

std::string ConfigurationItem::traceConfigurationItems (  )  const

fill a string with the configuration items name, arguments and children

Returns:
a string representing the configuration items tree

Definition at line 78 of file OBTConfigurationItem.cpp.

References getArgument(), getArgumentsCount(), getChild(), getChildrenCount(), getName(), and traceConfigurationItems().

Referenced by traceConfigurationItems().

00079 {
00080         static std::string tabString ;
00081         std::string result ;
00082         result += tabString ;
00083         result += getName() ;
00084 
00085         std::pair< const char*, const char* > argument ;
00086         unsigned int nArguments = getArgumentsCount() ;
00087         for ( unsigned int i = 0 ; i < nArguments ; ++i )
00088         {
00089                 argument = getArgument( i ) ;
00090                 result += " " ;
00091                 result += argument.first ;
00092                 result += "=" ;
00093                 result += argument.second ;
00094         }
00095 
00096         result += "\n" ;
00097 
00098         unsigned int nChildren = getChildrenCount() ;
00099         for ( unsigned int i = 0 ; i < nChildren ; ++i )
00100         {
00101                 tabString += "   " ;
00102                 result += getChild( i ).traceConfigurationItems() ;
00103                 tabString = tabString.substr( 0, tabString.size() - 3 ) ;
00104         }
00105         return result ;
00106 }

ConfigurationItem & OBT::ConfigurationItem::touchChild ( unsigned int  childNumber  )  [inline, private]

accessor to a child

Parameters:
childNumber number of the child to retrieve
Returns:
a reference to the child childNumber

Definition at line 149 of file OBTConfigurationItem.h.

References _children.

Referenced by OBT::AbstractConfigurationFileParser::touchChild().

00150         {
00151                 return _children.at( childNumber ) ;
00152         }

std::vector< ConfigurationItem * > ConfigurationItem::touchChildren ( const char *  name  )  [private]

accessor to the configuration items childrem named name

Parameters:
name of the children to return
Returns:
a vector of children named name

Definition at line 52 of file OBTConfigurationItem.cpp.

References _children, and _name.

00053 {
00054         std::vector< ConfigurationItem*> configItems ;
00055         if ( name == _name )
00056         {
00057                 configItems.push_back( this ) ;
00058         }
00059         std::vector< ConfigurationItem*> returnedItems ;
00060         std::string str( name ) ;
00061         std::vector<ConfigurationItem>::iterator ite( _children.begin() ) ;
00062         std::vector<ConfigurationItem>::iterator iteE( _children.end() ) ;
00063         for ( ; ite != iteE ; ++ite )
00064         {
00065                 returnedItems = ite->touchChildren( name ) ;
00066                 if ( returnedItems.size() != 0 )
00067                 {
00068                         configItems.insert( configItems.end(), returnedItems.begin(), returnedItems.end() ) ;
00069                 }
00070         }
00071         return configItems ;
00072 }


Friends And Related Function Documentation

friend class AbstractConfigurationFileParser [friend]

Definition at line 25 of file OBTConfigurationItem.h.


Member Data Documentation

std::string OBT::ConfigurationItem::_name [private]

configuration item name

Definition at line 120 of file OBTConfigurationItem.h.

Referenced by getChildren(), getName(), and touchChildren().

std::map<std::string, std::string> OBT::ConfigurationItem::_arguments [private]

arguments

Definition at line 122 of file OBTConfigurationItem.h.

Referenced by addArgument(), getArgument(), and getArgumentsCount().

std::vector<ConfigurationItem> OBT::ConfigurationItem::_children [private]

children

Definition at line 124 of file OBTConfigurationItem.h.

Referenced by addChild(), getChild(), getChildren(), getChildrenCount(), touchChild(), and touchChildren().


Generated on Wed Oct 1 11:34:18 2008 for OBT by  doxygen 1.5.3