ConfigParser.h
1 /**************************************************************************************
2 Copyright 2015 Applied Research Associates, Inc.
3 Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 this file except in compliance with the License. You may obtain a copy of the License
5 at:
6 http://www.apache.org/licenses/LICENSE-2.0
7 Unless required by applicable law or agreed to in writing, software distributed under
8 the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
9 CONDITIONS OF ANY KIND, either express or implied. See the License for the
10 specific language governing permissions and limitations under the License.
11 **************************************************************************************/
12 #pragma once
13 
14 #include <biogears/cdm/CommonDataModel.h>
15 
16 #include <map>
17 #include <string>
18 #include <vector>
19 
20 namespace biogears {
21 class BIOGEARS_API ConfigSet {
22 public:
23  void SetKeyValues(const std::map<std::string, std::string>& keyValues);
24  void AddKeyValue(const std::string& key, const std::string& value);
25  const std::map<std::string, std::string>& GetKeyValues() const { return m_keyValues; }
26 
27  bool HasKey(const std::string& key) const;
28  std::string GetValue(const std::string& key) const;
29  const char* GetValue(const char* key) const;
30 private:
31  std::map<std::string, std::string> m_keyValues;
32 };
33 
34 class BIOGEARS_API ConfigParser {
35 public:
36  ConfigParser(const std::string& configFilePath);
37 
38  const std::vector<ConfigSet>& GetConfigSets() const { return m_configSets; }
39 
40 private:
41  void ParseConfigFile(const std::string& configFile);
42  std::tuple<std::string, std::string> ParseKeyValue(const std::string& line);
43 
44  std::map<std::string, std::string> m_globalKeyValues;
45  std::vector<ConfigSet> m_configSets;
46 
47  bool m_parsingGlobalKeyValues = true;
48 };
49 }
std::vector< ConfigSet > m_configSets
Definition: ConfigParser.h:45
const std::map< std::string, std::string > & GetKeyValues() const
Definition: ConfigParser.h:25
Definition: ConfigParser.h:34
Definition: ConfigParser.h:21
std::map< std::string, std::string > m_globalKeyValues
Definition: ConfigParser.h:44
std::map< std::string, std::string > m_keyValues
Definition: ConfigParser.h:31
Definition: SEElectricalCircuit.h:18
const std::vector< ConfigSet > & GetConfigSets() const
Definition: ConfigParser.h:38