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