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,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 "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     try
00082     {
00083         info_type = TheBESKeys::TheKeys()->get_key( "BES.Info.Type", found ) ;
00084     }
00085     catch( ... )
00086     {
00087         info_type = "" ;
00088     }
00089 
00090     if( !found || info_type == "" )
00091         info_type = BES_DEFAULT_INFO_TYPE ;
00092 
00093     BESInfoList::Info_citer i ;
00094     i = _info_list.find( info_type ) ;
00095     if( i != _info_list.end() )
00096     {
00097         p_info_builder p = (*i).second ;
00098         if( p )
00099         {
00100             return p( info_type ) ;
00101         }
00102     }
00103     return 0 ;
00104 }
00105 
00113 void
00114 BESInfoList::dump( ostream &strm ) const
00115 {
00116     strm << BESIndent::LMarg << "BESInfoList::dump - ("
00117                              << (void *)this << ")" << endl ;
00118     BESIndent::Indent() ;
00119     if( _info_list.size() )
00120     {
00121         strm << BESIndent::LMarg << "registered builders:" << endl ;
00122         BESIndent::Indent() ;
00123         BESInfoList::Info_citer i = _info_list.begin() ;
00124         BESInfoList::Info_citer ie = _info_list.end() ;
00125         for( ; i != ie; i++ )
00126         {
00127             p_info_builder p = (*i).second ;
00128             if( p )
00129             {
00130                 BESInfo *info = p( "dump" ) ;
00131                 info->dump( strm ) ;
00132                 delete info ;
00133             }
00134             else
00135             {
00136                 strm << BESIndent::LMarg << "builder is null" << endl ;
00137             }
00138         }
00139         BESIndent::UnIndent() ;
00140     }
00141     else
00142     {
00143         strm << BESIndent::LMarg << "registered builders: none" << endl ;
00144     }
00145     BESIndent::UnIndent() ;
00146 }
00147 
00148 BESInfoList *
00149 BESInfoList::TheList()
00150 {
00151     if( _instance == 0 )
00152     {
00153         _instance = new BESInfoList ;
00154     }
00155     return _instance ;
00156 }
00157 

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