| 
									
										
										
										
											2022-09-29 02:24:26 -04:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Furnace Tracker - multi-system chiptune tracker | 
					
						
							| 
									
										
										
										
											2023-01-19 19:18:40 -05:00
										 |  |  |  * Copyright (C) 2021-2023 tildearrow and contributors | 
					
						
							| 
									
										
										
										
											2022-09-29 02:24:26 -04:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or modify | 
					
						
							|  |  |  |  * it under the terms of the GNU General Public License as published by | 
					
						
							|  |  |  |  * the Free Software Foundation; either version 2 of the License, or | 
					
						
							|  |  |  |  * (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License along | 
					
						
							|  |  |  |  * with this program; if not, write to the Free Software Foundation, Inc., | 
					
						
							|  |  |  |  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef _DIVCONFIG_H
 | 
					
						
							|  |  |  | #define _DIVCONFIG_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "../ta-utils.h"
 | 
					
						
							|  |  |  | #include <map>
 | 
					
						
							| 
									
										
										
										
											2023-04-02 18:32:21 -04:00
										 |  |  | #include <vector>
 | 
					
						
							|  |  |  | #include <initializer_list>
 | 
					
						
							| 
									
										
										
										
											2022-09-29 02:24:26 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | class DivConfig { | 
					
						
							|  |  |  |   std::map<String,String> conf; | 
					
						
							| 
									
										
										
										
											2022-09-29 04:19:48 -04:00
										 |  |  |   void parseLine(const char* line); | 
					
						
							| 
									
										
										
										
											2022-09-29 02:24:26 -04:00
										 |  |  |   public: | 
					
						
							|  |  |  |     // config loading/saving
 | 
					
						
							|  |  |  |     bool loadFromMemory(const char* buf); | 
					
						
							| 
									
										
										
										
											2022-09-29 21:13:40 -04:00
										 |  |  |     bool loadFromBase64(const char* buf); | 
					
						
							| 
									
										
										
										
											2023-04-05 05:44:21 -04:00
										 |  |  |     bool loadFromFile(const char* path, bool createOnFail=true, bool redundancy=false); | 
					
						
							| 
									
										
										
										
											2022-09-29 02:24:26 -04:00
										 |  |  |     String toString(); | 
					
						
							| 
									
										
										
										
											2022-09-29 21:13:40 -04:00
										 |  |  |     String toBase64(); | 
					
						
							| 
									
										
										
										
											2023-04-05 05:44:21 -04:00
										 |  |  |     bool save(const char* path, bool redundancy=false); | 
					
						
							| 
									
										
										
										
											2022-09-29 02:24:26 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-22 13:10:08 -05:00
										 |  |  |     // get the map
 | 
					
						
							|  |  |  |     const std::map<String,String>& configMap(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-29 02:24:26 -04:00
										 |  |  |     // get a config value
 | 
					
						
							| 
									
										
										
										
											2022-09-29 21:13:40 -04:00
										 |  |  |     bool getBool(String key, bool fallback) const; | 
					
						
							|  |  |  |     int getInt(String key, int fallback) const; | 
					
						
							|  |  |  |     float getFloat(String key, float fallback) const; | 
					
						
							|  |  |  |     double getDouble(String key, double fallback) const; | 
					
						
							|  |  |  |     String getString(String key, String fallback) const; | 
					
						
							| 
									
										
										
										
											2023-04-02 18:32:21 -04:00
										 |  |  |     std::vector<int> getIntList(String key, std::initializer_list<int> fallback) const; | 
					
						
							| 
									
										
										
										
											2022-09-29 02:24:26 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-22 13:10:08 -05:00
										 |  |  |     // check for existence
 | 
					
						
							| 
									
										
										
										
											2023-02-10 17:55:44 -05:00
										 |  |  |     bool has(String key) const; | 
					
						
							| 
									
										
										
										
											2022-12-22 13:10:08 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-29 02:24:26 -04:00
										 |  |  |     // set a config value
 | 
					
						
							| 
									
										
										
										
											2022-09-29 19:03:39 -04:00
										 |  |  |     void set(String key, bool value); | 
					
						
							|  |  |  |     void set(String key, int value); | 
					
						
							|  |  |  |     void set(String key, float value); | 
					
						
							|  |  |  |     void set(String key, double value); | 
					
						
							|  |  |  |     void set(String key, const char* value); | 
					
						
							|  |  |  |     void set(String key, String value); | 
					
						
							| 
									
										
										
										
											2023-04-02 18:32:21 -04:00
										 |  |  |     void set(String key, const std::vector<int>& value); | 
					
						
							| 
									
										
										
										
											2022-09-29 19:03:39 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // remove a config value
 | 
					
						
							|  |  |  |     bool remove(String key); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // clear config
 | 
					
						
							|  |  |  |     void clear(); | 
					
						
							| 
									
										
										
										
											2022-09-29 02:24:26 -04:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-29 19:03:39 -04:00
										 |  |  | #endif
 |