bes  Updated for version 3.20.6
BESReporterList.cc
1 // BESReporterList.cc
2 
3 // This file is part of bes, A C++ back-end server implementation framework
4 // for the OPeNDAP Data Access Protocol.
5 
6 // Copyright (c) 2004-2009 University Corporation for Atmospheric Research
7 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 //
23 // You can contact University Corporation for Atmospheric Research at
24 // 3080 Center Green Drive, Boulder, CO 80301
25 
26 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
27 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
28 //
29 // Authors:
30 // pwest Patrick West <pwest@ucar.edu>
31 // jgarcia Jose Garcia <jgarcia@ucar.edu>
32 
33 #include "BESReporterList.h"
34 #include "BESReporter.h"
35 
36 using std::endl;
37 using std::ostream;
38 using std::string;
39 
40 BESReporterList *BESReporterList::_instance = 0 ;
41 
42 BESReporterList::BESReporterList()
43 {
44 }
45 
46 BESReporterList::~BESReporterList()
47 {
48  BESReporter *reporter = 0 ;
49  BESReporterList::Reporter_iter i = _reporter_list.begin() ;
50  for( ; i != _reporter_list.end(); i++ )
51  {
52  reporter = (*i).second ;
53  if( reporter ) { delete reporter ; (*i).second = 0 ; }
54  // instead of erasing each element as I go, call clear outside
55  // of the for loop
56  }
57  _reporter_list.clear() ;
58 }
59 
60 bool
61 BESReporterList::add_reporter( string reporter_name,
62  BESReporter *reporter_object )
63 {
64  if( find_reporter( reporter_name ) == 0 )
65  {
66  _reporter_list[reporter_name] = reporter_object ;
67  return true ;
68  }
69  return false ;
70 }
71 
73 BESReporterList::remove_reporter( string reporter_name )
74 {
75  BESReporter *ret = 0 ;
76  BESReporterList::Reporter_iter i ;
77  i = _reporter_list.find( reporter_name ) ;
78  if( i != _reporter_list.end() )
79  {
80  ret = (*i).second;
81  _reporter_list.erase( i ) ;
82  }
83  return ret ;
84 }
85 
87 BESReporterList::find_reporter( string reporter_name )
88 {
89  BESReporterList::Reporter_citer i ;
90  i = _reporter_list.find( reporter_name ) ;
91  if( i != _reporter_list.end() )
92  {
93  return (*i).second;
94  }
95  return 0 ;
96 }
97 
98 void
99 BESReporterList::report( BESDataHandlerInterface &dhi )
100 {
101  BESReporter *reporter = 0 ;
102  BESReporterList::Reporter_iter i = _reporter_list.begin() ;
103  for( ; i != _reporter_list.end(); i++ )
104  {
105  reporter = (*i).second ;
106  if( reporter ) reporter->report( dhi ) ;
107  }
108 }
109 
117 void
118 BESReporterList::dump( ostream &strm ) const
119 {
120  strm << BESIndent::LMarg << "BESReporterList::dump - ("
121  << (void *)this << ")" << endl ;
122  BESIndent::Indent() ;
123  if( _reporter_list.size() )
124  {
125  strm << BESIndent::LMarg << "registered reporters:" << endl ;
126  BESIndent::Indent() ;
127  BESReporterList::Reporter_citer i = _reporter_list.begin() ;
128  BESReporterList::Reporter_citer ie = _reporter_list.end() ;
129  for( ; i != ie; i++ )
130  {
131  strm << BESIndent::LMarg << "reporter: " << (*i).first << endl ;
132  BESIndent::Indent() ;
133  BESReporter *reporter = (*i).second ;
134  reporter->dump( strm ) ;
135  BESIndent::UnIndent() ;
136  }
137  BESIndent::UnIndent() ;
138  }
139  else
140  {
141  strm << BESIndent::LMarg << "registered reporters: none" << endl ;
142  }
143  BESIndent::UnIndent() ;
144 }
145 
147 BESReporterList::TheList()
148 {
149  if( _instance == 0 )
150  {
151  _instance = new BESReporterList ;
152  }
153  return _instance ;
154 }
155 
BESReporterList
Definition: BESReporterList.h:44
BESReporter::dump
virtual void dump(std::ostream &strm) const =0
dump the contents of this object to the specified ostream
BESReporter
Definition: BESReporter.h:39
BESDataHandlerInterface
Structure storing information used by the BES to handle the request.
Definition: BESDataHandlerInterface.h:56
BESReporterList::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: BESReporterList.cc:118