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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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  {
67  ret = (*i).second;
68  found = true ;
69  }
70  return ret ;
71 }
72 
76 void
78 {
79  string name ;
80  string value ;
81  map<string,string> props ;
82  BESContextManager::Context_citer i = _context_list.begin() ;
83  BESContextManager::Context_citer e = _context_list.end() ;
84  for( ; i != e; i++ )
85  {
86  props.clear() ;
87  name = (*i).first ;
88  value = (*i).second ;
89  props["name"] = name ;
90  info.add_tag( "context", value, &props ) ;
91  }
92 }
93 
101 void
102 BESContextManager::dump( ostream &strm ) const
103 {
104  strm << BESIndent::LMarg << "BESContextManager::dump - ("
105  << (void *)this << ")" << endl ;
107  if( _context_list.size() )
108  {
109  strm << BESIndent::LMarg << "current context:" << endl ;
111  BESContextManager::Context_citer i = _context_list.begin() ;
112  BESContextManager::Context_citer ie = _context_list.end() ;
113  for( ; i != ie; i++ )
114  {
115  strm << BESIndent::LMarg << (*i).first << ": " << (*i).second
116  << endl ;
117  }
119  }
120  else
121  {
122  strm << BESIndent::LMarg << "no context" << endl ;
123  }
125 }
126 
129 {
130  if( _instance == 0 )
131  {
132  _instance = new BESContextManager ;
133  }
134  return _instance ;
135 }
136