BESContainerStorageList.cc

Go to the documentation of this file.
00001 // BESContainerStorageList.cc
00002 
00003 // This file is part of bes, A C++ back-end server implementation framework
00004 // for the OPeNDAP Data Access Protocol.
00005 
00006 // Copyright (c) 2004,2005 University Corporation for Atmospheric Research
00007 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
00008 //
00009 // This library is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU Lesser General Public
00011 // License as published by the Free Software Foundation; either
00012 // version 2.1 of the License, or (at your option) any later version.
00013 // 
00014 // This library is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 // Lesser General Public License for more details.
00018 // 
00019 // You should have received a copy of the GNU Lesser General Public
00020 // License along with this library; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 // You can contact University Corporation for Atmospheric Research at
00024 // 3080 Center Green Drive, Boulder, CO 80301
00025  
00026 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
00027 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
00028 //
00029 // Authors:
00030 //      pwest       Patrick West <pwest@ucar.edu>
00031 //      jgarcia     Jose Garcia <jgarcia@ucar.edu>
00032 
00033 #include <iostream>
00034 
00035 using std::endl ;
00036 
00037 #include "BESContainerStorageList.h"
00038 #include "BESContainerStorage.h"
00039 #include "BESContainerStorageException.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 
00245 BESContainer *
00246 BESContainerStorageList::look_for( const string &sym_name )
00247 {
00248     BESContainer *ret_container = 0 ;
00249     BESContainerStorageList::persistence_list *pl = _first ;
00250     bool done = false ;
00251     while( done == false )
00252     {
00253         if( pl )
00254         {
00255             ret_container = pl->_persistence_obj->look_for( sym_name ) ;
00256             if( ret_container )
00257             {
00258                 done = true ;
00259             }
00260             else
00261             {
00262                 pl = pl->_next ;
00263             }
00264         }
00265         else
00266         {
00267             done = true ;
00268         }
00269     }
00270     if( !ret_container )
00271     {
00272         if( isnice() )
00273         {
00274             (*BESLog::TheLog()) << "Could not find the symbolic name "
00275                                 << sym_name << endl ;
00276         }
00277         else
00278         {
00279             string s = (string)"Could not find the symbolic name "
00280                        + sym_name ;
00281             throw BESContainerStorageException( s, __FILE__, __LINE__ ) ;
00282         }
00283     }
00284 
00285     return ret_container ;
00286 }
00287 
00300 void
00301 BESContainerStorageList::show_containers( BESInfo &info )
00302 {
00303     BESContainerStorageList::persistence_list *pl = _first ;
00304     while( pl )
00305     {
00306         info.begin_tag( "store" ) ;
00307         pl->_persistence_obj->show_containers( info ) ;
00308         info.end_tag( "store" ) ;
00309         pl = pl->_next ;
00310     }
00311 }
00312 
00320 void
00321 BESContainerStorageList::dump( ostream &strm ) const
00322 {
00323     strm << BESIndent::LMarg << "BESContainerStorageList::dump - ("
00324                              << (void *)this << ")" << endl ;
00325     BESIndent::Indent() ;
00326     BESContainerStorageList::persistence_list *pl = _first ;
00327     if( pl )
00328     {
00329         strm << BESIndent::LMarg << "container storage:" << endl ;
00330         BESIndent::Indent() ;
00331         while( pl )
00332         {
00333             pl->_persistence_obj->dump( strm ) ;
00334             pl = pl->_next ;
00335         }
00336         BESIndent::UnIndent() ;
00337     }
00338     else
00339     {
00340         strm << BESIndent::LMarg << "container storage: empty" << endl ;
00341     }
00342     BESIndent::UnIndent() ;
00343 }
00344 
00345 BESContainerStorageList *
00346 BESContainerStorageList::TheList()
00347 {
00348     if( _instance == 0 )
00349     {
00350         _instance = new BESContainerStorageList ;
00351     }
00352     return _instance ;
00353 }
00354 

Generated on Sat Jan 19 04:05:36 2008 for OPeNDAP Back End Server (BES) by  doxygen 1.5.4