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 <iostream>
00034
00035 using std::endl ;
00036
00037 #include "BESContainerStorageList.h"
00038 #include "BESContainerStorage.h"
00039 #include "BESSyntaxUserError.h"
00040 #include "BESContainer.h"
00041 #include "TheBESKeys.h"
00042 #include "BESLog.h"
00043 #include "BESInfo.h"
00044
00045 BESContainerStorageList *BESContainerStorageList::_instance = 0 ;
00046
00047 BESContainerStorageList::BESContainerStorageList()
00048 : _first( 0 )
00049 {
00050 }
00051
00052 BESContainerStorageList::~BESContainerStorageList()
00053 {
00054 BESContainerStorageList::persistence_list *pl = _first ;
00055 while( pl )
00056 {
00057 if( pl->_persistence_obj )
00058 {
00059 delete pl->_persistence_obj ;
00060 }
00061 BESContainerStorageList::persistence_list *next = pl->_next ;
00062 delete pl ;
00063 pl = next ;
00064 }
00065 }
00066
00079 bool
00080 BESContainerStorageList::add_persistence( BESContainerStorage *cp )
00081 {
00082 bool ret = false ;
00083 if( !_first )
00084 {
00085 _first = new BESContainerStorageList::persistence_list ;
00086 _first->_persistence_obj = cp ;
00087 _first->_next = 0 ;
00088 ret = true ;
00089 }
00090 else
00091 {
00092 BESContainerStorageList::persistence_list *pl = _first ;
00093 bool done = false ;
00094 while( done == false )
00095 {
00096 if( pl->_persistence_obj->get_name() != cp->get_name() )
00097 {
00098 if( pl->_next )
00099 {
00100 pl = pl->_next ;
00101 }
00102 else
00103 {
00104 pl->_next = new BESContainerStorageList::persistence_list ;
00105 pl->_next->_persistence_obj = cp ;
00106 pl->_next->_next = 0 ;
00107 done = true ;
00108 ret = true ;
00109 }
00110 }
00111 else
00112 {
00113 done = true ;
00114 ret = false ;
00115 }
00116 }
00117 }
00118 return ret ;
00119 }
00120
00129 bool
00130 BESContainerStorageList::del_persistence( const string &persist_name )
00131 {
00132 bool ret = false ;
00133 BESContainerStorageList::persistence_list *pl = _first ;
00134 BESContainerStorageList::persistence_list *last = 0 ;
00135
00136 bool done = false ;
00137 while( done == false )
00138 {
00139 if( pl )
00140 {
00141 if( pl->_persistence_obj &&
00142 pl->_persistence_obj->get_name() == persist_name )
00143 {
00144 ret = true ;
00145 done = true ;
00146 if( pl == _first )
00147 {
00148 _first = _first->_next ;
00149 }
00150 else
00151 {
00152 last->_next = pl->_next ;
00153 }
00154 delete pl->_persistence_obj ;
00155 delete pl ;
00156 pl = 0 ;
00157 }
00158 else
00159 {
00160 last = pl ;
00161 pl = pl->_next ;
00162 }
00163 }
00164 else
00165 {
00166 done = true ;
00167 }
00168 }
00169
00170 return ret ;
00171 }
00172
00181 BESContainerStorage *
00182 BESContainerStorageList::find_persistence( const string &persist_name )
00183 {
00184 BESContainerStorage *ret = NULL ;
00185 BESContainerStorageList::persistence_list *pl = _first ;
00186 bool done = false ;
00187 while( done == false )
00188 {
00189 if( pl )
00190 {
00191 if( persist_name == pl->_persistence_obj->get_name() )
00192 {
00193 ret = pl->_persistence_obj ;
00194 done = true ;
00195 }
00196 else
00197 {
00198 pl = pl->_next ;
00199 }
00200 }
00201 else
00202 {
00203 done = true ;
00204 }
00205 }
00206 return ret ;
00207 }
00208
00209 bool
00210 BESContainerStorageList::isnice()
00211 {
00212 bool ret = false ;
00213 string key = "BES.Container.Persistence" ;
00214 bool found = false ;
00215 string isnice = TheBESKeys::TheKeys()->get_key( key, found ) ;
00216 if( isnice == "Nice" || isnice == "nice" || isnice == "NICE" )
00217 ret = true ;
00218 else
00219 ret = false ;
00220 return ret ;
00221 }
00222
00246 BESContainer *
00247 BESContainerStorageList::look_for( const string &sym_name )
00248 {
00249 BESContainer *ret_container = 0 ;
00250 BESContainerStorageList::persistence_list *pl = _first ;
00251 bool done = false ;
00252 while( done == false )
00253 {
00254 if( pl )
00255 {
00256 ret_container = pl->_persistence_obj->look_for( sym_name ) ;
00257 if( ret_container )
00258 {
00259 done = true ;
00260 }
00261 else
00262 {
00263 pl = pl->_next ;
00264 }
00265 }
00266 else
00267 {
00268 done = true ;
00269 }
00270 }
00271 if( !ret_container )
00272 {
00273 if( isnice() )
00274 {
00275 (*BESLog::TheLog()) << "Could not find the symbolic name "
00276 << sym_name << endl ;
00277 }
00278 else
00279 {
00280 string s = (string)"Could not find the symbolic name "
00281 + sym_name ;
00282 throw BESSyntaxUserError( s, __FILE__, __LINE__ ) ;
00283 }
00284 }
00285
00286 return ret_container ;
00287 }
00288
00301 void
00302 BESContainerStorageList::show_containers( BESInfo &info )
00303 {
00304 BESContainerStorageList::persistence_list *pl = _first ;
00305 while( pl )
00306 {
00307 info.begin_tag( "store" ) ;
00308 pl->_persistence_obj->show_containers( info ) ;
00309 info.end_tag( "store" ) ;
00310 pl = pl->_next ;
00311 }
00312 }
00313
00321 void
00322 BESContainerStorageList::dump( ostream &strm ) const
00323 {
00324 strm << BESIndent::LMarg << "BESContainerStorageList::dump - ("
00325 << (void *)this << ")" << endl ;
00326 BESIndent::Indent() ;
00327 BESContainerStorageList::persistence_list *pl = _first ;
00328 if( pl )
00329 {
00330 strm << BESIndent::LMarg << "container storage:" << endl ;
00331 BESIndent::Indent() ;
00332 while( pl )
00333 {
00334 pl->_persistence_obj->dump( strm ) ;
00335 pl = pl->_next ;
00336 }
00337 BESIndent::UnIndent() ;
00338 }
00339 else
00340 {
00341 strm << BESIndent::LMarg << "container storage: empty" << endl ;
00342 }
00343 BESIndent::UnIndent() ;
00344 }
00345
00346 BESContainerStorageList *
00347 BESContainerStorageList::TheList()
00348 {
00349 if( _instance == 0 )
00350 {
00351 _instance = new BESContainerStorageList ;
00352 }
00353 return _instance ;
00354 }
00355