BESContextManager.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
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