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