1d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman//
3d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// Licensed under the Apache License, Version 2.0 (the "License");
4d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// you may not use this file except in compliance with the License.
5d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// You may obtain a copy of the License at
666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman//
7d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens//    http://www.apache.org/licenses/LICENSE-2.0
866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman//
9d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// Unless required by applicable law or agreed to in writing, software
10d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// distributed under the License is distributed on an "AS IS" BASIS,
11d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// See the License for the specific language governing permissions and
13d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// limitations under the License.
1466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman
1566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#ifndef sw_Configurator_hpp
1666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#define sw_Configurator_hpp
1766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman
1866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include <string>
1966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include <vector>
2066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman
2166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include <stdlib.h>
2266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman
2366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Baumannamespace sw
2466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman{
25d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	class Configurator
2666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman	{
2766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman	public:
2866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		Configurator(std::string iniPath = "");
2966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman
3066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		~Configurator();
3166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman
32d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		std::string getValue(std::string sectionName, std::string valueName, std::string defaultValue = "") const;
3366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		int getInteger(std::string sectionName, std::string valueName, int defaultValue = 0) const;
3466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		bool getBoolean(std::string sectionName, std::string valueName, bool defaultValue = false) const;
3566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		double getFloat(std::string sectionName, std::string valueName, double defaultValue = 0.0) const;
3666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		unsigned int getFormatted(std::string sectionName, std::string valueName, char *format,
37d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		                          void *v1 = 0, void *v2 = 0, void *v3 = 0, void *v4 = 0,
38d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		                          void *v5 = 0, void *v6 = 0, void *v7 = 0, void *v8 = 0,
39d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		                          void *v9 = 0, void *v10 = 0, void *v11 = 0, void *v12 = 0,
40d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		                          void *v13 = 0, void *v14 = 0, void *v15 = 0, void *v16 = 0);
4166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman
4266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		void addValue(std::string sectionName, std::string valueName, std::string value);
4366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman
4466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		void writeFile(std::string title = "Configuration File");
4566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman
4666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman	private:
4766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		bool readFile();
4866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman
4966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		unsigned int addKeyName(std::string sectionName);
5066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		int findKey(std::string sectionName) const;
5166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		int findValue(unsigned int sectionID, std::string valueName) const;
5266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman
5366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		std::string path;
5466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman
5566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		struct Section
5666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		{
5766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			std::vector<std::string> names;
58d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens			std::vector<std::string> values;
5966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		};
6066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman
6166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		std::vector<Section> sections;
6266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		std::vector<std::string> names;
6366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman	};
6466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman}
6566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman
6666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#endif   // sw_Configurator_hpp
67