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,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 "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     info.begin_tag( "context_list" ) ;
00080     string name ;
00081     string value ;
00082     BESContextManager::Context_citer i = _context_list.begin() ;
00083     BESContextManager::Context_citer e = _context_list.end() ;
00084     for( ; i != e; i++ )
00085     {
00086         name = (*i).first ;
00087         value = (*i).second ;
00088         map<string,string> temp_map ;
00089         temp_map["name"] = name ;
00090         info.add_tag( "Context", value, &temp_map ) ;
00091     }
00092     info.end_tag( "context_list" ) ;
00093 }
00094 
00102 void
00103 BESContextManager::dump( ostream &strm ) const
00104 {
00105     strm << BESIndent::LMarg << "BESContextManager::dump - ("
00106                              << (void *)this << ")" << endl ;
00107     BESIndent::Indent() ;
00108     if( _context_list.size() )
00109     {
00110         strm << BESIndent::LMarg << "current context:" << endl ;
00111         BESIndent::Indent() ;
00112         BESContextManager::Context_citer i = _context_list.begin() ;
00113         BESContextManager::Context_citer ie = _context_list.end() ;
00114         for( ; i != ie; i++ ) 
00115         {
00116             strm << BESIndent::LMarg << (*i).first << ": " << (*i).second
00117                  << endl ;
00118         }
00119         BESIndent::UnIndent() ;
00120     }
00121     else
00122     {
00123         strm << BESIndent::LMarg << "no context" << endl ;
00124     }
00125     BESIndent::UnIndent() ;
00126 }
00127 
00128 BESContextManager *
00129 BESContextManager::TheManager()
00130 {
00131     if( _instance == 0 )
00132     {
00133         _instance = new BESContextManager ;
00134     }
00135     return _instance ;
00136 }
00137 

Generated on Fri Nov 30 12:06:46 2007 for OPeNDAP Back End Server (BES) by  doxygen 1.5.1