00001 #include "OBTConfigurationItem.h"
00002
00003 using namespace OBT ;
00004
00005
00006
00007
00008 ConfigurationItem::ConfigurationItem( const char* name )
00009 :
00010 _name( name ),
00011 _text(),
00012 _line(0),
00013 _column(0)
00014 {
00015
00016 }
00017
00018
00019
00020
00021 ConfigurationItem::~ConfigurationItem()
00022 {
00023 }
00024
00025
00026
00027
00028 std::vector<const ConfigurationItem*>
00029 ConfigurationItem::getChildren( const char* name ) const
00030 {
00031 std::vector<const ConfigurationItem*> configItems ;
00032 if ( name == _name )
00033 {
00034 configItems.push_back( this ) ;
00035 }
00036 std::vector<const ConfigurationItem*> returnedItems ;
00037 std::string str( name ) ;
00038 std::vector<ConfigurationItem>::const_iterator ite( _children.begin() ) ;
00039 std::vector<ConfigurationItem>::const_iterator iteE( _children.end() ) ;
00040 for ( ; ite != iteE ; ++ite )
00041 {
00042 returnedItems = ite->getChildren( name ) ;
00043 if ( returnedItems.size() != 0 )
00044 {
00045 configItems.insert( configItems.end(), returnedItems.begin(), returnedItems.end() ) ;
00046 }
00047 }
00048 return configItems ;
00049 }
00050
00051
00052
00053
00054 std::vector<ConfigurationItem*>
00055 ConfigurationItem::touchChildren( const char* name )
00056 {
00057 std::vector< ConfigurationItem*> configItems ;
00058 if ( name == _name )
00059 {
00060 configItems.push_back( this ) ;
00061 }
00062 std::vector< ConfigurationItem*> returnedItems ;
00063 std::string str( name ) ;
00064 std::vector<ConfigurationItem>::iterator ite( _children.begin() ) ;
00065 std::vector<ConfigurationItem>::iterator iteE( _children.end() ) ;
00066 for ( ; ite != iteE ; ++ite )
00067 {
00068 returnedItems = ite->touchChildren( name ) ;
00069 if ( returnedItems.size() != 0 )
00070 {
00071 configItems.insert( configItems.end(), returnedItems.begin(), returnedItems.end() ) ;
00072 }
00073 }
00074 return configItems ;
00075 }
00076
00077
00078
00079
00080 std::string
00081 ConfigurationItem::traceConfigurationItems( ) const
00082 {
00083 static std::string tabString ;
00084 std::string result ;
00085 result += tabString ;
00086 result += getName() ;
00087 if ( getText() )
00088 {
00089 result += "[" ;
00090 result += getText() ;
00091 result += "]" ;
00092 }
00093
00094 std::pair< const char*, const char* > argument ;
00095 unsigned int nArguments = getArgumentsCount() ;
00096 for ( unsigned int i = 0 ; i < nArguments ; ++i )
00097 {
00098 argument = getArgument( i ) ;
00099 result += " " ;
00100 result += argument.first ;
00101 result += "=" ;
00102 result += argument.second ;
00103 }
00104
00105 result += "\n" ;
00106
00107 unsigned int nChildren = getChildrenCount() ;
00108 for ( unsigned int i = 0 ; i < nChildren ; ++i )
00109 {
00110 tabString += " " ;
00111 result += getChild( i )->traceConfigurationItems() ;
00112 tabString = tabString.substr( 0, tabString.size() - 3 ) ;
00113 }
00114 return result ;
00115 }
00116
00117