bes  Updated for version 3.20.6
BESReturnManager.cc
1 // BESReturnManager.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 "BESReturnManager.h"
34 
35 using std::endl;
36 using std::ostream;
37 using std::string;
38 
39 BESReturnManager *BESReturnManager::_instance = 0;
40 
41 BESReturnManager::BESReturnManager()
42 {
43 }
44 
45 BESReturnManager::~BESReturnManager()
46 {
47  BESReturnManager::Transmitter_iter i;
48  BESTransmitter *t = 0;
49  for (i = _transmitter_list.begin(); i != _transmitter_list.end(); i++) {
50  t = (*i).second;
51  delete t;
52  }
53 }
54 
55 bool BESReturnManager::add_transmitter(const string &name, BESTransmitter *transmitter)
56 {
57  if (find_transmitter(name) == 0) {
58  _transmitter_list[name] = transmitter;
59  return true;
60  }
61  return false;
62 }
63 
64 bool BESReturnManager::del_transmitter(const string &name)
65 {
66  bool ret = false;
67  BESReturnManager::Transmitter_iter i;
68  i = _transmitter_list.find(name);
69  if (i != _transmitter_list.end()) {
70  BESTransmitter *obj = (*i).second;
71  _transmitter_list.erase(i);
72  if (obj) delete obj;
73  ret = true;
74  }
75  return ret;
76 }
77 
79 BESReturnManager::find_transmitter(const string &name)
80 {
81  BESReturnManager::Transmitter_citer i;
82  i = _transmitter_list.find(name);
83  if (i != _transmitter_list.end()) {
84  return (*i).second;
85  }
86  return 0;
87 }
88 
96 void BESReturnManager::dump(ostream &strm) const
97 {
98  strm << BESIndent::LMarg << "BESReturnManager::dump - (" << (void *) this << ")" << endl;
99  BESIndent::Indent();
100  if (_transmitter_list.size()) {
101  strm << BESIndent::LMarg << "registered transmitters:" << endl;
102  BESIndent::Indent();
103  BESReturnManager::Transmitter_citer i = _transmitter_list.begin();
104  BESReturnManager::Transmitter_citer ie = _transmitter_list.end();
105  for (; i != ie; i++) {
106  strm << BESIndent::LMarg << (*i).first << endl;
107  BESIndent::Indent();
108  (*i).second->dump(strm);
109  BESIndent::UnIndent();
110  }
111  BESIndent::UnIndent();
112  }
113  else {
114  strm << BESIndent::LMarg << "registered transmitters: none" << endl;
115  }
116  BESIndent::UnIndent();
117 }
118 
120 BESReturnManager::TheManager()
121 {
122  if (_instance == 0) {
123  _instance = new BESReturnManager;
124  }
125  return _instance;
126 }
127 
BESReturnManager::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: BESReturnManager.cc:96
BESTransmitter
Definition: BESTransmitter.h:47
BESReturnManager
ReturnManager holds the list of response object transmitter that knows how to transmit response objec...
Definition: BESReturnManager.h:49