AOSharedServiceLibrary
properties_reader.h
1 /*
2 MIT License Block
3 
4 Copyright (c) 2016 Alex Barry
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12 
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 THE SOFTWARE.
23 */
24 
25 #include <sys/stat.h>
26 #include <unordered_map>
27 #include <string>
28 #include <iterator>
29 #include <sstream>
30 #include <fstream>
31 #include <vector>
32 
33 #include "aossl/core/include/kv_store.h"
34 
35 #ifndef AOSSL_PROPERTIES_INCLUDE_PROPERTIES_READER_H_
36 #define AOSSL_PROPERTIES_INCLUDE_PROPERTIES_READER_H_
37 
38 namespace AOSSL {
39 
41  std::string config_file;
42 
43  public:
44  // Create a new Command Line Interpreter
45  // Here we create a new interpreter by passing in a single argument, the
46  // address of a properties file.
47  explicit PropertiesReader(std::string& file_path) : KeyValueStore() {
48  std::string line;
49  std::ifstream file(file_path.c_str());
50 
51  if (file.is_open()) {
52  while (getline(file, line)) {
53  // Read a line from the property file
54 
55  // Figure out if we have a blank or comment line
56  if (line.length() > 0) {
57  if (!(line[0] == '/' && line[1] == '/')) {
58  std::size_t eq_pos = line.find("=", 0);
59  if (eq_pos != std::string::npos) {
60  std::string var_name = line.substr(0, eq_pos);
61  std::string var_value = \
62  line.substr(eq_pos+1, line.length() - eq_pos);
63  KeyValueStore::set_opt(var_name, var_value);
64  }
65  }
66  }
67  }
68  file.close();
69  }
70  }
71 
72  ~PropertiesReader() {}
73 
74  void load_config() {}
75 };
76 
77 } // namespace AOSSL
78 
79 #endif // AOSSL_PROPERTIES_INCLUDE_PROPERTIES_READER_H_
void load_config()
Re-load configuration.
Definition: properties_reader.h:74
Key Value Store.
Definition: kv_store.h:42
void set_opt(std::string &key, std::string &value)
Set an option.
Definition: kv_store.h:83
Definition: properties_reader.h:40
Definition: cli.h:35