Skip to content
Flecs v4.1
world.inl
Go to the documentation of this file.
1/**
2 * @file addons/cpp/mixins/json/world.inl
3 * @brief JSON world mixin.
4 */
5
6/** Serialize an untyped value to JSON.
7 *
8 * @memberof flecs::world
9 * @ingroup cpp_addons_json
10 */
11flecs::string to_json(flecs::entity_t tid, const void* value) const {
12 char *json = ecs_ptr_to_json(world_, tid, value);
13 return flecs::string(json);
14}
15
16/** Serialize a value to JSON.
17 *
18 * @memberof flecs::world
19 * @ingroup cpp_addons_json
20 */
21template <typename T>
22flecs::string to_json(const T* value) const {
24 return to_json(tid, value);
25}
26
27/** Serialize the world to JSON.
28 *
29 * @memberof flecs::world
30 * @ingroup cpp_addons_json
31 */
33 return flecs::string( ecs_world_to_json(world_, nullptr) );
34}
35
36/** Deserialize a value from JSON.
37 *
38 * @memberof flecs::world
39 * @ingroup cpp_addons_json
40 */
41const char* from_json(flecs::entity_t tid, void* value, const char *json, flecs::from_json_desc_t *desc = nullptr) {
42 return ecs_ptr_from_json(world_, tid, value, json, desc);
43}
44
45/** Deserialize a value from JSON.
46 *
47 * @memberof flecs::world
48 * @ingroup cpp_addons_json
49 */
50template <typename T>
51const char* from_json(T* value, const char *json, flecs::from_json_desc_t *desc = nullptr) {
53 value, json, desc);
54}
55
56/** Deserialize JSON into the world.
57 *
58 * @memberof flecs::world
59 * @ingroup cpp_addons_json
60 */
61const char* from_json(const char *json, flecs::from_json_desc_t *desc = nullptr) {
62 return ecs_world_from_json(world_, json, desc);
63}
64
65/** Deserialize a JSON file into the world.
66 *
67 * @memberof flecs::world
68 * @ingroup cpp_addons_json
69 */
70const char* from_json_file(const char *json, flecs::from_json_desc_t *desc = nullptr) {
71 return ecs_world_from_json_file(world_, json, desc);
72}
FLECS_API const char * ecs_world_from_json(ecs_world_t *world, const char *json, const ecs_from_json_desc_t *desc)
Parse JSON object with multiple entities into the world.
FLECS_API const char * ecs_world_from_json_file(ecs_world_t *world, const char *filename, const ecs_from_json_desc_t *desc)
Same as ecs_world_from_json(), but loads JSON from a file.
FLECS_API char * ecs_ptr_to_json(const ecs_world_t *world, ecs_entity_t type, const void *data)
Serialize value into JSON string.
FLECS_API char * ecs_world_to_json(ecs_world_t *world, const ecs_world_to_json_desc_t *desc)
Serialize world into JSON string.
FLECS_API const char * ecs_ptr_from_json(const ecs_world_t *world, ecs_entity_t type, void *ptr, const char *json, const ecs_from_json_desc_t *desc)
Parse JSON string into value.
flecs::string to_json(flecs::entity_t tid, const void *value) const
Serialize an untyped value to JSON.
Definition world.hpp:12
ecs_entity_t entity_t
Entity type.
Definition c_types.hpp:21
Owned string wrapper.
Definition string.hpp:15
world_t * world_
Pointer to the underlying C world.
Definition world.hpp:1009
const char * from_json_file(const char *json, flecs::from_json_desc_t *desc=nullptr)
Deserialize a JSON file into the world.
Definition world.inl:70
const char * from_json(const char *json, flecs::from_json_desc_t *desc=nullptr)
Deserialize JSON into the world.
Definition world.inl:61
flecs::string to_json(const T *value) const
Serialize a value to JSON.
Definition world.inl:22
flecs::string to_json() const
Serialize the world to JSON.
Definition world.inl:32
const char * from_json(flecs::entity_t tid, void *value, const char *json, flecs::from_json_desc_t *desc=nullptr)
Deserialize a value from JSON.
Definition world.inl:41
const char * from_json(T *value, const char *json, flecs::from_json_desc_t *desc=nullptr)
Deserialize a value from JSON.
Definition world.inl:51
flecs::string to_json(flecs::entity_t tid, const void *value) const
Serialize an untyped value to JSON.
Definition world.inl:11