BESContextManager.cc

Go to the documentation of this file.
00001 // BESContextManager.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 "BESContextManager.h"
00034 #include "BESInfo.h"
00035 
00036 BESContextManager *BESContextManager::_instance = 0 ;
00037 
00043 void
00044 BESContextManager::set_context( const string &name, const string &value )
00045 {
00046     _context_list[name] = value ;
00047 }
00048 
00058 string
00059 BESContextManager::get_context( const string &name, bool &found )
00060 {
00061     string ret ;
00062     found = false ;
00063     BESContextManager::Context_iter i ;
00064     i = _context_list.find( name ) ;
00065     if( i != _context_list.end() )
00066     {
00067         ret = (*i).second;
00068         found = true ;
00069     }
00070     return ret ;
00071 }
00072 
00076 void
00077 BESContextManager::list_context( BESInfo &info )
00078 {
00079     string name ;
00080     string value ;
00081     map<string,string> props ;
00082     BESContextManager::Context_citer i = _context_list.begin() ;
00083     BESContextManager::Context_citer e = _context_list.end() ;
00084     for( ; i != e; i++ )
00085     {
00086         props.clear() ;
00087         name = (*i).first ;
00088         value = (*i).second ;
00089         props["name"] = name ;
00090         info.add_tag( "context", value, &props ) ;
00091     }
00092 }
00093 
00101 void
00102 BESContextManager::dump( ostream &strm ) const
00103 {
00104     strm << BESIndent::LMarg << "BESContextManager::dump - ("
00105                              << (void *)this << ")" << endl ;
00106     BESIndent::Indent() ;
00107     if( _context_list.size() )
00108     {
00109         strm << BESIndent::LMarg << "current context:" << endl ;
00110         BESIndent::Indent() ;
00111         BESContextManager::Context_citer i = _context_list.begin() ;
00112         BESContextManager::Context_citer ie = _context_list.end() ;
00113         for( ; i != ie; i++ ) 
00114         {
00115             strm << BESIndent::LMarg << (*i).first << ": " << (*i).second
00116                  << endl ;
00117         }
00118         BESIndent::UnIndent() ;
00119     }
00120     else
00121     {
00122         strm << BESIndent::LMarg << "no context" << endl ;
00123     }
00124     BESIndent::UnIndent() ;
00125 }
00126 
00127 BESContextManager *
00128 BESContextManager::TheManager()
00129 {
00130     if( _instance == 0 )
00131     {
00132         _instance = new BESContextManager ;
00133     }
00134     return _instance ;
00135 }
00136 

Generated on Sat Aug 22 06:06:26 2009 for OPeNDAP Hyrax Back End Server (BES) by  doxygen 1.6.0