1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef sw_Configurator_hpp 16 #define sw_Configurator_hpp 17 18 #include <string> 19 #include <vector> 20 21 #include <stdlib.h> 22 23 namespace sw 24 { 25 class Configurator 26 { 27 public: 28 Configurator(std::string iniPath = ""); 29 30 ~Configurator(); 31 32 std::string getValue(std::string sectionName, std::string valueName, std::string defaultValue = "") const; 33 int getInteger(std::string sectionName, std::string valueName, int defaultValue = 0) const; 34 bool getBoolean(std::string sectionName, std::string valueName, bool defaultValue = false) const; 35 double getFloat(std::string sectionName, std::string valueName, double defaultValue = 0.0) const; 36 unsigned int getFormatted(std::string sectionName, std::string valueName, char *format, 37 void *v1 = 0, void *v2 = 0, void *v3 = 0, void *v4 = 0, 38 void *v5 = 0, void *v6 = 0, void *v7 = 0, void *v8 = 0, 39 void *v9 = 0, void *v10 = 0, void *v11 = 0, void *v12 = 0, 40 void *v13 = 0, void *v14 = 0, void *v15 = 0, void *v16 = 0); 41 42 void addValue(std::string sectionName, std::string valueName, std::string value); 43 44 void writeFile(std::string title = "Configuration File"); 45 46 private: 47 bool readFile(); 48 49 unsigned int addKeyName(std::string sectionName); 50 int findKey(std::string sectionName) const; 51 int findValue(unsigned int sectionID, std::string valueName) const; 52 53 std::string path; 54 55 struct Section 56 { 57 std::vector<std::string> names; 58 std::vector<std::string> values; 59 }; 60 61 std::vector<Section> sections; 62 std::vector<std::string> names; 63 }; 64 } 65 66 #endif // sw_Configurator_hpp 67