blob: 6fd930cf98c27ebe8d640b2c70e634b934154f51 [file] [log] [blame]
Nicolas Capens0bac2852016-05-07 06:09:58 -04001// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
John Bauman66b8ab22014-05-06 15:57:45 -04002//
Nicolas Capens0bac2852016-05-07 06:09:58 -04003// 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
John Bauman66b8ab22014-05-06 15:57:45 -04006//
Nicolas Capens0bac2852016-05-07 06:09:58 -04007// http://www.apache.org/licenses/LICENSE-2.0
John Bauman66b8ab22014-05-06 15:57:45 -04008//
Nicolas Capens0bac2852016-05-07 06:09:58 -04009// 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.
John Bauman66b8ab22014-05-06 15:57:45 -040014
15#ifndef sw_Configurator_hpp
16#define sw_Configurator_hpp
17
18#include <string>
19#include <vector>
20
21#include <stdlib.h>
22
23namespace sw
24{
Nicolas Capens0bac2852016-05-07 06:09:58 -040025 class Configurator
John Bauman66b8ab22014-05-06 15:57:45 -040026 {
27 public:
28 Configurator(std::string iniPath = "");
29
30 ~Configurator();
31
Nicolas Capens0bac2852016-05-07 06:09:58 -040032 std::string getValue(std::string sectionName, std::string valueName, std::string defaultValue = "") const;
John Bauman66b8ab22014-05-06 15:57:45 -040033 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,
Nicolas Capens0bac2852016-05-07 06:09:58 -040037 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);
John Bauman66b8ab22014-05-06 15:57:45 -040041
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;
Nicolas Capens0bac2852016-05-07 06:09:58 -040058 std::vector<std::string> values;
John Bauman66b8ab22014-05-06 15:57:45 -040059 };
60
61 std::vector<Section> sections;
62 std::vector<std::string> names;
63 };
64}
65
66#endif // sw_Configurator_hpp