OPeNDAP Hyrax Back End Server (BES)
Updated for version 3.8.3
|
00001 // BESDefinitionStorageVolatile.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 "BESDefinitionStorageVolatile.h" 00034 #include "BESDefine.h" 00035 #include "BESInfo.h" 00036 00037 BESDefinitionStorageVolatile::~BESDefinitionStorageVolatile() 00038 { 00039 del_definitions() ; 00040 } 00041 00048 BESDefine * 00049 BESDefinitionStorageVolatile::look_for( const string &def_name ) 00050 { 00051 Define_citer i ; 00052 i = _def_list.find( def_name ) ; 00053 if( i != _def_list.end() ) 00054 { 00055 return (*i).second; 00056 } 00057 return NULL ; 00058 } 00059 00067 bool 00068 BESDefinitionStorageVolatile::add_definition( const string &def_name, 00069 BESDefine *d ) 00070 { 00071 if( look_for( def_name ) == NULL ) 00072 { 00073 _def_list[def_name] = d ; 00074 return true ; 00075 } 00076 return false ; 00077 } 00078 00087 bool 00088 BESDefinitionStorageVolatile::del_definition( const string &def_name ) 00089 { 00090 bool ret = false ; 00091 Define_iter i ; 00092 i = _def_list.find( def_name ) ; 00093 if( i != _def_list.end() ) 00094 { 00095 BESDefine *d = (*i).second; 00096 _def_list.erase( i ) ; 00097 delete d ; 00098 ret = true ; 00099 } 00100 return ret ; 00101 } 00102 00107 bool 00108 BESDefinitionStorageVolatile::del_definitions( ) 00109 { 00110 while( _def_list.size() != 0 ) 00111 { 00112 Define_iter di = _def_list.begin() ; 00113 BESDefine *d = (*di).second ; 00114 _def_list.erase( di ) ; 00115 if( d ) 00116 { 00117 delete d ; 00118 } 00119 } 00120 return true ; 00121 } 00122 00133 void 00134 BESDefinitionStorageVolatile::show_definitions( BESInfo &info ) 00135 { 00136 map<string,string> dprops ; // for the definition 00137 map<string,string> cprops ; // for the container 00138 map<string,string> aprops ; // for aggregation 00139 Define_citer di = _def_list.begin() ; 00140 Define_citer de = _def_list.end() ; 00141 for( ; di != de; di++ ) 00142 { 00143 string def_name = (*di).first ; 00144 BESDefine *def = (*di).second ; 00145 00146 dprops.clear() ; 00147 dprops["name"] = def_name ; 00148 info.begin_tag( "definition", &dprops ) ; 00149 00150 BESDefine::containers_citer ci = def->first_container() ; 00151 BESDefine::containers_citer ce = def->end_container() ; 00152 for( ; ci != ce; ci++ ) 00153 { 00154 cprops.clear() ; 00155 string sym = (*ci)->get_symbolic_name() ; 00156 cprops["name"] = sym ; 00157 // FIXME: need to get rid of the root directory 00158 string real = (*ci)->get_real_name() ; 00159 string type = (*ci)->get_container_type() ; 00160 cprops["type"] = type ; 00161 string con = (*ci)->get_constraint() ; 00162 if( !con.empty() ) 00163 { 00164 cprops["constraint"] = con ; 00165 } 00166 string attrs = (*ci)->get_attributes() ; 00167 if( !attrs.empty() ) 00168 { 00169 cprops["attributes"] = attrs ; 00170 } 00171 info.add_tag( "container", real, &cprops ) ; 00172 } 00173 00174 if( !def->get_agg_handler().empty() ) 00175 { 00176 aprops.clear() ; 00177 aprops["handler"] = def->get_agg_handler() ; 00178 info.add_tag( "aggregation", def->get_agg_cmd(), &aprops ) ; 00179 } 00180 00181 info.end_tag( "definition" ) ; 00182 } 00183 } 00184 00192 void 00193 BESDefinitionStorageVolatile::dump( ostream &strm ) const 00194 { 00195 strm << BESIndent::LMarg << "BESDefinitionStorageVolatile::dump - (" 00196 << (void *)this << ")" << endl ; 00197 BESIndent::Indent() ; 00198 strm << BESIndent::LMarg << "name: " << get_name() << endl ; 00199 if( _def_list.size() ) 00200 { 00201 strm << BESIndent::LMarg << "definitions:" << endl ; 00202 BESIndent::Indent() ; 00203 Define_citer di = _def_list.begin() ; 00204 Define_citer de = _def_list.end() ; 00205 for( ; di != de; di++ ) 00206 { 00207 (*di).second->dump( strm ) ; 00208 } 00209 BESIndent::UnIndent() ; 00210 } 00211 else 00212 { 00213 strm << BESIndent::LMarg << "definitions: none" << endl ; 00214 } 00215 BESIndent::UnIndent() ; 00216 } 00217