blob: 1cd8f7c2c687f4e743351534e3cb0328d1d7d1a2 [file] [log] [blame]
Nicolas Capens68a82382018-10-02 13:16:55 -04001// 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
Nicolas Capens157ba262019-12-10 17:49:14 -050023namespace sw {
24
25class Configurator
Nicolas Capens68a82382018-10-02 13:16:55 -040026{
Nicolas Capens157ba262019-12-10 17:49:14 -050027public:
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
46private:
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
Nicolas Capens68a82382018-10-02 13:16:55 -040056 {
Nicolas Capens68a82382018-10-02 13:16:55 -040057 std::vector<std::string> names;
Nicolas Capens157ba262019-12-10 17:49:14 -050058 std::vector<std::string> values;
Nicolas Capens68a82382018-10-02 13:16:55 -040059 };
Nicolas Capens157ba262019-12-10 17:49:14 -050060
61 std::vector<Section> sections;
62 std::vector<std::string> names;
63};
64
65} // namespace sw
Nicolas Capens68a82382018-10-02 13:16:55 -040066
Ben Clayton595d9112019-12-17 20:37:57 +000067#endif // sw_Configurator_hpp