Code

Use subdirectories with icon sizes.
[inkscape.git] / src / libnr / nr-object.h
1 #ifndef __NR_OBJECT_H__
2 #define __NR_OBJECT_H__
4 /*
5  * RGBA display list system for inkscape
6  *
7  * Authors:
8  *   Lauris Kaplinski <lauris@kaplinski.com>
9  *   MenTaLguY <mental@rydia.net>
10  *
11  * This code is in public domain
12  */
14 #if HAVE_CONFIG_H
15 #include "config.h"
16 #endif
18 #include <glib/gtypes.h>
19 #include "gc-managed.h"
20 #include "gc-finalized.h"
21 #include "gc-anchored.h"
23 typedef guint32 NRType;
25 struct NRObject;
26 struct NRObjectClass;
28 #define NR_TYPE_OBJECT (nr_object_get_type ())
29 #define NR_OBJECT(o) (NR_CHECK_INSTANCE_CAST ((o), NR_TYPE_OBJECT, NRObject))
30 #define NR_IS_OBJECT(o) (NR_CHECK_INSTANCE_TYPE ((o), NR_TYPE_OBJECT))
32 #define NR_TYPE_ACTIVE_OBJECT (nr_active_object_get_type ())
33 #define NR_ACTIVE_OBJECT(o) (NR_CHECK_INSTANCE_CAST ((o), NR_TYPE_ACTIVE_OBJECT, NRActiveObject))
34 #define NR_IS_ACTIVE_OBJECT(o) (NR_CHECK_INSTANCE_TYPE ((o), NR_TYPE_ACTIVE_OBJECT))
36 #define nr_return_if_fail(expr) if (!(expr) && nr_emit_fail_warning (__FILE__, __LINE__, "?", #expr)) return
37 #define nr_return_val_if_fail(expr,val) if (!(expr) && nr_emit_fail_warning (__FILE__, __LINE__, "?", #expr)) return (val)
39 unsigned int nr_emit_fail_warning (const gchar *file, unsigned int line, const gchar *method, const gchar *expr);
41 #ifndef NR_DISABLE_CAST_CHECKS
42 #define NR_CHECK_INSTANCE_CAST(ip, tc, ct) ((ct *) nr_object_check_instance_cast (ip, tc))
43 #else
44 #define NR_CHECK_INSTANCE_CAST(ip, tc, ct) ((ct *) ip)
45 #endif
47 #define NR_CHECK_INSTANCE_TYPE(ip, tc) nr_object_check_instance_type (ip, tc)
48 #define NR_OBJECT_GET_CLASS(ip) (((NRObject *) ip)->klass)
50 NRType nr_type_is_a (NRType type, NRType test);
52 void const *nr_object_check_instance_cast(void const *ip, NRType tc);
53 unsigned int nr_object_check_instance_type(void const *ip, NRType tc);
55 NRType nr_object_register_type (NRType parent,
56                                 gchar const *name,
57                                 unsigned int csize,
58                                 unsigned int isize,
59                                 void (* cinit) (NRObjectClass *),
60                                 void (* iinit) (NRObject *));
62 /* NRObject */
64 class NRObject : public Inkscape::GC::Managed<>,
65                  public Inkscape::GC::Finalized,
66                  public Inkscape::GC::Anchored
67 {
68 public:
69         NRObjectClass *klass;
71         static NRObject *alloc(NRType type);
73         template <typename T>
74         static void invoke_ctor(NRObject *object) {
75                 new (object) T();
76         }
78         /* these can go away eventually */
79         NRObject *reference() {
80                 return Inkscape::GC::anchor(this);
81         }
82         NRObject *unreference() {
83                 Inkscape::GC::release(this);
84                 return NULL;
85         }
87 protected:
88         NRObject() {}
90 private:
91         NRObject(NRObject const &); // no copy
92         void operator=(NRObject const &); // no assign
94         void *operator new(size_t size, void *placement) { (void)size; return placement; }
95 };
97 struct NRObjectClass {
98         NRType type;
99         NRObjectClass *parent;
101         gchar *name;
102         unsigned int csize;
103         unsigned int isize;
104         void (* cinit) (NRObjectClass *);
105         void (* iinit) (NRObject *);
106         void (* finalize) (NRObject *object);
107         void (*cpp_ctor)(NRObject *object);
108 };
110 NRType nr_object_get_type (void);
112 /* Dynamic lifecycle */
114 inline NRObject *nr_object_new (NRType type) {
115         return NRObject::alloc(type);
118 inline NRObject *nr_object_ref (NRObject *object) {
119         return object->reference();
121 inline NRObject *nr_object_unref (NRObject *object) {
122         return object->unreference();
125 /* NRActiveObject */
127 struct NRObjectEventVector {
128         void (* dispose) (NRObject *object, void *data);
129 };
131 struct NRObjectListener {
132         const NRObjectEventVector *vector;
133         unsigned int size;
134         void *data;
135 };
137 struct NRObjectCallbackBlock {
138         unsigned int size;
139         unsigned int length;
140         NRObjectListener listeners[1];
141 };
143 struct NRActiveObject : public NRObject {
144         NRActiveObject() : callbacks(NULL) {}
145         NRObjectCallbackBlock *callbacks;
146 };
148 struct NRActiveObjectClass : public NRObjectClass {
149 };
151 NRType nr_active_object_get_type (void);
153 void nr_active_object_add_listener (NRActiveObject *object, const NRObjectEventVector *vector, unsigned int size, void *data);
154 void nr_active_object_remove_listener_by_data (NRActiveObject *object, void *data);
156 #endif