bes  Updated for version 3.20.6
TheBESKeys.h
1 // TheBESKeys.h
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 #ifndef TheBESKeys_h_
34 #define TheBESKeys_h_ 1
35 
36 #include <fstream>
37 #include <map>
38 #include <set>
39 #include <vector>
40 #include <string>
41 
42 #include "BESObj.h"
43 
80 class TheBESKeys: public BESObj {
81 private:
82 
83  // TODO I don't think this needs to be a pointer - the code could be
84  // redesigned. jhrg 3/7/18
85  std::ifstream * _keys_file;
86  std::string _keys_file_name;
87  std::map<std::string, std::vector<std::string> > *_the_keys;
88  bool _own_keys;
89 
90  static std::set<std::string> KeyList;
91  static bool LoadedKeys(const std::string &key_file);
92 
93  void clean();
94  void initialize_keys();
95 #if 0
96  //void load_keys();
97  //bool break_pair(const char* b, std::string& key, std::string &value, bool &addto);
98  //bool only_blanks(const char *line);
99  //void load_include_files(const std::string &files);
100  //void load_include_file(const std::string &file);
101 #endif
102  TheBESKeys() :
103  _keys_file(0), _keys_file_name(""), _the_keys(0), _own_keys(false)
104  {
105  }
106 
107  TheBESKeys(const std::string &keys_file_name, std::map<std::string, std::vector<std::string> > *keys);
108 
109 protected:
110  TheBESKeys(const std::string &keys_file_name);
111 
112 public:
113  static TheBESKeys *_instance;
114  virtual ~TheBESKeys();
115 
116  std::string keys_file_name() const
117  {
118  return _keys_file_name;
119  }
120 
121  void set_key(const std::string &key, const std::string &val, bool addto = false);
122  void set_key(const std::string &pair);
123 
124  void get_value(const std::string& s, std::string &val, bool &found);
125  void get_values(const std::string& s, std::vector<std::string> &vals, bool &found);
126 
127  bool read_bool_key(const std::string &key, bool default_value);
128  std::string read_string_key(const std::string &key, const std::string &default_value);
129  int read_int_key(const std::string &key, int default_value);
130 
131  typedef std::map<std::string, std::vector<std::string> >::const_iterator Keys_citer;
132 
133  Keys_citer keys_begin()
134  {
135  return _the_keys->begin();
136  }
137 
138  Keys_citer keys_end()
139  {
140  return _the_keys->end();
141  }
142 
143  virtual void dump(std::ostream &strm) const;
144 
149  static std::string ConfigFile;
150 
154  static TheBESKeys *TheKeys();
155 };
156 
157 #endif // TheBESKeys_h_
158 
TheBESKeys::ConfigFile
static std::string ConfigFile
Definition: TheBESKeys.h:149
TheBESKeys::read_string_key
std::string read_string_key(const std::string &key, const std::string &default_value)
Read a string-valued key from the bes.conf file.
Definition: TheBESKeys.cc:351
TheBESKeys::read_bool_key
bool read_bool_key(const std::string &key, bool default_value)
Read a boolean-valued key from the bes.conf file.
Definition: TheBESKeys.cc:326
TheBESKeys::TheKeys
static TheBESKeys * TheKeys()
Definition: TheBESKeys.cc:62
TheBESKeys
mapping of key/value pairs defining different behaviors of an application.
Definition: TheBESKeys.h:80
BESObj
top level BES object to house generic methods
Definition: BESObj.h:49
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
TheBESKeys::get_values
void get_values(const std::string &s, std::vector< std::string > &vals, bool &found)
Retrieve the values of a given key, if set.
Definition: TheBESKeys.cc:303
TheBESKeys::set_key
void set_key(const std::string &key, const std::string &val, bool addto=false)
allows the user to set key/value pairs from within the application.
Definition: TheBESKeys.cc:224
TheBESKeys::~TheBESKeys
virtual ~TheBESKeys()
cleans up the key/value pair mapping
Definition: TheBESKeys.cc:128
TheBESKeys::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: TheBESKeys.cc:402
TheBESKeys::read_int_key
int read_int_key(const std::string &key, int default_value)
Read an integer-valued key from the bes.conf file.
Definition: TheBESKeys.cc:376