added tlibc error handling everywhere
This commit is contained in:
137
include/tlibtoml.h
Normal file
137
include/tlibtoml.h
Normal file
@@ -0,0 +1,137 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <time.h>
|
||||
#include "tlibc/tlibc.h"
|
||||
#include "tlibc/time.h"
|
||||
#include "tlibc/errors.h"
|
||||
#include "tlibc/string/str.h"
|
||||
#include "tlibc/collections/HashMap.h"
|
||||
|
||||
|
||||
Result(void) tlibtoml_init();
|
||||
void tlibtoml_deinit();
|
||||
|
||||
typedef DateTime TomlDateTime;
|
||||
typedef HashMap(TomlValue) TomlTable;
|
||||
|
||||
typedef enum TlibtomlError {
|
||||
TLIBTOML_OK,
|
||||
TLIBTOML_ERR,
|
||||
TLIBTOML_ERR_OS,
|
||||
TLIBTOML_ERR_NOMEM,
|
||||
TLIBTOML_ERR_SYNTAX,
|
||||
TLIBTOML_ERR_UNICODE
|
||||
} TlibtomlError;
|
||||
ErrorCodePage_declare(TLIBTOML);
|
||||
|
||||
typedef struct TomlValue TomlValue;
|
||||
|
||||
typedef struct TomlArray {
|
||||
TomlValue* elements;
|
||||
u64 len;
|
||||
u64 _capacity;
|
||||
} TomlArray;
|
||||
|
||||
|
||||
typedef enum {
|
||||
TLIBTOML_INVALID_TYPE,
|
||||
TLIBTOML_TABLE,
|
||||
TLIBTOML_ARRAY,
|
||||
TLIBTOML_STRING,
|
||||
TLIBTOML_INTEGER,
|
||||
TLIBTOML_FLOAT,
|
||||
TLIBTOML_DATETIME,
|
||||
TLIBTOML_BOOLEAN,
|
||||
} TomlType;
|
||||
|
||||
struct TomlValue {
|
||||
TomlType type;
|
||||
union {
|
||||
i64 i;
|
||||
f64 f;
|
||||
bool b;
|
||||
str* s;
|
||||
TomlArray* array;
|
||||
TomlTable* table;
|
||||
TomlDateTime* dt;
|
||||
} value;
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// toml.c //
|
||||
// //
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Result(TomlTable*) toml_load_str(str s);
|
||||
Result(TomlTable*) toml_load_file(FILE* file);
|
||||
Result(TomlTable*) toml_load_filename(cstr filename);
|
||||
|
||||
/* TODO: implement dump functions
|
||||
str toml_dump_str(const TomlTable* self, TomlErr *err);
|
||||
void toml_dump_file(const TomlTable* self, FILE* file, TomlErr *err);
|
||||
*/
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// TomlTable.c //
|
||||
// //
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TomlTable* TomlTable_new(void);
|
||||
void TomlTable_free(TomlTable* self);
|
||||
|
||||
void TomlTable_set(TomlTable* self, str key, TomlValue value);
|
||||
NULLABLE(TomlValue*) TomlTable_get(const TomlTable* self, str key);
|
||||
Result(TomlTable*) TomlTable_get_table(const TomlTable* self, str key);
|
||||
Result(TomlArray*) TomlTable_get_array(const TomlTable* self, str key);
|
||||
Result(str*) TomlTable_get_str(const TomlTable* self, str key);
|
||||
Result(i64) TomlTable_get_integer(const TomlTable* self, str key);
|
||||
Result(f64) TomlTable_get_float(const TomlTable* self, str key);
|
||||
Result(bool) TomlTable_get_bool(const TomlTable* self, str key);
|
||||
Result(TomlDateTime*) TomlTable_get_datetime(const TomlTable* self, str key);
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// TomlArray.c //
|
||||
// //
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TomlArray* TomlArray_new(void);
|
||||
void TomlArray_free(TomlArray* self);
|
||||
void TomlArray_append(TomlArray* self, TomlValue value);
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// TomlValue.c //
|
||||
// //
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TomlValue TomlValue_new(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);
|
||||
/// copies the string
|
||||
TomlValue TomlValue_copy_str(str s);
|
||||
/// doesnt copy the string
|
||||
TomlValue TomlValue_move_str(str s);
|
||||
void TomlValue_destroy(TomlValue* self);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user