Debian Codegraph @

src/cdogs/yajl_utils.h

raw symbols SCIP
1 /*
2 Copyright (c) 2013-2017, 2025 Cong Xu
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7
8 Redistributions of source code must retain the above copyright notice, this
9 list of conditions and the following disclaimer.
10 Redistributions in binary form must reproduce the above copyright notice,
11 this list of conditions and the following disclaimer in the documentation
12 and/or other materials provided with the distribution.
13
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 POSSIBILITY OF SUCH DAMAGE.
25 */
26 #pragma once
27
28 #include <stdbool.h>
29
30 #include "vector.h"
31 #include "yajl/api/yajl_gen.h"
32 #include "yajl/api/yajl_tree.h"
33
34 yajl_val YAJLReadFile(const char *filename);
35 yajl_gen_status YAJLAddIntPair(yajl_gen g, const char *name, const int number);
36 yajl_gen_status YAJLAddBoolPair(
37 yajl_gen g, const char *name, const bool value);
38 yajl_gen_status YAJLAddStringPair(yajl_gen g, const char *name, const char *s);
39 yajl_gen_status YAJLAddColorPair(
40 yajl_gen g, const char *name, const color_t c);
41 void YAJLBool(bool *value, yajl_val node, const char *name);
42 void YAJLInt(int *value, yajl_val node, const char *name);
43 void YAJLDouble(double *value, yajl_val node, const char *name);
44 void YAJLVec2i(struct vec2i *value, yajl_val node, const char *name);
45 #define YAJL_GET_VEC2I(v) \
46 svec2i( \
47 (int)YAJL_GET_INTEGER(YAJL_GET_ARRAY(v)->values[0]), \
48 (int)YAJL_GET_INTEGER(YAJL_GET_ARRAY(v)->values[1]))
49 // remember to free
50 void YAJLStr(char **value, yajl_val node, const char *name);
51 char *YAJLGetStr(yajl_val node, const char *name);
52 /*
53 void LoadSoundFromNode(Mix_Chunk **value, json_t *node, const char *name);
54 // Load a const Pic * based on a name
55 void LoadPic(const Pic **value, json_t *node, const char *name);
56 // Load an array of const WeaponClass *
57 void LoadBulletGuns(CArray *guns, json_t *node, const char *name);
58 */
59 void YAJLLoadColor(color_t *c, yajl_val node, const char *name);
60 // Try to load a JSON node using a slash-delimited "path"
61 // If at any point the path fails, NULL is returned.
62 yajl_val YAJLFindNode(yajl_val node, const char *path);
63 /*
64 #define JSON_UTILS_ADD_ENUM_PAIR(parent, name, value, func)\
65 json_insert_pair_into_object(\
66 (parent), (name), json_new_string(func(value)));
67 */
68 bool YAJLTryLoadValue(yajl_val *node, const char *name);
69 /*
70 #define JSON_UTILS_LOAD_ENUM(value, node, name, func)\
71 {\
72 json_t *_node = (node);\
73 if (TryLoadValue(&_node, (name)))\
74 {\
75 (value) = func(_node->text);\
76 }\
77 }
78 */
79
80 bool YAJLTrySaveJSONFile(yajl_gen g, const char *filename);