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 "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 &&
00140                 pl->_persistence_obj->get_name() == persist_name )
00141             {
00142                 ret = true ;
00143                 done = true ;
00144                 if( pl == _first )
00145                 {
00146                     _first = _first->_next ;
00147                 }
00148                 else
00149                 {
00150                     last->_next = pl->_next ;
00151                 }
00152                 delete pl->_persistence_obj ;
00153                 delete pl ;
00154                 pl = 0 ;
00155             }
00156             else
00157             {
00158                 last = pl ;
00159                 pl = pl->_next ;
00160             }
00161         }
00162         else
00163         {
00164             done = true ;
00165         }
00166     }
00167 
00168     return ret ;
00169 }
00170 
00179 BESDefinitionStorage *
00180 BESDefinitionStorageList::find_persistence( const string &persist_name )
00181 {
00182     BESDefinitionStorage *ret = NULL ;
00183     BESDefinitionStorageList::persistence_list *pl = _first ;
00184     bool done = false ;
00185     while( done == false )
00186     {
00187         if( pl )
00188         {
00189             if( persist_name == pl->_persistence_obj->get_name() )
00190             {
00191                 ret = pl->_persistence_obj ;
00192                 done = true ;
00193             }
00194             else
00195             {
00196                 pl = pl->_next ;
00197             }
00198         }
00199         else
00200         {
00201             done = true ;
00202         }
00203     }
00204     return ret ;
00205 }
00206 
00217 BESDefine *
00218 BESDefinitionStorageList::look_for( const string &def_name )
00219 {
00220     BESDefine *ret_def = NULL ;
00221     BESDefinitionStorageList::persistence_list *pl = _first ;
00222     bool done = false ;
00223     while( done == false )
00224     {
00225         if( pl )
00226         {
00227             ret_def = pl->_persistence_obj->look_for( def_name ) ;
00228             if( ret_def )
00229             {
00230                 done = true ;
00231             }
00232             else
00233             {
00234                 pl = pl->_next ;
00235             }
00236         }
00237         else
00238         {
00239             done = true ;
00240         }
00241     }
00242     return ret_def ;
00243 }
00244 
00259 void
00260 BESDefinitionStorageList::show_definitions( BESInfo &info )
00261 {
00262     BESDefinitionStorageList::persistence_list *pl = _first ;
00263     bool first = true ;
00264     while( pl )
00265     {
00266         if( !first )
00267         {
00268             // separate each store with a blank line
00269             info.add_break( 1 ) ;
00270         }
00271         first = false ;
00272         info.begin_tag( "store" ) ;
00273         pl->_persistence_obj->show_definitions( info ) ;
00274         info.end_tag( "store" ) ;
00275         pl = pl->_next ;
00276     }
00277 }
00278 
00279 BESDefinitionStorageList *
00280 BESDefinitionStorageList::TheList()
00281 {
00282     if( _instance == 0 )
00283     {
00284         _instance = new BESDefinitionStorageList ;
00285     }
00286     return _instance ;
00287 }
00288 
00296 void
00297 BESDefinitionStorageList::dump( ostream &strm ) const
00298 {
00299     strm << BESIndent::LMarg << "BESDefinitionStorageList::dump - ("
00300                              << (void *)this << ")" << endl;
00301     BESIndent::Indent() ;
00302     if( _first )
00303     {
00304         strm << BESIndent::LMarg << "registered definition storage:" << endl ;
00305         BESIndent::Indent() ;
00306         BESDefinitionStorageList::persistence_list *pl = _first ;
00307         while( pl )
00308         {
00309             pl->_persistence_obj->dump( strm ) ;
00310             pl = pl->_next ;
00311         }
00312         BESIndent::UnIndent() ;
00313     }
00314     else
00315     {
00316         strm << BESIndent::LMarg << "registered definition storage: none" << endl ;
00317     }
00318     BESIndent::UnIndent() ;
00319 }
00320 

Generated on Wed Jan 2 06:01:18 2008 for OPeNDAP Back End Server (BES) by  doxygen 1.5.4