bes  Updated for version 3.17.0
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
44 BESContextManager::set_context( const string &name, const string &value )
45 {
46  _context_list[name] = value ;
47 }
48 
54 void
55 BESContextManager::unset_context( const string &name )
56 {
57  _context_list.erase(name);
58 }
59 
69 string
70 BESContextManager::get_context( const string &name, bool &found )
71 {
72  string ret = "";
73  found = false;
74  BESContextManager::Context_iter i;
75  i = _context_list.find(name);
76  if (i != _context_list.end()) {
77  ret = (*i).second;
78  found = true;
79  }
80  return ret;
81 }
82 
86 void
88 {
89  string name ;
90  string value ;
91  map<string,string> props ;
92  BESContextManager::Context_citer i = _context_list.begin() ;
93  BESContextManager::Context_citer e = _context_list.end() ;
94  for( ; i != e; i++ )
95  {
96  props.clear() ;
97  name = (*i).first ;
98  value = (*i).second ;
99  props["name"] = name ;
100  info.add_tag( "context", value, &props ) ;
101  }
102 }
103 
111 void
112 BESContextManager::dump( ostream &strm ) const
113 {
114  strm << BESIndent::LMarg << "BESContextManager::dump - ("
115  << (void *)this << ")" << endl ;
116  BESIndent::Indent() ;
117  if( _context_list.size() )
118  {
119  strm << BESIndent::LMarg << "current context:" << endl ;
120  BESIndent::Indent() ;
121  BESContextManager::Context_citer i = _context_list.begin() ;
122  BESContextManager::Context_citer ie = _context_list.end() ;
123  for( ; i != ie; i++ )
124  {
125  strm << BESIndent::LMarg << (*i).first << ": " << (*i).second
126  << endl ;
127  }
128  BESIndent::UnIndent() ;
129  }
130  else
131  {
132  strm << BESIndent::LMarg << "no context" << endl ;
133  }
134  BESIndent::UnIndent() ;
135 }
136 
138 BESContextManager::TheManager()
139 {
140  if( _instance == 0 )
141  {
142  _instance = new BESContextManager ;
143  }
144  return _instance ;
145 }
146 
maintains the list of registered request handlers for this server
virtual void dump(ostream &strm) const
dumps information about this object
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