BESContainerStorageVolatile.cc

Go to the documentation of this file.
00001 // BESContainerStorageVolatile.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 "BESContainerStorageVolatile.h"
00034 #include "BESFileContainer.h"
00035 #include "BESContainerStorageException.h"
00036 #include "BESInfo.h"
00037 #include "TheBESKeys.h"
00038 
00046 BESContainerStorageVolatile::BESContainerStorageVolatile( const string &n )
00047     : BESContainerStorage( n )
00048 {
00049     string base_key = "BES.Data.RootDirectory" ;
00050     bool found = false ;
00051     _root_dir = TheBESKeys::TheKeys()->get_key( base_key, found ) ;
00052     if( _root_dir == "" )
00053     {
00054         string s = base_key + " not defined in bes configuration file" ;
00055         throw BESContainerStorageException( s, __FILE__, __LINE__ ) ;
00056     }
00057 }
00058 
00059 BESContainerStorageVolatile::~BESContainerStorageVolatile()
00060 { 
00061     del_containers() ;
00062 }
00063 
00073 BESContainer *
00074 BESContainerStorageVolatile::look_for( const string &sym_name )
00075 {
00076     BESContainer *ret_container = 0 ;
00077 
00078     BESContainerStorageVolatile::Container_citer i ;
00079     i = _container_list.find( sym_name ) ;
00080     if( i != _container_list.end() )
00081     {
00082         BESContainer *c = (*i).second ;
00083         ret_container = c->ptr_duplicate() ;
00084     }
00085 
00086     return ret_container ;
00087 }
00088 
00104 void
00105 BESContainerStorageVolatile::add_container( const string &sym_name,
00106                                             const string &real_name,
00107                                             const string &type )
00108 {
00109     if( type == "" )
00110     {
00111         string s = "Unable to add container, type of data must be specified"  ;
00112         throw BESContainerStorageException( s, __FILE__, __LINE__ ) ;
00113     }
00114 
00115     BESContainerStorageVolatile::Container_citer i ;
00116     i = _container_list.find( sym_name ) ;
00117     if( i != _container_list.end() )
00118     {
00119         string s = (string)"A container with the name "
00120                    + sym_name
00121                    + " already exists" ;
00122         throw BESContainerStorageException( s, __FILE__, __LINE__ ) ;
00123     }
00124     string new_r_name = _root_dir + "/" + real_name ;
00125     BESContainer *c = new BESFileContainer( sym_name, new_r_name, type ) ;
00126     _container_list[sym_name] = c ;
00127 }
00128 
00146 void
00147 BESContainerStorageVolatile::add_container( BESContainer *c )
00148 {
00149     if( !c )
00150     {
00151         string s = "Unable to add container, container passed is null"  ;
00152         throw BESContainerStorageException( s, __FILE__, __LINE__ ) ;
00153     }
00154     if( c->get_container_type() == "" )
00155     {
00156         string s = "Unable to add container, type of data must be specified"  ;
00157         throw BESContainerStorageException( s, __FILE__, __LINE__ ) ;
00158     }
00159     string sym_name = c->get_symbolic_name() ;
00160     BESContainerStorageVolatile::Container_citer i ;
00161     i = _container_list.find( sym_name ) ;
00162     if( i != _container_list.end() )
00163     {
00164         string s = (string)"A container with the name "
00165                    + sym_name
00166                    + " already exists" ;
00167         throw BESContainerStorageException( s, __FILE__, __LINE__ ) ;
00168     }
00169     _container_list[sym_name] = c ;
00170 }
00171 
00178 bool
00179 BESContainerStorageVolatile::del_container( const string &s_name )
00180 {
00181     bool ret = false ;
00182     BESContainerStorageVolatile::Container_iter i ;
00183     i = _container_list.find( s_name ) ;
00184     if( i != _container_list.end() )
00185     {
00186         BESContainer *c = (*i).second;
00187         _container_list.erase( i ) ;
00188         delete c ;
00189         ret = true ;
00190     }
00191     return ret ;
00192 }
00193 
00201 bool
00202 BESContainerStorageVolatile::del_containers( )
00203 {
00204     while( _container_list.size() != 0 )
00205     {
00206         Container_iter ci = _container_list.begin() ;
00207         BESContainer *c = (*ci).second ;
00208         _container_list.erase( ci ) ;
00209         if( c )
00210         {
00211             delete c ;
00212         }
00213     }
00214     return true ;
00215 }
00216 
00231 void
00232 BESContainerStorageVolatile::show_containers( BESInfo &info )
00233 {
00234     info.add_tag( "name", get_name() ) ;
00235     BESContainerStorageVolatile::Container_iter i = _container_list.begin() ;
00236     for( ; i != _container_list.end(); i++ )
00237     {
00238         info.begin_tag( "container" ) ;
00239         BESContainer *c = (*i).second;
00240         string sym = c->get_symbolic_name() ;
00241         info.add_tag( "symbolicName", sym ) ;
00242         string real = c->get_real_name() ;
00243         info.add_tag( "realName", real ) ;
00244         string type = c->get_container_type() ;
00245         info.add_tag( "dataType", type ) ;
00246         info.end_tag( "container" ) ;
00247     }
00248 }
00249 
00257 void
00258 BESContainerStorageVolatile::dump( ostream &strm ) const
00259 {
00260     strm << BESIndent::LMarg << "BESContainerStorageVolatile::dump - ("
00261                              << (void *)this << ")" << endl ;
00262     BESIndent::Indent() ;
00263     strm << BESIndent::LMarg << "name: " << get_name() << endl ;
00264     if( _container_list.size() )
00265     {
00266         strm << BESIndent::LMarg << "containers:" << endl ;
00267         BESIndent::Indent() ;
00268         BESContainerStorageVolatile::Container_citer i
00269             = _container_list.begin() ;
00270         BESContainerStorageVolatile::Container_citer ie
00271             = _container_list.end() ;
00272         for( ; i != ie; i++ )
00273         {
00274             BESContainer *c = (*i).second;
00275             c->dump( strm ) ;
00276         }
00277         BESIndent::UnIndent() ;
00278     }
00279     else
00280     {
00281         strm << BESIndent::LMarg << "containers: none" << endl ;
00282     }
00283     BESIndent::UnIndent() ;
00284 }
00285 

Generated on Wed Jan 2 06:01:18 2008 for OPeNDAP Back End Server (BES) by  doxygen 1.5.4