replaced TomlTable with HashMap
This commit is contained in:
@@ -11,9 +11,10 @@ extern "C" {
|
||||
#include <time.h>
|
||||
#include "tlibc/std.h"
|
||||
#include "tlibc/string/str.h"
|
||||
#include "tlibc/string/StringBuilder.h"
|
||||
#include "tlibc/collections/HashMap.h"
|
||||
|
||||
typedef struct tm TomlDateTime;
|
||||
typedef HashMap(TomlValue) TomlTable;
|
||||
|
||||
typedef enum {
|
||||
TOML_OK,
|
||||
@@ -29,28 +30,17 @@ typedef struct {
|
||||
NULLABLE(char*) message;
|
||||
} TomlErr;
|
||||
|
||||
typedef struct _TomlValue TomlValue;
|
||||
typedef struct TomlValue TomlValue;
|
||||
|
||||
typedef struct {
|
||||
TomlValue** elements;
|
||||
TomlValue* elements;
|
||||
u64 len;
|
||||
u64 _capacity;
|
||||
} TomlArray;
|
||||
|
||||
typedef struct _TomlKeyValue TomlKeyValue;
|
||||
|
||||
typedef struct {
|
||||
u64 _capacity;
|
||||
u64 len;
|
||||
TomlKeyValue* _keyvals;
|
||||
} TomlTable;
|
||||
|
||||
typedef struct {
|
||||
TomlTable* _table;
|
||||
TomlKeyValue* _keyval;
|
||||
} TomlTableIter;
|
||||
|
||||
typedef enum {
|
||||
TOML_INVALID_TYPE,
|
||||
TOML_TABLE,
|
||||
TOML_ARRAY,
|
||||
TOML_STRING,
|
||||
@@ -60,7 +50,7 @@ typedef enum {
|
||||
TOML_BOOLEAN,
|
||||
} TomlType;
|
||||
|
||||
struct _TomlValue {
|
||||
struct TomlValue {
|
||||
TomlType type;
|
||||
union {
|
||||
TomlTable* table;
|
||||
@@ -68,16 +58,11 @@ struct _TomlValue {
|
||||
str s;
|
||||
i64 i;
|
||||
f64 f;
|
||||
TomlDateTime dt;
|
||||
TomlDateTime* dt;
|
||||
bool b;
|
||||
} value;
|
||||
};
|
||||
|
||||
struct _TomlKeyValue {
|
||||
str key;
|
||||
TomlValue* value;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
void* (*malloc)(void* context, u64 size);
|
||||
void* (*realloc)(void* context, void* p, u64 size);
|
||||
@@ -97,35 +82,30 @@ void toml_err_clear(void);
|
||||
TomlTable* toml_table_new(void);
|
||||
void toml_table_free(TomlTable* self);
|
||||
|
||||
void toml_table_set(TomlTable* self, str key, TomlValue* value);
|
||||
void toml_table_set(TomlTable* self, str key, TomlValue value);
|
||||
TomlValue* toml_table_get(const TomlTable* self, str key);
|
||||
TomlTable* toml_table_get_table(const TomlTable* self, str key);
|
||||
TomlArray* toml_table_get_array(const TomlTable* self, str key);
|
||||
str toml_table_get_str(const TomlTable* self, str key);
|
||||
i64 toml_table_get_integer(const TomlTable* self, str key);
|
||||
f64 toml_table_get_float(const TomlTable* self, str key);
|
||||
const TomlDateTime* toml_table_get_datetime(const TomlTable* self, str key);
|
||||
TomlDateTime* toml_table_get_datetime(const TomlTable* self, str key);
|
||||
bool toml_table_get_bool(const TomlTable* self, str key);
|
||||
|
||||
TomlTableIter toml_table_iter_new(TomlTable* table);
|
||||
TomlKeyValue* toml_table_iter_get(TomlTableIter* self);
|
||||
i32 toml_table_iter_has_next(TomlTableIter* self);
|
||||
void toml_table_iter_next(TomlTableIter* self);
|
||||
|
||||
TomlArray* toml_array_new(void);
|
||||
void toml_array_free(TomlArray* self);
|
||||
void toml_array_append(TomlArray* self, TomlValue* value);
|
||||
void toml_array_append(TomlArray* self, TomlValue value);
|
||||
|
||||
TomlValue* toml_value_new(TomlType type);
|
||||
TomlValue* toml_value_new_string(TomlType type);
|
||||
TomlValue* toml_value_new_table(void);
|
||||
TomlValue* toml_value_new_array(void);
|
||||
TomlValue* toml_value_new_integer(i64 integer);
|
||||
TomlValue* toml_value_new_float(f64 flt);
|
||||
TomlValue* toml_value_new_datetime(void);
|
||||
TomlValue* toml_value_new_bool(bool b);
|
||||
TomlValue* toml_value_from_str(str s);
|
||||
void toml_value_free(TomlValue* self);
|
||||
TomlValue TomlValue_new(TomlType type);
|
||||
TomlValue TomlValue_new_string(TomlType type);
|
||||
TomlValue TomlValue_new_table(void);
|
||||
TomlValue TomlValue_new_array(void);
|
||||
TomlValue TomlValue_new_integer(i64 integer);
|
||||
TomlValue TomlValue_new_float(f64 flt);
|
||||
TomlValue TomlValue_new_datetime(void);
|
||||
TomlValue TomlValue_new_bool(bool b);
|
||||
TomlValue TomlValue_from_str(str s);
|
||||
void TomlValue_destroy(TomlValue* self);
|
||||
|
||||
TomlTable* toml_load_str(str s);
|
||||
TomlTable* toml_load_file(FILE* file);
|
||||
|
||||
Reference in New Issue
Block a user