• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 /******************************************************************************
17  *
18  *  The original Work has been changed by NXP.
19  *
20  *  Copyright 2019,2023 NXP
21  *
22  *  Licensed under the Apache License, Version 2.0 (the "License");
23  *  you may not use this file except in compliance with the License.
24  *  You may obtain a copy of the License at
25  *
26  *  http://www.apache.org/licenses/LICENSE-2.0
27  *
28  *  Unless required by applicable law or agreed to in writing, software
29  *  distributed under the License is distributed on an "AS IS" BASIS,
30  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  *  See the License for the specific language governing permissions and
32  *  limitations under the License.
33  *
34  ******************************************************************************/
35 #pragma once
36 
37 #include <map>
38 #include <string>
39 #include <vector>
40 
41 class ConfigValue {
42  public:
43   enum Type { UNSIGNED, STRING, BYTES };
44 
45   ConfigValue();
46   Type getType() const;
47   std::string getString() const;
48   unsigned getUnsigned() const;
49   std::vector<uint8_t> getBytes() const;
50 
51   bool parseFromString(std::string in);
52 
53  private:
54   Type type_;
55   std::string value_string_;
56   unsigned value_unsigned_;
57   std::vector<uint8_t> value_bytes_;
58 };
59 
60 class ConfigFile {
61  public:
62   void parseFromFile(const std::string& file_name);
63   void parseFromString(const std::string& config);
64 
65   bool hasKey(const std::string& key);
66   std::string getString(const std::string& key);
67   unsigned getUnsigned(const std::string& key);
68 
69  private:
70   ConfigValue& getValue(const std::string& key);
71 
72   std::map<std::string, ConfigValue> values_;
73 };
74