bes  Updated for version 3.17.0
BESAggFactory.cc
1 // BESAggFactory.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 "BESAggFactory.h"
34 
35 BESAggFactory *BESAggFactory::_instance = 0 ;
36 
47 bool
48 BESAggFactory::add_handler( const string &handler_name,
49  p_agg_handler handler_method )
50 {
51  BESAggFactory::Handler_citer i ;
52  i = _handler_list.find( handler_name ) ;
53  if( i == _handler_list.end() )
54  {
55  _handler_list[handler_name] = handler_method ;
56  return true ;
57  }
58  return false ;
59 }
60 
70 bool
71 BESAggFactory::remove_handler( const string &handler_name )
72 {
73  BESAggFactory::Handler_iter i ;
74  i = _handler_list.find( handler_name ) ;
75  if( i != _handler_list.end() )
76  {
77  _handler_list.erase( i ) ;
78  return true ;
79  }
80  return false ;
81 }
82 
96 BESAggFactory::find_handler( const string &handler_name )
97 {
98  BESAggFactory::Handler_citer i ;
99  i = _handler_list.find( handler_name ) ;
100  if( i != _handler_list.end() )
101  {
102  p_agg_handler p = (*i).second ;
103  if( p )
104  {
105  return p( handler_name ) ;
106  }
107  }
108  return 0 ;
109 }
110 
119 string
121 {
122  string ret = "";
123  bool first_name = true ;
124  BESAggFactory::Handler_citer i = _handler_list.begin() ;
125  for( ; i != _handler_list.end(); i++ )
126  {
127  if( !first_name )
128  ret += ", " ;
129  ret += (*i).first ;
130  first_name = false ;
131  }
132  return ret ;
133 }
134 
142 void
143 BESAggFactory::dump( ostream &strm ) const
144 {
145  strm << BESIndent::LMarg << "BESAggFactory::dump - ("
146  << (void *)this << ")" << endl ;
147  BESIndent::Indent() ;
148  if( _handler_list.size() )
149  {
150  strm << BESIndent::LMarg << "registered agg handlers:" << endl ;
151  BESIndent::Indent() ;
152  BESAggFactory::Handler_citer i = _handler_list.begin() ;
153  for( ; i != _handler_list.end(); i++ )
154  {
155  strm << BESIndent::LMarg << (*i).first << endl ;
156  }
157  BESIndent::UnIndent() ;
158  }
159  else
160  {
161  strm << BESIndent::LMarg << "registered agg handlers: none" << endl ;
162  }
163  BESIndent::UnIndent() ;
164 }
165 
167 BESAggFactory::TheFactory()
168 {
169  if( _instance == 0 )
170  {
171  _instance = new BESAggFactory ;
172  }
173  return _instance ;
174 }
175 
virtual bool remove_handler(const string &handler_name)
removes a response handler from the list
List of all registered aggregation handlers for this server.
Definition: BESAggFactory.h:55
virtual BESAggregationServer * find_handler(const string &handler_name)
returns the aggregation handler with the given name in the list
virtual string get_handler_names()
returns the list of all agg handlers currently registered with this server.
virtual void dump(ostream &strm) const
dumps information about this object
virtual bool add_handler(const string &handler_name, p_agg_handler handler_method)
add an aggregation handler to the list
Abstraction representing mechanism for aggregating data.