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