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

Generated on Sat Jan 19 04:05:36 2008 for OPeNDAP Back End Server (BES) by  doxygen 1.5.4