BESInfoList.cc

Go to the documentation of this file.
00001 // BESInfoList.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 "BESInfoList.h"
00034 #include "BESInfo.h"
00035 #include "TheBESKeys.h"
00036 
00037 #define BES_DEFAULT_INFO_TYPE "txt"
00038 
00039 BESInfoList *BESInfoList::_instance = 0 ;
00040 
00041 BESInfoList::BESInfoList()
00042 {
00043 }
00044 
00045 BESInfoList::~BESInfoList()
00046 {
00047 }
00048 
00049 bool
00050 BESInfoList::add_info_builder( const string &info_type,
00051                                p_info_builder info_builder )
00052 {
00053     BESInfoList::Info_citer i ;
00054     i = _info_list.find( info_type ) ;
00055     if( i == _info_list.end() )
00056     {
00057         _info_list[info_type] = info_builder ;
00058         return true ;
00059     }
00060     return false ;
00061 }
00062 
00063 bool
00064 BESInfoList::rem_info_builder( const string &info_type )
00065 {
00066     BESInfoList::Info_iter i ;
00067     i = _info_list.find( info_type ) ;
00068     if( i != _info_list.end() )
00069     {
00070         _info_list.erase( i ) ;
00071         return true ;
00072     }
00073     return false ;
00074 }
00075 
00076 BESInfo *
00077 BESInfoList::build_info( )
00078 {
00079     string info_type = "" ;
00080     bool found = false ;
00081     TheBESKeys::TheKeys()->get_value( "BES.Info.Type", info_type, found ) ;
00082 
00083     if( !found || info_type == "" )
00084         info_type = BES_DEFAULT_INFO_TYPE ;
00085 
00086     BESInfoList::Info_citer i ;
00087     i = _info_list.find( info_type ) ;
00088     if( i != _info_list.end() )
00089     {
00090         p_info_builder p = (*i).second ;
00091         if( p )
00092         {
00093             return p( info_type ) ;
00094         }
00095     }
00096     return 0 ;
00097 }
00098 
00106 void
00107 BESInfoList::dump( ostream &strm ) const
00108 {
00109     strm << BESIndent::LMarg << "BESInfoList::dump - ("
00110                              << (void *)this << ")" << endl ;
00111     BESIndent::Indent() ;
00112     if( _info_list.size() )
00113     {
00114         strm << BESIndent::LMarg << "registered builders:" << endl ;
00115         BESIndent::Indent() ;
00116         BESInfoList::Info_citer i = _info_list.begin() ;
00117         BESInfoList::Info_citer ie = _info_list.end() ;
00118         for( ; i != ie; i++ )
00119         {
00120             p_info_builder p = (*i).second ;
00121             if( p )
00122             {
00123                 BESInfo *info = p( "dump" ) ;
00124                 info->dump( strm ) ;
00125                 delete info ;
00126             }
00127             else
00128             {
00129                 strm << BESIndent::LMarg << "builder is null" << endl ;
00130             }
00131         }
00132         BESIndent::UnIndent() ;
00133     }
00134     else
00135     {
00136         strm << BESIndent::LMarg << "registered builders: none" << endl ;
00137     }
00138     BESIndent::UnIndent() ;
00139 }
00140 
00141 BESInfoList *
00142 BESInfoList::TheList()
00143 {
00144     if( _instance == 0 )
00145     {
00146         _instance = new BESInfoList ;
00147     }
00148     return _instance ;
00149 }
00150