bes  Updated for version 3.20.6
BESInfoList.cc
1 // BESInfoList.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 "BESInfoList.h"
34 #include "BESInfo.h"
35 #include "TheBESKeys.h"
36 
37 using std::endl;
38 using std::ostream;
39 using std::string;
40 
41 #define BES_DEFAULT_INFO_TYPE "txt"
42 
43 BESInfoList *BESInfoList::_instance = 0 ;
44 
45 BESInfoList::BESInfoList()
46 {
47 }
48 
49 BESInfoList::~BESInfoList()
50 {
51 }
52 
53 bool
54 BESInfoList::add_info_builder( const string &info_type,
55  p_info_builder info_builder )
56 {
57  BESInfoList::Info_citer i ;
58  i = _info_list.find( info_type ) ;
59  if( i == _info_list.end() )
60  {
61  _info_list[info_type] = info_builder ;
62  return true ;
63  }
64  return false ;
65 }
66 
67 bool
68 BESInfoList::rem_info_builder( const string &info_type )
69 {
70  BESInfoList::Info_iter i ;
71  i = _info_list.find( info_type ) ;
72  if( i != _info_list.end() )
73  {
74  _info_list.erase( i ) ;
75  return true ;
76  }
77  return false ;
78 }
79 
80 BESInfo *
81 BESInfoList::build_info( )
82 {
83  string info_type = "" ;
84  bool found = false ;
85  TheBESKeys::TheKeys()->get_value( "BES.Info.Type", info_type, found ) ;
86 
87  if( !found || info_type == "" )
88  info_type = BES_DEFAULT_INFO_TYPE ;
89 
90  BESInfoList::Info_citer i ;
91  i = _info_list.find( info_type ) ;
92  if( i != _info_list.end() )
93  {
94  p_info_builder p = (*i).second ;
95  if( p )
96  {
97  return p( info_type ) ;
98  }
99  }
100  return 0 ;
101 }
102 
110 void
111 BESInfoList::dump( ostream &strm ) const
112 {
113  strm << BESIndent::LMarg << "BESInfoList::dump - ("
114  << (void *)this << ")" << endl ;
115  BESIndent::Indent() ;
116  if( _info_list.size() )
117  {
118  strm << BESIndent::LMarg << "registered builders:" << endl ;
119  BESIndent::Indent() ;
120  BESInfoList::Info_citer i = _info_list.begin() ;
121  BESInfoList::Info_citer ie = _info_list.end() ;
122  for( ; i != ie; i++ )
123  {
124  p_info_builder p = (*i).second ;
125  if( p )
126  {
127  BESInfo *info = p( "dump" ) ;
128  info->dump( strm ) ;
129  delete info ;
130  }
131  else
132  {
133  strm << BESIndent::LMarg << "builder is null" << endl ;
134  }
135  }
136  BESIndent::UnIndent() ;
137  }
138  else
139  {
140  strm << BESIndent::LMarg << "registered builders: none" << endl ;
141  }
142  BESIndent::UnIndent() ;
143 }
144 
145 BESInfoList *
146 BESInfoList::TheList()
147 {
148  if( _instance == 0 )
149  {
150  _instance = new BESInfoList ;
151  }
152  return _instance ;
153 }
154 
BESInfo
informational response object
Definition: BESInfo.h:63
TheBESKeys::TheKeys
static TheBESKeys * TheKeys()
Definition: TheBESKeys.cc:62
BESInfoList
Definition: BESInfoList.h:45
BESInfoList::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: BESInfoList.cc:111
TheBESKeys::get_value
void get_value(const std::string &s, std::string &val, bool &found)
Retrieve the value of a given key, if set.
Definition: TheBESKeys.cc:272
BESInfo::dump
virtual void dump(std::ostream &strm) const
Displays debug information about this object.
Definition: BESInfo.cc:275