tblite
Light-weight tight-binding framework
Loading...
Searching...
No Matches
table.h
Go to the documentation of this file.
1/* This file is part of tblite.
2 * SPDX-Identifier: LGPL-3.0-or-later
3 *
4 * tblite is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * tblite is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with tblite. If not, see <https://www.gnu.org/licenses/>.
16**/
17
25
26#pragma once
27
28#include "tblite/macros.h"
29#include "tblite/error.h"
30
36typedef struct _tblite_table* tblite_table;
37
39typedef struct _tblite_array* tblite_array;
40
43 TBLITE_TABLE_VALUE_TYPE_NONE = 0,
44 TBLITE_TABLE_VALUE_TYPE_BOOL = 1,
45 TBLITE_TABLE_VALUE_TYPE_INT = 2,
46 TBLITE_TABLE_VALUE_TYPE_DOUBLE = 3,
47 TBLITE_TABLE_VALUE_TYPE_CHAR = 4,
48 TBLITE_TABLE_VALUE_TYPE_ARRAY = 5,
49 TBLITE_TABLE_VALUE_TYPE_TABLE = 6
50};
51
58
64
74 tblite_table table,
75 char key[],
76 double* value,
77 int n);
78
88 tblite_table table,
89 char key[],
90 int64_t* value,
91 int n);
92
102 tblite_table table,
103 char key[],
104 bool* value,
105 int n);
106
116 tblite_table table,
117 char key[],
118 char (* value)[],
119 int n);
120
129 tblite_table table,
130 char key[]);
131
135
139
143 tblite_array array,
144 double value);
145
149 tblite_array array,
150 int64_t value);
151
155 tblite_array array,
156 bool value);
157
161 tblite_array array,
162 char value[]);
163
167 tblite_array array);
168
172 tblite_array array,
173 int index);
174
178 tblite_array array,
179 int index,
180 double* value);
181
185 tblite_array array,
186 int index,
187 int64_t* value);
188
192 tblite_array array,
193 int index,
194 bool* value);
195
199 tblite_array array,
200 int index,
201 char value[],
202 int n);
203
207 tblite_table table,
208 char key[],
209 tblite_array array);
210
214 tblite_table table,
215 char key[]);
216
220 tblite_table table,
221 char key[],
222 bool* value);
223
227 tblite_table table,
228 char key[],
229 int64_t* value);
230
234 tblite_table table,
235 char key[],
236 double* value);
237
241 tblite_table table,
242 char key[],
243 char value[],
244 int n);
245
249 tblite_table table,
250 char key[]);
251
255 tblite_table table,
256 char key[]);
257
261 tblite_table table);
262
266 tblite_table table,
267 int index,
268 char key[],
269 int n);
270
278 tblite_table table,
279 char filename[]);
280
281/*
282 * Type generic macros
283 */
284
291#define tblite_table_set_value(error, table, key, value, ...) \
292 _Generic((value), \
293 double*: tblite_table_set_double, \
294 int64_t*: tblite_table_set_int64_t, \
295 bool*: tblite_table_set_bool, \
296 char(*)[]: tblite_table_set_char \
297 )((error), (table), (key), (value), __VA_ARGS__)
Provides a light-weight error handler for communicating with the library.
struct _tblite_error * tblite_error
Error instance.
Definition error.h:35
General macro definitions for the tblite C API bindings.
#define TBLITE_API_ENTRY
Definition macros.h:49
#define TBLITE_API_CALL
Definition macros.h:57
TBLITE_API_ENTRY void TBLITE_API_CALL tblite_delete_table(tblite_table *table)
TBLITE_API_ENTRY void TBLITE_API_CALL tblite_table_set_array(tblite_error error, tblite_table table, char key[], tblite_array array)
Set the value of a table entry to a data array.
TBLITE_API_ENTRY void TBLITE_API_CALL tblite_table_get_char(tblite_error error, tblite_table table, char key[], char value[], int n)
Return a scalar character value from a table entry.
struct _tblite_table * tblite_table
Definition table.h:36
TBLITE_API_ENTRY tblite_array TBLITE_API_CALL tblite_new_array(void)
Create new data array object.
TBLITE_API_ENTRY int TBLITE_API_CALL tblite_table_get_type(tblite_error error, tblite_table table, char key[])
Return the value kind of a table entry.
TBLITE_API_ENTRY void TBLITE_API_CALL tblite_delete_array(tblite_array *array)
Delete a data array object.
TBLITE_API_ENTRY void TBLITE_API_CALL tblite_table_set_int64_t(tblite_error error, tblite_table table, char key[], int64_t *value, int n)
TBLITE_API_ENTRY tblite_array TBLITE_API_CALL tblite_table_get_array(tblite_error error, tblite_table table, char key[])
Return an array value from a table entry.
TBLITE_API_ENTRY void TBLITE_API_CALL tblite_array_get_int64_t(tblite_error error, tblite_array array, int index, int64_t *value)
Return an array entry as an integer value.
TBLITE_API_ENTRY void TBLITE_API_CALL tblite_array_push_back_double(tblite_error error, tblite_array array, double value)
Append a double value to a data array.
TBLITE_API_ENTRY void TBLITE_API_CALL tblite_table_set_bool(tblite_error error, tblite_table table, char key[], bool *value, int n)
TBLITE_API_ENTRY void TBLITE_API_CALL tblite_array_push_back_bool(tblite_error error, tblite_array array, bool value)
Append a boolean value to a data array.
TBLITE_API_ENTRY void TBLITE_API_CALL tblite_dump_table(tblite_error error, tblite_table table, char filename[])
TBLITE_API_ENTRY void TBLITE_API_CALL tblite_array_push_back_char(tblite_error error, tblite_array array, char value[])
Append a character string to a data array.
TBLITE_API_ENTRY int TBLITE_API_CALL tblite_array_size(tblite_error error, tblite_array array)
Return the number of entries in a data array.
struct _tblite_array * tblite_array
Handle for holding an array data structure.
Definition table.h:39
TBLITE_API_ENTRY tblite_table TBLITE_API_CALL tblite_table_add_table(tblite_error error, tblite_table table, char key[])
TBLITE_API_ENTRY void TBLITE_API_CALL tblite_table_get_double(tblite_error error, tblite_table table, char key[], double *value)
Return a scalar floating point value from a table entry.
TBLITE_API_ENTRY void TBLITE_API_CALL tblite_table_get_bool(tblite_error error, tblite_table table, char key[], bool *value)
Return a scalar bool value from a table entry.
tblite_table_value_type
Supported value kinds for table entries.
Definition table.h:42
TBLITE_API_ENTRY int TBLITE_API_CALL tblite_table_get_n_keys(tblite_error error, tblite_table table)
Return the number of entries in a table.
TBLITE_API_ENTRY void TBLITE_API_CALL tblite_array_get_double(tblite_error error, tblite_array array, int index, double *value)
Return an array entry as a double value.
TBLITE_API_ENTRY int TBLITE_API_CALL tblite_array_get_type(tblite_error error, tblite_array array, int index)
Return the value kind of an array entry.
TBLITE_API_ENTRY void TBLITE_API_CALL tblite_table_get_int64_t(tblite_error error, tblite_table table, char key[], int64_t *value)
Return a scalar integer value from a table entry.
TBLITE_API_ENTRY tblite_table TBLITE_API_CALL tblite_table_get_table(tblite_error error, tblite_table table, char key[])
Return a child table from a table entry.
TBLITE_API_ENTRY void TBLITE_API_CALL tblite_array_push_back_int64_t(tblite_error error, tblite_array array, int64_t value)
Append an integer value to a data array.
TBLITE_API_ENTRY void TBLITE_API_CALL tblite_table_get_key(tblite_error error, tblite_table table, int index, char key[], int n)
Return the key of a table entry at the given index.
TBLITE_API_ENTRY void TBLITE_API_CALL tblite_array_get_char(tblite_error error, tblite_array array, int index, char value[], int n)
Return an array entry as a character string.
TBLITE_API_ENTRY void TBLITE_API_CALL tblite_table_set_double(tblite_error error, tblite_table table, char key[], double *value, int n)
TBLITE_API_ENTRY void TBLITE_API_CALL tblite_table_set_char(tblite_error error, tblite_table table, char key[], char(*value)[], int n)
TBLITE_API_ENTRY tblite_table TBLITE_API_CALL tblite_new_table(tblite_table *table)
TBLITE_API_ENTRY void TBLITE_API_CALL tblite_array_get_bool(tblite_error error, tblite_array array, int index, bool *value)
Return an array entry as a boolean value.