Back to index

libdrm  2.4.37
bof.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a
00005  * copy of this software and associated documentation files (the "Software"),
00006  * to deal in the Software without restriction, including without limitation
00007  * on the rights to use, copy, modify, merge, publish, distribute, sub
00008  * license, and/or sell copies of the Software, and to permit persons to whom
00009  * the Software is furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice (including the next
00012  * paragraph) shall be included in all copies or substantial portions of the
00013  * Software.
00014  *
00015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
00018  * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
00019  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
00020  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
00021  * USE OR OTHER DEALINGS IN THE SOFTWARE.
00022  *
00023  * Authors:
00024  *      Jerome Glisse
00025  */
00026 #ifndef BOF_H
00027 #define BOF_H
00028 
00029 #include <stdio.h>
00030 #include <stdint.h>
00031 
00032 #define BOF_TYPE_STRING            0
00033 #define BOF_TYPE_NULL              1
00034 #define BOF_TYPE_BLOB              2
00035 #define BOF_TYPE_OBJECT            3
00036 #define BOF_TYPE_ARRAY             4
00037 #define BOF_TYPE_INT32             5
00038 
00039 struct bof;
00040 
00041 typedef struct bof {
00042        struct bof    **array;
00043        unsigned      centry;
00044        unsigned      nentry;
00045        unsigned      refcount;
00046        FILE          *file;
00047        uint32_t      type;
00048        uint32_t      size;
00049        uint32_t      array_size;
00050        void          *value;
00051        long          offset;
00052 } bof_t;
00053 
00054 extern int bof_file_flush(bof_t *root);
00055 extern bof_t *bof_file_new(const char *filename);
00056 extern int bof_object_dump(bof_t *object, const char *filename);
00057 
00058 /* object */
00059 extern bof_t *bof_object(void);
00060 extern bof_t *bof_object_get(bof_t *object, const char *keyname);
00061 extern int bof_object_set(bof_t *object, const char *keyname, bof_t *value);
00062 /* array */
00063 extern bof_t *bof_array(void);
00064 extern int bof_array_append(bof_t *array, bof_t *value);
00065 extern bof_t *bof_array_get(bof_t *bof, unsigned i);
00066 extern unsigned bof_array_size(bof_t *bof);
00067 /* blob */
00068 extern bof_t *bof_blob(unsigned size, void *value);
00069 extern unsigned bof_blob_size(bof_t *bof);
00070 extern void *bof_blob_value(bof_t *bof);
00071 /* string */
00072 extern bof_t *bof_string(const char *value);
00073 /* int32 */
00074 extern bof_t *bof_int32(int32_t value);
00075 extern int32_t bof_int32_value(bof_t *bof);
00076 /* common functions */
00077 extern void bof_decref(bof_t *bof);
00078 extern void bof_incref(bof_t *bof);
00079 extern bof_t *bof_load_file(const char *filename);
00080 extern int bof_dump_file(bof_t *bof, const char *filename);
00081 extern void bof_print(bof_t *bof);
00082 
00083 static inline int bof_is_object(bof_t *bof){return (bof->type == BOF_TYPE_OBJECT);}
00084 static inline int bof_is_blob(bof_t *bof){return (bof->type == BOF_TYPE_BLOB);}
00085 static inline int bof_is_null(bof_t *bof){return (bof->type == BOF_TYPE_NULL);}
00086 static inline int bof_is_int32(bof_t *bof){return (bof->type == BOF_TYPE_INT32);}
00087 static inline int bof_is_array(bof_t *bof){return (bof->type == BOF_TYPE_ARRAY);}
00088 static inline int bof_is_string(bof_t *bof){return (bof->type == BOF_TYPE_STRING);}
00089 
00090 #endif