BESDefinitionStorageVolatile.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "BESDefinitionStorageVolatile.h"
00034 #include "BESDefine.h"
00035 #include "BESInfo.h"
00036
00037 BESDefinitionStorageVolatile::~BESDefinitionStorageVolatile()
00038 {
00039 del_definitions() ;
00040 }
00041
00048 BESDefine *
00049 BESDefinitionStorageVolatile::look_for( const string &def_name )
00050 {
00051 Define_citer i ;
00052 i = _def_list.find( def_name ) ;
00053 if( i != _def_list.end() )
00054 {
00055 return (*i).second;
00056 }
00057 return NULL ;
00058 }
00059
00067 bool
00068 BESDefinitionStorageVolatile::add_definition( const string &def_name,
00069 BESDefine *d )
00070 {
00071 if( look_for( def_name ) == NULL )
00072 {
00073 _def_list[def_name] = d ;
00074 return true ;
00075 }
00076 return false ;
00077 }
00078
00087 bool
00088 BESDefinitionStorageVolatile::del_definition( const string &def_name )
00089 {
00090 bool ret = false ;
00091 Define_iter i ;
00092 i = _def_list.find( def_name ) ;
00093 if( i != _def_list.end() )
00094 {
00095 BESDefine *d = (*i).second;
00096 _def_list.erase( i ) ;
00097 delete d ;
00098 ret = true ;
00099 }
00100 return ret ;
00101 }
00102
00107 bool
00108 BESDefinitionStorageVolatile::del_definitions( )
00109 {
00110 while( _def_list.size() != 0 )
00111 {
00112 Define_iter di = _def_list.begin() ;
00113 BESDefine *d = (*di).second ;
00114 _def_list.erase( di ) ;
00115 if( d )
00116 {
00117 delete d ;
00118 }
00119 }
00120 return true ;
00121 }
00122
00133 void
00134 BESDefinitionStorageVolatile::show_definitions( BESInfo &info )
00135 {
00136 map<string,string> dprops ;
00137 map<string,string> cprops ;
00138 map<string,string> aprops ;
00139 Define_citer di = _def_list.begin() ;
00140 Define_citer de = _def_list.end() ;
00141 for( ; di != de; di++ )
00142 {
00143 string def_name = (*di).first ;
00144 BESDefine *def = (*di).second ;
00145
00146 dprops.clear() ;
00147 dprops["name"] = def_name ;
00148 info.begin_tag( "definition", &dprops ) ;
00149
00150 BESDefine::containers_citer ci = def->first_container() ;
00151 BESDefine::containers_citer ce = def->end_container() ;
00152 for( ; ci != ce; ci++ )
00153 {
00154 cprops.clear() ;
00155 string sym = (*ci)->get_symbolic_name() ;
00156 cprops["name"] = sym ;
00157
00158 string real = (*ci)->get_real_name() ;
00159 string type = (*ci)->get_container_type() ;
00160 cprops["type"] = type ;
00161 string con = (*ci)->get_constraint() ;
00162 if( !con.empty() )
00163 {
00164 cprops["constraint"] = con ;
00165 }
00166 string attrs = (*ci)->get_attributes() ;
00167 if( !attrs.empty() )
00168 {
00169 cprops["attributes"] = attrs ;
00170 }
00171 info.add_tag( "container", real, &cprops ) ;
00172 }
00173
00174 if( !def->get_agg_handler().empty() )
00175 {
00176 aprops.clear() ;
00177 aprops["handler"] = def->get_agg_handler() ;
00178 info.add_tag( "aggregation", def->get_agg_cmd(), &aprops ) ;
00179 }
00180
00181 info.end_tag( "definition" ) ;
00182 }
00183 }
00184
00192 void
00193 BESDefinitionStorageVolatile::dump( ostream &strm ) const
00194 {
00195 strm << BESIndent::LMarg << "BESDefinitionStorageVolatile::dump - ("
00196 << (void *)this << ")" << endl ;
00197 BESIndent::Indent() ;
00198 strm << BESIndent::LMarg << "name: " << get_name() << endl ;
00199 if( _def_list.size() )
00200 {
00201 strm << BESIndent::LMarg << "definitions:" << endl ;
00202 BESIndent::Indent() ;
00203 Define_citer di = _def_list.begin() ;
00204 Define_citer de = _def_list.end() ;
00205 for( ; di != de; di++ )
00206 {
00207 (*di).second->dump( strm ) ;
00208 }
00209 BESIndent::UnIndent() ;
00210 }
00211 else
00212 {
00213 strm << BESIndent::LMarg << "definitions: none" << endl ;
00214 }
00215 BESIndent::UnIndent() ;
00216 }
00217