OPeNDAP Hyrax Back End Server (BES)
Updated for version 3.8.3
|
00001 // BESReporterList.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 "BESReporterList.h" 00034 #include "BESReporter.h" 00035 00036 BESReporterList *BESReporterList::_instance = 0 ; 00037 00038 BESReporterList::BESReporterList() 00039 { 00040 } 00041 00042 BESReporterList::~BESReporterList() 00043 { 00044 BESReporter *reporter = 0 ; 00045 BESReporterList::Reporter_iter i = _reporter_list.begin() ; 00046 for( ; i != _reporter_list.end(); i++ ) 00047 { 00048 reporter = (*i).second ; 00049 if( reporter ) { delete reporter ; (*i).second = 0 ; } 00050 // instead of erasing each element as I go, call clear outside 00051 // of the for loop 00052 } 00053 _reporter_list.clear() ; 00054 } 00055 00056 bool 00057 BESReporterList::add_reporter( string reporter_name, 00058 BESReporter *reporter_object ) 00059 { 00060 if( find_reporter( reporter_name ) == 0 ) 00061 { 00062 _reporter_list[reporter_name] = reporter_object ; 00063 return true ; 00064 } 00065 return false ; 00066 } 00067 00068 BESReporter * 00069 BESReporterList::remove_reporter( string reporter_name ) 00070 { 00071 BESReporter *ret = 0 ; 00072 BESReporterList::Reporter_iter i ; 00073 i = _reporter_list.find( reporter_name ) ; 00074 if( i != _reporter_list.end() ) 00075 { 00076 ret = (*i).second; 00077 _reporter_list.erase( i ) ; 00078 } 00079 return ret ; 00080 } 00081 00082 BESReporter * 00083 BESReporterList::find_reporter( string reporter_name ) 00084 { 00085 BESReporterList::Reporter_citer i ; 00086 i = _reporter_list.find( reporter_name ) ; 00087 if( i != _reporter_list.end() ) 00088 { 00089 return (*i).second; 00090 } 00091 return 0 ; 00092 } 00093 00094 void 00095 BESReporterList::report( BESDataHandlerInterface &dhi ) 00096 { 00097 BESReporter *reporter = 0 ; 00098 BESReporterList::Reporter_iter i = _reporter_list.begin() ; 00099 for( ; i != _reporter_list.end(); i++ ) 00100 { 00101 reporter = (*i).second ; 00102 if( reporter ) reporter->report( dhi ) ; 00103 } 00104 } 00105 00113 void 00114 BESReporterList::dump( ostream &strm ) const 00115 { 00116 strm << BESIndent::LMarg << "BESReporterList::dump - (" 00117 << (void *)this << ")" << endl ; 00118 BESIndent::Indent() ; 00119 if( _reporter_list.size() ) 00120 { 00121 strm << BESIndent::LMarg << "registered reporters:" << endl ; 00122 BESIndent::Indent() ; 00123 BESReporterList::Reporter_citer i = _reporter_list.begin() ; 00124 BESReporterList::Reporter_citer ie = _reporter_list.end() ; 00125 for( ; i != ie; i++ ) 00126 { 00127 strm << BESIndent::LMarg << "reporter: " << (*i).first << endl ; 00128 BESIndent::Indent() ; 00129 BESReporter *reporter = (*i).second ; 00130 reporter->dump( strm ) ; 00131 BESIndent::UnIndent() ; 00132 } 00133 BESIndent::UnIndent() ; 00134 } 00135 else 00136 { 00137 strm << BESIndent::LMarg << "registered reporters: none" << endl ; 00138 } 00139 BESIndent::UnIndent() ; 00140 } 00141 00142 BESReporterList * 00143 BESReporterList::TheList() 00144 { 00145 if( _instance == 0 ) 00146 { 00147 _instance = new BESReporterList ; 00148 } 00149 return _instance ; 00150 } 00151