]> git.draconx.ca Git - upkg.git/blob - src/uobject/uobject.h
Stop using gnulib's flexmember module.
[upkg.git] / src / uobject / uobject.h
1 /*
2  *  upkg: tool for manipulating Unreal Tournament packages.
3  *  Copyright © 2009-2011 Nick Bowler
4  *
5  *  This program is free software: you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation, either version 3 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #ifndef U_OBJECT_H_
20 #define U_OBJECT_H_
21
22 #include <glib-object.h>
23 #include <stdarg.h>
24 #include "upkg.h"
25
26 #define U_TYPE_OBJECT u_object_get_type()
27 #define U_OBJECT(obj) \
28         G_TYPE_CHECK_INSTANCE_CAST(obj, U_TYPE_OBJECT, UObject)
29 #define U_OBJECT_CLASS(class) \
30         G_TYPE_CHECK_CLASS_CAST(class, U_TYPE_OBJECT, UObjectClass)
31 #define IS_U_OBJECT(obj) \
32         G_TYPE_CHECK_INSTANCE_TYPE(obj, U_TYPE_OBJECT)
33 #define IS_U_OBJECT_CLASS(class) \
34         G_TYPE_CHECK_CLASS_TYPE(class, U_TYPE_OBJECT, UObjectClass)
35 #define U_OBJECT_GET_CLASS(obj) \
36         G_TYPE_INSTANCE_GET_CLASS(obj, U_TYPE_OBJECT, UObjectClass)
37
38 typedef struct UObject      UObject;
39 typedef struct UObjectClass UObjectClass;
40
41 struct UObject {
42         GObject parent;
43
44         GTypeModule *pkg;
45         struct upkg_file *pkg_file;
46         char *pkg_name;
47 };
48
49 struct UObjectClass {
50         GObjectClass parent;
51
52         int (*deserialize)(UObject *obj);
53 };
54
55 GType u_object_get_type(void);
56
57 int u_object_deserialize(GObject *obj, GTypeModule *pkg, unsigned long idx);
58
59 float u_unpack_binary32_le(const unsigned char *buf);
60
61 GObject *u_object_new_from_package(GTypeModule *pkg, unsigned long idx);
62
63 /* Resolve an object reference from one object to another. */
64 GObject *u_object_get_by_link(GObject *obj, long link);
65
66 /* Logging helpers for UObject class implementations. */
67 void u_vlog_full(GObject *o, GLogLevelFlags level, const char *fmt, va_list ap);
68 void u_log_full(GObject *o, GLogLevelFlags level, const char *fmt, ...);
69
70 #define u_log(uo, ...)  u_log_full(G_OBJECT(uo), G_LOG_LEVEL_MESSAGE, __VA_ARGS__)
71 #define u_warn(uo, ...) u_log_full(G_OBJECT(uo), G_LOG_LEVEL_WARNING, __VA_ARGS__)
72 #define u_err(uo, ...)  u_log_full(G_OBJECT(uo), G_LOG_LEVEL_CRITICAL, __VA_ARGS__)
73
74 #endif