Debian Codegraph @

src/engine/config.h

raw
1 /**
2 * Furnace Tracker - multi-system chiptune tracker
3 * Copyright (C) 2021-2025 tildearrow and contributors
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef _DIVCONFIG_H
21 #define _DIVCONFIG_H
22
23 #include "../ta-utils.h"
24 #include <initializer_list>
25
26 class DivConfig {
27 std::map<String,String> conf;
28 void parseLine(const char* line);
29 public:
30 // config loading/saving
31 bool loadFromMemory(const char* buf);
32 bool loadFromBase64(const char* buf);
33 bool loadFromFile(const char* path, bool createOnFail=true, bool redundancy=false);
34 String toString();
35 String toBase64();
36 bool save(const char* path, bool redundancy=false);
37
38 // get the map
39 const std::map<String,String>& configMap();
40
41 // get a config value
42 bool getBool(String key, bool fallback) const;
43 int getInt(String key, int fallback) const;
44 float getFloat(String key, float fallback) const;
45 double getDouble(String key, double fallback) const;
46 String getString(String key, String fallback) const;
47 std::vector<int> getIntList(String key, std::initializer_list<int> fallback) const;
48
49 // check for existence
50 bool has(String key) const;
51
52 // set a config value
53 void set(String key, bool value);
54 void set(String key, int value);
55 void set(String key, float value);
56 void set(String key, double value);
57 void set(String key, const char* value);
58 void set(String key, String value);
59 void set(String key, const std::vector<int>& value);
60
61 // remove a config value
62 bool remove(String key);
63
64 // clear config
65 void clear();
66 };
67
68 #endif