OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
BESContextManager.cc
Go to the documentation of this file.
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 
58 string
59 BESContextManager::get_context( const string &name, bool &found )
60 {
61  string ret = "";
62  found = false;
64  i = _context_list.find(name);
65  if (i != _context_list.end()) {
66  ret = (*i).second;
67  found = true;
68  }
69  return ret;
70 }
71 
75 void
77 {
78  string name ;
79  string value ;
80  map<string,string> props ;
81  BESContextManager::Context_citer i = _context_list.begin() ;
82  BESContextManager::Context_citer e = _context_list.end() ;
83  for( ; i != e; i++ )
84  {
85  props.clear() ;
86  name = (*i).first ;
87  value = (*i).second ;
88  props["name"] = name ;
89  info.add_tag( "context", value, &props ) ;
90  }
91 }
92 
100 void
101 BESContextManager::dump( ostream &strm ) const
102 {
103  strm << BESIndent::LMarg << "BESContextManager::dump - ("
104  << (void *)this << ")" << endl ;
106  if( _context_list.size() )
107  {
108  strm << BESIndent::LMarg << "current context:" << endl ;
110  BESContextManager::Context_citer i = _context_list.begin() ;
111  BESContextManager::Context_citer ie = _context_list.end() ;
112  for( ; i != ie; i++ )
113  {
114  strm << BESIndent::LMarg << (*i).first << ": " << (*i).second
115  << endl ;
116  }
118  }
119  else
120  {
121  strm << BESIndent::LMarg << "no context" << endl ;
122  }
124 }
125 
128 {
129  if( _instance == 0 )
130  {
131  _instance = new BESContextManager ;
132  }
133  return _instance ;
134 }
135 
map< string, string >::const_iterator Context_citer
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 void add_tag(const string &tag_name, const string &tag_data, map< string, string > *attrs=0)=0
virtual string get_context(const string &name, bool &found)
retrieve the value of the specified context from the BES
static void Indent()
Definition: BESIndent.cc:38
map< string, string >::iterator Context_iter
informational response object
Definition: BESInfo.h:68
virtual void list_context(BESInfo &info)
Adds all context and their values to the given informational object.
static ostream & LMarg(ostream &strm)
Definition: BESIndent.cc:73
static BESContextManager * TheManager()
static void UnIndent()
Definition: BESIndent.cc:44