ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/include/object.h
Revision: 1.5
Committed: Sun Sep 16 18:54:42 2007 UTC (16 years, 8 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.4: +9 -4 lines
Log Message:
#defines to enum

File Contents

# User Rev Content
1 pippijn 1.5 /**
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 pippijn 1.3 * Copyright © 2007 William Pitcock <nenolod -at- atheme.org>
10 pippijn 1.2 * Rights to this code are as documented in doc/pod/license.pod.
11 pippijn 1.1 *
12 pippijn 1.5 * $Id: object.h,v 1.4 2007-08-30 19:56:19 pippijn Exp $
13 pippijn 1.1 */
14    
15     #ifndef OBJECT_H
16     #define OBJECT_H
17    
18 pippijn 1.4 #include <common/memory.h>
19    
20 pippijn 1.1 /* 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 pippijn 1.3 struct object_t : zero_initialised
60 pippijn 1.1 {
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