OPeNDAP Hyrax Back End Server (BES)
Updated for version 3.8.3
|
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-2009 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->_reference = 1 ; 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->_reference = 1 ; 00105 pl->_next->_next = 0 ; 00106 done = true ; 00107 ret = true ; 00108 } 00109 } 00110 else 00111 { 00112 done = true ; 00113 ret = false ; 00114 } 00115 } 00116 } 00117 return ret ; 00118 } 00119 00128 bool 00129 BESDefinitionStorageList::ref_persistence( const string &persist_name ) 00130 { 00131 bool ret = false ; 00132 BESDefinitionStorageList::persistence_list *pl = _first ; 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 pl->_reference++ ; 00145 } 00146 else 00147 { 00148 pl = pl->_next ; 00149 } 00150 } 00151 else 00152 { 00153 done = true ; 00154 } 00155 } 00156 00157 return ret ; 00158 } 00159 00170 bool 00171 BESDefinitionStorageList::deref_persistence( const string &persist_name ) 00172 { 00173 bool ret = false ; 00174 BESDefinitionStorageList::persistence_list *pl = _first ; 00175 BESDefinitionStorageList::persistence_list *last = 0 ; 00176 00177 bool done = false ; 00178 while( done == false ) 00179 { 00180 if( pl ) 00181 { 00182 if( pl->_persistence_obj && 00183 pl->_persistence_obj->get_name() == persist_name ) 00184 { 00185 ret = true ; 00186 done = true ; 00187 pl->_reference-- ; 00188 if( !pl->_reference ) 00189 { 00190 if( pl == _first ) 00191 { 00192 _first = _first->_next ; 00193 } 00194 else 00195 { 00196 if (!last) 00197 throw BESInternalError("ContainerStorageList last is null", __FILE__, __LINE__); 00198 last->_next = pl->_next ; 00199 } 00200 delete pl->_persistence_obj ; 00201 delete pl ; 00202 pl = 0 ; 00203 } 00204 } 00205 else 00206 { 00207 last = pl ; 00208 pl = pl->_next ; 00209 } 00210 } 00211 else 00212 { 00213 done = true ; 00214 } 00215 } 00216 00217 return ret ; 00218 } 00219 00228 BESDefinitionStorage * 00229 BESDefinitionStorageList::find_persistence( const string &persist_name ) 00230 { 00231 BESDefinitionStorage *ret = NULL ; 00232 BESDefinitionStorageList::persistence_list *pl = _first ; 00233 bool done = false ; 00234 while( done == false ) 00235 { 00236 if( pl ) 00237 { 00238 if( persist_name == pl->_persistence_obj->get_name() ) 00239 { 00240 ret = pl->_persistence_obj ; 00241 done = true ; 00242 } 00243 else 00244 { 00245 pl = pl->_next ; 00246 } 00247 } 00248 else 00249 { 00250 done = true ; 00251 } 00252 } 00253 return ret ; 00254 } 00255 00266 BESDefine * 00267 BESDefinitionStorageList::look_for( const string &def_name ) 00268 { 00269 BESDefine *ret_def = NULL ; 00270 BESDefinitionStorageList::persistence_list *pl = _first ; 00271 bool done = false ; 00272 while( done == false ) 00273 { 00274 if( pl ) 00275 { 00276 ret_def = pl->_persistence_obj->look_for( def_name ) ; 00277 if( ret_def ) 00278 { 00279 done = true ; 00280 } 00281 else 00282 { 00283 pl = pl->_next ; 00284 } 00285 } 00286 else 00287 { 00288 done = true ; 00289 } 00290 } 00291 return ret_def ; 00292 } 00293 00308 void 00309 BESDefinitionStorageList::show_definitions( BESInfo &info ) 00310 { 00311 BESDefinitionStorageList::persistence_list *pl = _first ; 00312 bool first = true ; 00313 while( pl ) 00314 { 00315 if( !first ) 00316 { 00317 // separate each store with a blank line 00318 info.add_break( 1 ) ; 00319 } 00320 first = false ; 00321 map<string,string> props ; 00322 props["name"] = pl->_persistence_obj->get_name() ; 00323 info.begin_tag( "store", &props ) ; 00324 pl->_persistence_obj->show_definitions( info ) ; 00325 info.end_tag( "store" ) ; 00326 pl = pl->_next ; 00327 } 00328 } 00329 00330 BESDefinitionStorageList * 00331 BESDefinitionStorageList::TheList() 00332 { 00333 if( _instance == 0 ) 00334 { 00335 _instance = new BESDefinitionStorageList ; 00336 } 00337 return _instance ; 00338 } 00339 00347 void 00348 BESDefinitionStorageList::dump( ostream &strm ) const 00349 { 00350 strm << BESIndent::LMarg << "BESDefinitionStorageList::dump - (" 00351 << (void *)this << ")" << endl; 00352 BESIndent::Indent() ; 00353 if( _first ) 00354 { 00355 strm << BESIndent::LMarg << "registered definition storage:" << endl ; 00356 BESIndent::Indent() ; 00357 BESDefinitionStorageList::persistence_list *pl = _first ; 00358 while( pl ) 00359 { 00360 pl->_persistence_obj->dump( strm ) ; 00361 pl = pl->_next ; 00362 } 00363 BESIndent::UnIndent() ; 00364 } 00365 else 00366 { 00367 strm << BESIndent::LMarg << "registered definition storage: none" << endl ; 00368 } 00369 BESIndent::UnIndent() ; 00370 } 00371