2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
32 #define BOF_TYPE_STRING 0
33 #define BOF_TYPE_NULL 1
34 #define BOF_TYPE_BLOB 2
35 #define BOF_TYPE_OBJECT 3
36 #define BOF_TYPE_ARRAY 4
37 #define BOF_TYPE_INT32 5
54 extern int bof_file_flush(bof_t
*root
);
55 extern bof_t
*bof_file_new(const char *filename
);
56 extern int bof_object_dump(bof_t
*object
, const char *filename
);
59 extern bof_t
*bof_object(void);
60 extern bof_t
*bof_object_get(bof_t
*object
, const char *keyname
);
61 extern int bof_object_set(bof_t
*object
, const char *keyname
, bof_t
*value
);
63 extern bof_t
*bof_array(void);
64 extern int bof_array_append(bof_t
*array
, bof_t
*value
);
65 extern bof_t
*bof_array_get(bof_t
*bof
, unsigned i
);
66 extern unsigned bof_array_size(bof_t
*bof
);
68 extern bof_t
*bof_blob(unsigned size
, void *value
);
69 extern unsigned bof_blob_size(bof_t
*bof
);
70 extern void *bof_blob_value(bof_t
*bof
);
72 extern bof_t
*bof_string(const char *value
);
74 extern bof_t
*bof_int32(int32_t value
);
75 extern int32_t bof_int32_value(bof_t
*bof
);
76 /* common functions */
77 extern void bof_decref(bof_t
*bof
);
78 extern void bof_incref(bof_t
*bof
);
79 extern bof_t
*bof_load_file(const char *filename
);
80 extern int bof_dump_file(bof_t
*bof
, const char *filename
);
81 extern void bof_print(bof_t
*bof
);
83 static inline int bof_is_object(bof_t
*bof
){return (bof
->type
== BOF_TYPE_OBJECT
);}
84 static inline int bof_is_blob(bof_t
*bof
){return (bof
->type
== BOF_TYPE_BLOB
);}
85 static inline int bof_is_null(bof_t
*bof
){return (bof
->type
== BOF_TYPE_NULL
);}
86 static inline int bof_is_int32(bof_t
*bof
){return (bof
->type
== BOF_TYPE_INT32
);}
87 static inline int bof_is_array(bof_t
*bof
){return (bof
->type
== BOF_TYPE_ARRAY
);}
88 static inline int bof_is_string(bof_t
*bof
){return (bof
->type
== BOF_TYPE_STRING
);}