ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/include/object.h
Revision: 1.6
Committed: Sat Sep 22 14:27:26 2007 UTC (16 years, 7 months ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +2 -2 lines
Log Message:
split up ermyth into ermyth-modules, libermyth (currently just ermyth-util) and ermyth-core

File Contents

# Content
1 /**
2 * object.h: Object management.
3 *
4 * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team
5 * Rights to this code are as documented in COPYING.
6 *
7 *
8 * Portions of this file were derived from sources bearing the following license:
9 * Copyright © 2007 William Pitcock <nenolod -at- atheme.org>
10 * Rights to this code are as documented in doc/pod/license.pod.
11 *
12 * $Id: object.h,v 1.5 2007-09-16 18:54:42 pippijn Exp $
13 */
14
15 #ifndef OBJECT_H
16 #define OBJECT_H
17
18 #include <util/memory.h>
19
20 /* object base class */
21 class object
22 {
23 mutable int refcnt;
24
25 protected:
26 object ()
27 : refcnt (1)
28 {
29 }
30
31 object (const object &other)
32 : refcnt (1)
33 {
34 }
35
36 virtual ~object () { }
37 virtual void _destroy () = 0;
38
39 public:
40 int refcnt_inc ()
41 {
42 return ++refcnt;
43 }
44
45 int refcnt_dec ()
46 {
47 if (!--refcnt)
48 {
49 this->_destroy ();
50 return 0;
51 }
52 else
53 return refcnt;
54 }
55 };
56
57 typedef void (*destructor_t) (void *);
58
59 struct object_t : zero_initialised
60 {
61 char *name;
62 int refcount;
63 destructor_t destructor;
64 };
65
66 E void object_init (object_t *, const char *name, destructor_t destructor);
67 E void *object_ref (void *);
68 E void object_unref (void *);
69
70 #define asobject(x) ((object_t *) x)
71
72 #endif