bes  Updated for version 3.19.1
BESContextManager.cc
1 // BESContextManager.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 "BESContextManager.h"
34 #include "BESInfo.h"
35 
36 BESContextManager *BESContextManager::_instance = 0;
37 
43 void BESContextManager::set_context(const string &name, const string &value)
44 {
45  _context_list[name] = value;
46 }
47 
53 void BESContextManager::unset_context(const string &name)
54 {
55  _context_list.erase(name);
56 }
57 
67 string BESContextManager::get_context(const string &name, bool &found)
68 {
69  string ret = "";
70  found = false;
71  BESContextManager::Context_iter i;
72  i = _context_list.find(name);
73  if (i != _context_list.end()) {
74  ret = (*i).second;
75  found = true;
76  }
77  return ret;
78 }
79 
84 {
85  string name;
86  string value;
87  map<string, string> props;
88  BESContextManager::Context_citer i = _context_list.begin();
89  BESContextManager::Context_citer e = _context_list.end();
90  for (; i != e; i++) {
91  props.clear();
92  name = (*i).first;
93  value = (*i).second;
94  props["name"] = name;
95  info.add_tag("context", value, &props);
96  }
97 }
98 
106 void BESContextManager::dump(ostream &strm) const
107 {
108  strm << BESIndent::LMarg << "BESContextManager::dump - (" << (void *) this << ")" << endl;
109  BESIndent::Indent();
110  if (_context_list.size()) {
111  strm << BESIndent::LMarg << "current context:" << endl;
112  BESIndent::Indent();
113  BESContextManager::Context_citer i = _context_list.begin();
114  BESContextManager::Context_citer ie = _context_list.end();
115  for (; i != ie; i++) {
116  strm << BESIndent::LMarg << (*i).first << ": " << (*i).second << endl;
117  }
118  BESIndent::UnIndent();
119  }
120  else {
121  strm << BESIndent::LMarg << "no context" << endl;
122  }
123  BESIndent::UnIndent();
124 }
125 
127 BESContextManager::TheManager()
128 {
129  if (_instance == 0) {
130  _instance = new BESContextManager;
131  }
132  return _instance;
133 }
134 
maintains the list of registered request handlers for this server
virtual void set_context(const string &name, const string &value)
set context in the BES
virtual string get_context(const string &name, bool &found)
retrieve the value of the specified context from the BES
informational response object
Definition: BESInfo.h:68
virtual void list_context(BESInfo &info)
Adds all context and their values to the given informational object.
virtual void unset_context(const string &name)
set context in the BES
virtual void dump(ostream &strm) const
dumps information about this object