GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_data_storage.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later
2/*
3 * Copyright (C) 2009-2025 Cyril Hrubis <metan@ucw.cz>
4 */
5
11#ifndef LOADERS_DATA_STORAGE_H
12#define LOADERS_DATA_STORAGE_H
13
29
35 long num;
37 long den;
38};
39
40typedef struct gp_storage gp_storage;
41typedef struct gp_data_dict gp_data_dict;
42
43union gp_data_value {
44 long i;
45 double d;
46 const char *str;
47 struct gp_data_rational rat;
48 gp_data_dict *dict;
49};
50
54typedef struct gp_data_node {
58 union gp_data_value value;
60 const char *id;
61 struct gp_data_node *next;
63
69gp_storage *gp_storage_create(void);
70
76void gp_storage_destroy(gp_storage *self);
77
87gp_data_node *gp_storage_root(gp_storage *self);
88
89/*
90 * Returns first node in a dict node list.
91 */
92gp_data_node *gp_data_dict_first(gp_data_node *node);
93
102void gp_storage_clear(gp_storage *self);
103
109void gp_data_print(const gp_data_node *node);
110
116static inline void gp_storage_print(gp_storage *self)
117{
119}
120
129
130/*
131 * Returns subnode of a given id (or NULL) starting at node.
132 *
133 * If node is NULL storage root is used.
134 */
135gp_data_node *gp_storage_get(gp_storage *self,
136 gp_data_node *node, const char *id);
137
138/*
139 * Returns data node by a path in the data storage.
140 *
141 * Example path: "/Exif/Orientation"
142 *
143 * The path works like filesystem path. The equivalent to working
144 * directory is the node pointer.
145 */
146gp_data_node *gp_storage_get_by_path(gp_storage *self, gp_data_node *node,
147 const char *path);
148
149/*
150 * Adds data into a dict.
151 *
152 * If node is NULL, data storage root is used.
153 *
154 * The data holds information to be used for the node addition.
155 *
156 * Returns newly created node or NULL in case of failure.
157 */
158gp_data_node *gp_storage_add(gp_storage *self,
159 gp_data_node *node, gp_data_node *data);
160
173 const char *id, long i);
174
187 const char *id, const char *str);
188
201 const char *id, double d);
202
216 const char *id, long num, long den);
217
229 const char *id);
230
231#endif /* LOADERS_GP_DATA_STORAGE_H */
gp_data_node * gp_storage_add_string(gp_storage *self, gp_data_node *node, const char *id, const char *str)
Adds a string to a storage.
const char * gp_data_type_name(enum gp_data_type type)
Returns a data type name.
static void gp_storage_print(gp_storage *self)
Prints a content of a storage into the stdout.
void gp_data_print(const gp_data_node *node)
Prints a data node into a stdout.
gp_data_node * gp_storage_add_rational(gp_storage *self, gp_data_node *node, const char *id, long num, long den)
Adds a rational number to a storage.
void gp_storage_clear(gp_storage *self)
Clears all data in storage.
struct gp_data_node gp_data_node
A data node.
gp_data_node * gp_storage_root(gp_storage *self)
Returns storage root node.
gp_storage * gp_storage_create(void)
Creates an empty data storage.
void gp_storage_destroy(gp_storage *self)
Destroys a data storage and frees all its data.
gp_data_node * gp_storage_add_dict(gp_storage *self, gp_data_node *node, const char *id)
Adds a dictionary to a storage.
gp_data_type
Data type.
@ GP_DATA_RATIONAL
A rational number.
@ GP_DATA_INT
A long integer.
@ GP_DATA_DOUBLE
A double.
@ GP_DATA_DICT
A dictionary aka hash.
@ GP_DATA_STRING
A string.
gp_data_node * gp_storage_add_double(gp_storage *self, gp_data_node *node, const char *id, double d)
Adds a double floating point to a storage.
gp_data_node * gp_storage_add_int(gp_storage *self, gp_data_node *node, const char *id, long i)
Adds a long integer to a storage.
A data node.
enum gp_data_type type
A data type.
union gp_data_value value
A data value.
const char * id
A data id.
Rational number.
long num
Numerator.
long den
Denominator.