2015-08-16 21:35:13 +00:00
|
|
|
#pragma once
|
2021-05-31 17:44:55 +00:00
|
|
|
|
|
|
|
#include <cstdio>
|
2015-08-18 17:36:19 +00:00
|
|
|
#include <map>
|
2021-05-31 17:44:55 +00:00
|
|
|
#include <string>
|
2015-08-16 21:35:13 +00:00
|
|
|
|
2019-03-23 19:56:01 +00:00
|
|
|
namespace emucfg {
|
|
|
|
|
2015-08-18 17:36:19 +00:00
|
|
|
struct ConfigEntry {
|
2019-02-16 13:25:54 +00:00
|
|
|
std::string value;
|
2019-09-30 13:33:19 +00:00
|
|
|
const std::string& get_string() const;
|
2015-08-18 17:36:19 +00:00
|
|
|
int get_int();
|
|
|
|
bool get_bool();
|
2022-05-05 16:01:05 +00:00
|
|
|
int64_t get_int64();
|
2015-08-16 21:35:13 +00:00
|
|
|
};
|
|
|
|
|
2015-08-18 17:36:19 +00:00
|
|
|
struct ConfigSection {
|
2019-02-16 13:25:54 +00:00
|
|
|
std::map<std::string, ConfigEntry> entries;
|
|
|
|
bool has_entry(const std::string& name);
|
|
|
|
void set(const std::string& name, const std::string& value);
|
|
|
|
void delete_entry(const std::string& name);
|
|
|
|
ConfigEntry* get_entry(const std::string& name);
|
2015-08-16 21:35:13 +00:00
|
|
|
};
|
|
|
|
|
2015-08-18 17:36:19 +00:00
|
|
|
struct ConfigFile {
|
|
|
|
private:
|
2019-02-16 13:25:54 +00:00
|
|
|
std::map<std::string, ConfigSection> sections;
|
|
|
|
std::map<std::string, ConfigSection> virtual_sections;
|
|
|
|
ConfigSection* add_section(const std::string& name, bool is_virtual);
|
|
|
|
ConfigSection* get_section(const std::string& name, bool is_virtual);
|
|
|
|
ConfigEntry* get_entry(const std::string& section_name, const std::string& entry_name);
|
2015-08-18 17:36:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
public:
|
2019-02-16 13:25:54 +00:00
|
|
|
bool has_section(const std::string& name);
|
|
|
|
bool has_entry(const std::string& section_name, const std::string& entry_name);
|
2021-03-01 09:13:40 +00:00
|
|
|
bool is_virtual(const std::string& section_name, const std::string& entry_name);
|
2015-08-18 17:36:19 +00:00
|
|
|
|
2021-03-14 19:17:37 +00:00
|
|
|
void parse(FILE* file);
|
|
|
|
void save(FILE* file);
|
2015-08-18 17:36:19 +00:00
|
|
|
|
|
|
|
/* getting values */
|
2020-03-29 17:29:14 +00:00
|
|
|
std::string get(const std::string& section_name, const std::string& entry_name, const std::string& default_value = "");
|
2019-02-16 13:25:54 +00:00
|
|
|
int get_int(const std::string& section_name, const std::string& entry_name, int default_value = 0);
|
2022-05-05 16:01:05 +00:00
|
|
|
int64_t get_int64(const std::string& section_name, const std::string& entry_name, int64_t default_value = 0);
|
2019-02-16 13:25:54 +00:00
|
|
|
bool get_bool(const std::string& section_name, const std::string& entry_name, bool default_value = false);
|
2015-08-18 17:36:19 +00:00
|
|
|
/* setting values */
|
2019-02-16 13:25:54 +00:00
|
|
|
void set(const std::string& section_name, const std::string& entry_name, const std::string& value, bool is_virtual = false);
|
|
|
|
void set_int(const std::string& section_name, const std::string& entry_name, int value, bool is_virtual = false);
|
2022-05-05 16:01:05 +00:00
|
|
|
void set_int64(const std::string& section_name, const std::string& entry_name, int64_t value, bool is_virtual = false);
|
2019-02-16 13:25:54 +00:00
|
|
|
void set_bool(const std::string& section_name, const std::string& entry_name, bool value, bool is_virtual = false);
|
|
|
|
|
|
|
|
void delete_section(const std::string& section_name);
|
|
|
|
void delete_entry(const std::string& section_name, const std::string& entry_name);
|
2015-08-18 17:36:19 +00:00
|
|
|
};
|
2019-03-23 19:56:01 +00:00
|
|
|
|
|
|
|
} // namespace emucfg
|
|
|
|
|