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 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     info.add_tag( "name", get_name() ) ;
00137     Define_citer di = _def_list.begin() ;
00138     Define_citer de = _def_list.end() ;
00139     for( ; di != de; di++ )
00140     {
00141         info.begin_tag( "definition" ) ;
00142         string def_name = (*di).first ;
00143         BESDefine *def = (*di).second ;
00144 
00145         info.add_tag( "name", def_name ) ;
00146         info.begin_tag( "containers" ) ;
00147 
00148         BESDefine::containers_citer ci = def->first_container() ;
00149         BESDefine::containers_citer ce = def->end_container() ;
00150         for( ; ci != ce; ci++ )
00151         {
00152             string sym = (*ci)->get_symbolic_name() ;
00153             info.add_tag( "symbolicName", sym ) ;
00154             string real = (*ci)->get_real_name() ;
00155             info.add_tag( "realName", real ) ;
00156             string type = (*ci)->get_container_type() ;
00157             info.add_tag( "dataType", type ) ;
00158             string con = (*ci)->get_constraint() ;
00159             info.add_tag( "constraint", con ) ;
00160             string attrs = (*ci)->get_attributes() ;
00161             info.add_tag( "attributes", attrs ) ;
00162         }
00163 
00164         info.end_tag( "containers" ) ;
00165         info.begin_tag( "aggregation" ) ;
00166         info.add_tag( "handler", def->get_agg_handler() ) ;
00167         info.add_tag( "command", def->get_agg_cmd() ) ;
00168         info.end_tag( "aggregation" ) ;
00169 
00170         info.end_tag( "definition" ) ;
00171     }
00172 }
00173 
00181 void
00182 BESDefinitionStorageVolatile::dump( ostream &strm ) const
00183 {
00184     strm << BESIndent::LMarg << "BESDefinitionStorageVolatile::dump - ("
00185                              << (void *)this << ")" << endl ;
00186     BESIndent::Indent() ;
00187     strm << BESIndent::LMarg << "name: " << get_name() << endl ;
00188     if( _def_list.size() )
00189     {
00190         strm << BESIndent::LMarg << "definitions:" << endl ;
00191         BESIndent::Indent() ;
00192         Define_citer di = _def_list.begin() ;
00193         Define_citer de = _def_list.end() ;
00194         for( ; di != de; di++ )
00195         {
00196             (*di).second->dump( strm ) ;
00197         }
00198         BESIndent::UnIndent() ;
00199     }
00200     else
00201     {
00202         strm << BESIndent::LMarg << "definitions: none" << endl ;
00203     }
00204     BESIndent::UnIndent() ;
00205 }
00206 

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