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