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 "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