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

Generated on Tue Mar 4 23:13:34 2008 for OPeNDAP Back End Server (BES) by  doxygen 1.5.1