BESDefinitionStorageList.cc

Go to the documentation of this file.
00001 // BESDefinitionStorageList.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 Atmostpheric 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 "BESDefinitionStorageList.h"
00038 #include "BESDefinitionStorage.h"
00039 #include "BESDefinitionStorageException.h"
00040 #include "BESDefine.h"
00041 #include "BESInfo.h"
00042 
00043 BESDefinitionStorageList *BESDefinitionStorageList::_instance = 0 ;
00044 
00045 BESDefinitionStorageList::BESDefinitionStorageList()
00046     : _first( 0 )
00047 {
00048 }
00049 
00050 BESDefinitionStorageList::~BESDefinitionStorageList()
00051 {
00052     BESDefinitionStorageList::persistence_list *pl = _first ;
00053     while( pl )
00054     {
00055         if( pl->_persistence_obj )
00056         {
00057             delete pl->_persistence_obj ;
00058         }
00059         BESDefinitionStorageList::persistence_list *next = pl->_next ;
00060         delete pl ;
00061         pl = next ;
00062     }
00063 }
00064 
00077 bool
00078 BESDefinitionStorageList::add_persistence( BESDefinitionStorage *cp )
00079 {
00080     bool ret = false ;
00081     if( !_first )
00082     {
00083         _first = new BESDefinitionStorageList::persistence_list ;
00084         _first->_persistence_obj = cp ;
00085         _first->_next = 0 ;
00086         ret = true ;
00087     }
00088     else
00089     {
00090         BESDefinitionStorageList::persistence_list *pl = _first ;
00091         bool done = false ;
00092         while( done == false )
00093         {
00094             if( pl->_persistence_obj->get_name() != cp->get_name() )
00095             {
00096                 if( pl->_next )
00097                 {
00098                     pl = pl->_next ;
00099                 }
00100                 else
00101                 {
00102                     pl->_next = new BESDefinitionStorageList::persistence_list ;
00103                     pl->_next->_persistence_obj = cp ;
00104                     pl->_next->_next = 0 ;
00105                     done = true ;
00106                     ret = true ;
00107                 }
00108             }
00109             else
00110             {
00111                 done = true ;
00112                 ret = false ;
00113             }
00114         }
00115     }
00116     return ret ;
00117 }
00118 
00127 bool
00128 BESDefinitionStorageList::del_persistence( const string &persist_name )
00129 {
00130     bool ret = false ;
00131     BESDefinitionStorageList::persistence_list *pl = _first ;
00132     BESDefinitionStorageList::persistence_list *last = 0 ;
00133 
00134     bool done = false ;
00135     while( done == false )
00136     {
00137         if( pl )
00138         {
00139             if( pl->_persistence_obj->get_name() == persist_name )
00140             {
00141                 ret = true ;
00142                 done = true ;
00143                 if( pl == _first )
00144                 {
00145                     _first = _first->_next ;
00146                 }
00147                 else
00148                 {
00149                     last->_next = pl->_next ;
00150                 }
00151                 delete pl->_persistence_obj ;
00152                 delete pl ;
00153             }
00154             else
00155             {
00156                 last = pl ;
00157                 pl = pl->_next ;
00158             }
00159         }
00160         else
00161         {
00162             done = true ;
00163         }
00164     }
00165 
00166     return ret ;
00167 }
00168 
00177 BESDefinitionStorage *
00178 BESDefinitionStorageList::find_persistence( const string &persist_name )
00179 {
00180     BESDefinitionStorage *ret = NULL ;
00181     BESDefinitionStorageList::persistence_list *pl = _first ;
00182     bool done = false ;
00183     while( done == false )
00184     {
00185         if( pl )
00186         {
00187             if( persist_name == pl->_persistence_obj->get_name() )
00188             {
00189                 ret = pl->_persistence_obj ;
00190                 done = true ;
00191             }
00192             else
00193             {
00194                 pl = pl->_next ;
00195             }
00196         }
00197         else
00198         {
00199             done = true ;
00200         }
00201     }
00202     return ret ;
00203 }
00204 
00215 BESDefine *
00216 BESDefinitionStorageList::look_for( const string &def_name )
00217 {
00218     BESDefine *ret_def = NULL ;
00219     BESDefinitionStorageList::persistence_list *pl = _first ;
00220     bool done = false ;
00221     while( done == false )
00222     {
00223         if( pl )
00224         {
00225             ret_def = pl->_persistence_obj->look_for( def_name ) ;
00226             if( ret_def )
00227             {
00228                 done = true ;
00229             }
00230             else
00231             {
00232                 pl = pl->_next ;
00233             }
00234         }
00235         else
00236         {
00237             done = true ;
00238         }
00239     }
00240     return ret_def ;
00241 }
00242 
00257 void
00258 BESDefinitionStorageList::show_definitions( BESInfo &info )
00259 {
00260     BESDefinitionStorageList::persistence_list *pl = _first ;
00261     bool first = true ;
00262     while( pl )
00263     {
00264         if( !first )
00265         {
00266             // separate each store with a blank line
00267             info.add_break( 1 ) ;
00268         }
00269         first = false ;
00270         info.begin_tag( "store" ) ;
00271         pl->_persistence_obj->show_definitions( info ) ;
00272         info.end_tag( "store" ) ;
00273         pl = pl->_next ;
00274     }
00275 }
00276 
00277 BESDefinitionStorageList *
00278 BESDefinitionStorageList::TheList()
00279 {
00280     if( _instance == 0 )
00281     {
00282         _instance = new BESDefinitionStorageList ;
00283     }
00284     return _instance ;
00285 }
00286 
00294 void
00295 BESDefinitionStorageList::dump( ostream &strm ) const
00296 {
00297     strm << BESIndent::LMarg << "BESDefinitionStorageList::dump - ("
00298                              << (void *)this << ")" << endl;
00299     BESIndent::Indent() ;
00300     if( _first )
00301     {
00302         strm << BESIndent::LMarg << "registered definition storage:" << endl ;
00303         BESIndent::Indent() ;
00304         BESDefinitionStorageList::persistence_list *pl = _first ;
00305         while( pl )
00306         {
00307             pl->_persistence_obj->dump( strm ) ;
00308             pl = pl->_next ;
00309         }
00310         BESIndent::UnIndent() ;
00311     }
00312     else
00313     {
00314         strm << BESIndent::LMarg << "registered definition storage: none" << endl ;
00315     }
00316     BESIndent::UnIndent() ;
00317 }
00318 

Generated on Wed Aug 29 03:14:16 2007 for OPeNDAP Back End Server (BES) by  doxygen 1.5.2