add array stuff

This commit is contained in:
Arisotura
2024-04-17 23:02:08 +02:00
parent 9283d1ae36
commit 92d1614b45
2 changed files with 187 additions and 69 deletions

View File

@ -26,7 +26,14 @@
#include <tuple>
//#define TOML_HEADER_ONLY 0
#include "toml/toml.hpp"
//#include "toml/toml.hpp"
#ifndef TOML11_VALUE_HPP
namespace toml
{
class value;
}
#endif
enum
{
@ -90,12 +97,51 @@ using DefaultList = std::unordered_map<std::string, T>;
using RangeList = std::unordered_map<std::string, std::tuple<int, int>>;
class Table;
class Array
{
public:
Array(toml::value& data);
~Array() {}
size_t Size();
Array GetArray(const int id);
int GetInt(const int id);
int64_t GetInt64(const int id);
bool GetBool(const int id);
std::string GetString(const int id);
void SetInt(const int id, int val);
void SetInt64(const int id, int64_t val);
void SetBool(const int id, bool val);
void SetString(const int id, const std::string& val);
// convenience
QString GetQString(const int id)
{
return QString::fromStdString(GetString(id));
}
void SetQString(const int id, const QString& val)
{
return SetString(id, val.toStdString());
}
private:
toml::value& Data;
};
class Table
{
public:
Table(toml::value& data, std::string path);
~Table() {}
Array GetArray(const std::string& path);
Table GetTable(const std::string& path);
int GetInt(const std::string& path);
@ -123,11 +169,6 @@ public:
private:
toml::value& Data;
std::string PathPrefix;
std::string DefaultPrefix;
int DefaultInt;
bool DefaultBool;
std::string DefaultString;
toml::value& ResolvePath(const std::string& path);
template<typename T> T FindDefault(const std::string& path, T def, DefaultList<T> list);
@ -269,8 +310,8 @@ extern bool GdbARM9BreakOnStartup;
bool Load();
void Save();
toml::value& GetLocalTable(int instance);
inline toml::value& GetGlobalTable() { return GetLocalTable(-1); }
Table GetLocalTable(int instance);
inline Table GetGlobalTable() { return GetLocalTable(-1); }
}