]> git.draconx.ca Git - upkg.git/blob - src/uobject/uobject.h
uobject: First stab at a generic logging mechanism.
[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         struct upkg *pkg;
45         struct upkg_file *pkg_file;
46 };
47
48 struct UObjectClass {
49         GObjectClass parent;
50
51         int (*deserialize)(UObject *obj);
52 };
53
54 GType u_object_get_type(void);
55
56 int u_object_deserialize(GObject *obj, struct upkg *pkg, unsigned long idx);
57
58 GObject *u_object_new_from_package(struct upkg *pkg, unsigned long idx);
59
60 /* Logging helpers for UObject class implementations. */
61 void u_vlog_full(GObject *o, GLogLevelFlags level, const char *fmt, va_list ap);
62 void u_log_full(GObject *o, GLogLevelFlags level, const char *fmt, ...);
63
64 #define u_log(uo, ...)  u_log_full(G_OBJECT(uo), G_LOG_LEVEL_MESSAGE, __VA_ARGS__)
65 #define u_warn(uo, ...) u_log_full(G_OBJECT(uo), G_LOG_LEVEL_WARNING, __VA_ARGS__)
66 #define u_err(uo, ...)  u_log_full(G_OBJECT(uo), G_LOG_LEVEL_CRITICAL, __VA_ARGS__)
67
68 #endif