84 lines
2.2 KiB
C
84 lines
2.2 KiB
C
/* 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/. */
|
|
|
|
#include "toml_internal.h"
|
|
|
|
TomlTable* TomlTable_new(void)
|
|
{
|
|
TomlTable* table = (TomlTable*)malloc(sizeof(TomlTable));
|
|
HashMap_construct(table, TomlValue, (Destructor_t)TomlValue_destroy);
|
|
return table;
|
|
}
|
|
|
|
void TomlTable_free(TomlTable* self)
|
|
{
|
|
if(!self)
|
|
return;
|
|
HashMap_destroy(self);
|
|
free(self);
|
|
}
|
|
|
|
Result(TomlTable*) TomlTable_get_table(const TomlTable* self, str key)
|
|
{
|
|
Deferral(1);
|
|
TomlValue* v = TomlTable_get(self, key);
|
|
try_assert(v != NULL);
|
|
try_assert(v->type == TLIBTOML_TABLE);
|
|
Return RESULT_VALUE(p, v->value.table);
|
|
}
|
|
|
|
Result(TomlArray*) TomlTable_get_array(const TomlTable* self, str key)
|
|
{
|
|
Deferral(1);
|
|
TomlValue* v = TomlTable_get(self, key);
|
|
try_assert(v != NULL);
|
|
try_assert(v->type == TLIBTOML_ARRAY);
|
|
Return RESULT_VALUE(p, v->value.array);
|
|
}
|
|
|
|
Result(str*) TomlTable_get_str(const TomlTable* self, str key)
|
|
{
|
|
Deferral(1);
|
|
TomlValue* v = TomlTable_get(self, key);
|
|
try_assert(v != NULL);
|
|
try_assert(v->type == TLIBTOML_STRING);
|
|
Return RESULT_VALUE(p, v->value.s);
|
|
}
|
|
|
|
Result(i64) TomlTable_get_integer(const TomlTable* self, str key)
|
|
{
|
|
Deferral(1);
|
|
TomlValue* v = TomlTable_get(self, key);
|
|
try_assert(v != NULL);
|
|
try_assert(v->type == TLIBTOML_INTEGER);
|
|
Return RESULT_VALUE(i, v->value.i);
|
|
}
|
|
|
|
Result(f64) TomlTable_get_float(const TomlTable* self, str key)
|
|
{
|
|
Deferral(1);
|
|
TomlValue* v = TomlTable_get(self, key);
|
|
try_assert(v != NULL);
|
|
try_assert(v->type == TLIBTOML_FLOAT);
|
|
Return RESULT_VALUE(f, v->value.f);
|
|
}
|
|
|
|
Result(TomlDateTime*) TomlTable_get_datetime(const TomlTable* self, str key)
|
|
{
|
|
Deferral(1);
|
|
TomlValue* v = TomlTable_get(self, key);
|
|
try_assert(v != NULL);
|
|
try_assert(v->type == TLIBTOML_DATETIME);
|
|
Return RESULT_VALUE(p, v->value.dt);
|
|
}
|
|
|
|
Result(bool) TomlTable_get_bool(const TomlTable* self, str key)
|
|
{
|
|
Deferral(1);
|
|
TomlValue* v = TomlTable_get(self, key);
|
|
try_assert(v != NULL);
|
|
try_assert(v->type == TLIBTOML_BOOLEAN);
|
|
Return RESULT_VALUE(i, v->value.b);
|
|
}
|