bes  Updated for version 3.19.1
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 BESReporterList *BESReporterList::_instance = 0 ;
37 
38 BESReporterList::BESReporterList()
39 {
40 }
41 
42 BESReporterList::~BESReporterList()
43 {
44  BESReporter *reporter = 0 ;
45  BESReporterList::Reporter_iter i = _reporter_list.begin() ;
46  for( ; i != _reporter_list.end(); i++ )
47  {
48  reporter = (*i).second ;
49  if( reporter ) { delete reporter ; (*i).second = 0 ; }
50  // instead of erasing each element as I go, call clear outside
51  // of the for loop
52  }
53  _reporter_list.clear() ;
54 }
55 
56 bool
57 BESReporterList::add_reporter( string reporter_name,
58  BESReporter *reporter_object )
59 {
60  if( find_reporter( reporter_name ) == 0 )
61  {
62  _reporter_list[reporter_name] = reporter_object ;
63  return true ;
64  }
65  return false ;
66 }
67 
69 BESReporterList::remove_reporter( string reporter_name )
70 {
71  BESReporter *ret = 0 ;
72  BESReporterList::Reporter_iter i ;
73  i = _reporter_list.find( reporter_name ) ;
74  if( i != _reporter_list.end() )
75  {
76  ret = (*i).second;
77  _reporter_list.erase( i ) ;
78  }
79  return ret ;
80 }
81 
83 BESReporterList::find_reporter( string reporter_name )
84 {
85  BESReporterList::Reporter_citer i ;
86  i = _reporter_list.find( reporter_name ) ;
87  if( i != _reporter_list.end() )
88  {
89  return (*i).second;
90  }
91  return 0 ;
92 }
93 
94 void
95 BESReporterList::report( BESDataHandlerInterface &dhi )
96 {
97  BESReporter *reporter = 0 ;
98  BESReporterList::Reporter_iter i = _reporter_list.begin() ;
99  for( ; i != _reporter_list.end(); i++ )
100  {
101  reporter = (*i).second ;
102  if( reporter ) reporter->report( dhi ) ;
103  }
104 }
105 
113 void
114 BESReporterList::dump( ostream &strm ) const
115 {
116  strm << BESIndent::LMarg << "BESReporterList::dump - ("
117  << (void *)this << ")" << endl ;
118  BESIndent::Indent() ;
119  if( _reporter_list.size() )
120  {
121  strm << BESIndent::LMarg << "registered reporters:" << endl ;
122  BESIndent::Indent() ;
123  BESReporterList::Reporter_citer i = _reporter_list.begin() ;
124  BESReporterList::Reporter_citer ie = _reporter_list.end() ;
125  for( ; i != ie; i++ )
126  {
127  strm << BESIndent::LMarg << "reporter: " << (*i).first << endl ;
128  BESIndent::Indent() ;
129  BESReporter *reporter = (*i).second ;
130  reporter->dump( strm ) ;
131  BESIndent::UnIndent() ;
132  }
133  BESIndent::UnIndent() ;
134  }
135  else
136  {
137  strm << BESIndent::LMarg << "registered reporters: none" << endl ;
138  }
139  BESIndent::UnIndent() ;
140 }
141 
143 BESReporterList::TheList()
144 {
145  if( _instance == 0 )
146  {
147  _instance = new BESReporterList ;
148  }
149  return _instance ;
150 }
151 
virtual void dump(ostream &strm) const
dumps information about this object
virtual void dump(ostream &strm) const =0
dump the contents of this object to the specified ostream
Structure storing information used by the BES to handle the request.