BESDefinitionStorageVolatile.cc

Go to the documentation of this file.
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,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 "BESDefinitionStorageVolatile.h"
00034 #include "BESDefine.h"
00035 #include "BESInfo.h"
00036 
00037 BESDefinitionStorageVolatile::~BESDefinitionStorageVolatile()
00038 {
00039 }
00040 
00047 BESDefine *
00048 BESDefinitionStorageVolatile::look_for( const string &def_name )
00049 {
00050     Define_citer i ;
00051     i = _def_list.find( def_name ) ;
00052     if( i != _def_list.end() )
00053     {
00054         return (*i).second;
00055     }
00056     return NULL ;
00057 }
00058 
00065 bool
00066 BESDefinitionStorageVolatile::add_definition( const string &def_name,
00067                                               BESDefine *d )
00068 {
00069     if( look_for( def_name ) == NULL )
00070     {
00071         _def_list[def_name] = d ;
00072         return true ;
00073     }
00074     return false ;
00075 }
00076 
00085 bool
00086 BESDefinitionStorageVolatile::del_definition( const string &def_name )
00087 {
00088     bool ret = false ;
00089     Define_iter i ;
00090     i = _def_list.find( def_name ) ;
00091     if( i != _def_list.end() )
00092     {
00093         BESDefine *d = (*i).second;
00094         _def_list.erase( i ) ;
00095         delete d ;
00096         ret = true ;
00097     }
00098     return ret ;
00099 }
00100 
00105 bool
00106 BESDefinitionStorageVolatile::del_definitions( )
00107 {
00108     while( _def_list.size() != 0 )
00109     {
00110         Define_iter di = _def_list.begin() ;
00111         BESDefine *d = (*di).second ;
00112         _def_list.erase( di ) ;
00113         if( d )
00114         {
00115             delete d ;
00116         }
00117     }
00118     return true ;
00119 }
00120 
00131 void
00132 BESDefinitionStorageVolatile::show_definitions( BESInfo &info )
00133 {
00134     info.add_tag( "name", get_name() ) ;
00135     Define_citer di = _def_list.begin() ;
00136     Define_citer de = _def_list.end() ;
00137     for( ; di != de; di++ )
00138     {
00139         info.begin_tag( "definition" ) ;
00140         string def_name = (*di).first ;
00141         BESDefine *def = (*di).second ;
00142 
00143         info.add_tag( "name", def_name ) ;
00144         info.begin_tag( "containers" ) ;
00145 
00146         BESDefine::containers_citer ci = def->first_container() ;
00147         BESDefine::containers_citer ce = def->end_container() ;
00148         for( ; ci != ce; ci++ )
00149         {
00150             string sym = (*ci).get_symbolic_name() ;
00151             info.add_tag( "symbolicName", sym ) ;
00152             string real = (*ci).get_real_name() ;
00153             info.add_tag( "realName", real ) ;
00154             string type = (*ci).get_container_type() ;
00155             info.add_tag( "dataType", type ) ;
00156             string con = (*ci).get_constraint() ;
00157             info.add_tag( "constraint", con ) ;
00158             string attrs = (*ci).get_attributes() ;
00159             info.add_tag( "attributes", attrs ) ;
00160         }
00161 
00162         info.end_tag( "containers" ) ;
00163         info.begin_tag( "aggregation" ) ;
00164         info.add_tag( "handler", def->get_agg_handler() ) ;
00165         info.add_tag( "command", def->get_agg_cmd() ) ;
00166         info.end_tag( "aggregation" ) ;
00167 
00168         info.end_tag( "definition" ) ;
00169     }
00170 }
00171 
00179 void
00180 BESDefinitionStorageVolatile::dump( ostream &strm ) const
00181 {
00182     strm << BESIndent::LMarg << "BESDefinitionStorageVolatile::dump - ("
00183                              << (void *)this << ")" << endl ;
00184     BESIndent::Indent() ;
00185     strm << BESIndent::LMarg << "name: " << get_name() << endl ;
00186     if( _def_list.size() )
00187     {
00188         strm << BESIndent::LMarg << "definitions:" << endl ;
00189         BESIndent::Indent() ;
00190         Define_citer di = _def_list.begin() ;
00191         Define_citer de = _def_list.end() ;
00192         for( ; di != de; di++ )
00193         {
00194             (*di).second->dump( strm ) ;
00195         }
00196         BESIndent::UnIndent() ;
00197     }
00198     else
00199     {
00200         strm << BESIndent::LMarg << "definitions: none" << endl ;
00201     }
00202     BESIndent::UnIndent() ;
00203 }
00204 

Generated on Wed Aug 29 02:59:01 2007 for OPeNDAP Back End Server (BES) by  doxygen 1.5.2