OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
BESReporterList.cc
Go to the documentation of this file.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 
39 {
40 }
41 
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 ;
50  _reporter_list.erase( i ) ;
51  }
52 }
53 
54 bool
55 BESReporterList::add_reporter( string reporter_name,
56  BESReporter *reporter_object )
57 {
58  if( find_reporter( reporter_name ) == 0 )
59  {
60  _reporter_list[reporter_name] = reporter_object ;
61  return true ;
62  }
63  return false ;
64 }
65 
67 BESReporterList::remove_reporter( string reporter_name )
68 {
69  BESReporter *ret = 0 ;
71  i = _reporter_list.find( reporter_name ) ;
72  if( i != _reporter_list.end() )
73  {
74  ret = (*i).second;
75  _reporter_list.erase( i ) ;
76  }
77  return ret ;
78 }
79 
81 BESReporterList::find_reporter( string reporter_name )
82 {
84  i = _reporter_list.find( reporter_name ) ;
85  if( i != _reporter_list.end() )
86  {
87  return (*i).second;
88  }
89  return 0 ;
90 }
91 
92 void
94 {
95  BESReporter *reporter = 0 ;
96  BESReporterList::Reporter_iter i = _reporter_list.begin() ;
97  for( ; i != _reporter_list.end(); i++ )
98  {
99  reporter = (*i).second ;
100  if( reporter ) reporter->report( dhi ) ;
101  }
102 }
103 
111 void
112 BESReporterList::dump( ostream &strm ) const
113 {
114  strm << BESIndent::LMarg << "BESReporterList::dump - ("
115  << (void *)this << ")" << endl ;
117  if( _reporter_list.size() )
118  {
119  strm << BESIndent::LMarg << "registered reporters:" << endl ;
121  BESReporterList::Reporter_citer i = _reporter_list.begin() ;
122  BESReporterList::Reporter_citer ie = _reporter_list.end() ;
123  for( ; i != ie; i++ )
124  {
125  strm << BESIndent::LMarg << "reporter: " << (*i).first << endl ;
127  BESReporter *reporter = (*i).second ;
128  reporter->dump( strm ) ;
130  }
132  }
133  else
134  {
135  strm << BESIndent::LMarg << "registered reporters: none" << endl ;
136  }
138 }
139 
142 {
143  if( _instance == 0 )
144  {
145  _instance = new BESReporterList ;
146  }
147  return _instance ;
148 }
149 
static BESReporterList * TheList()
map< string, BESReporter *>::const_iterator Reporter_citer
virtual void report(BESDataHandlerInterface &dhi)
virtual BESReporter * remove_reporter(string reporter_name)
virtual void dump(ostream &strm) const
dumps information about this object
static void Indent()
Definition: BESIndent.cc:38
static ostream & LMarg(ostream &strm)
Definition: BESIndent.cc:73
map< string, BESReporter *>::iterator Reporter_iter
virtual bool add_reporter(string reporter_name, BESReporter *handler)
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.
virtual ~BESReporterList(void)
virtual BESReporter * find_reporter(string reporter_name)
virtual void report(BESDataHandlerInterface &dhi)=0
static void UnIndent()
Definition: BESIndent.cc:44