ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/include/object.h
Revision: 1.2
Committed: Sat Jul 21 01:29:07 2007 UTC (16 years, 10 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.1: +2 -2 lines
Log Message:
- moved to new documentation system
- fixed small build error

File Contents

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