ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/include/object.h
Revision: 1.4
Committed: Thu Aug 30 19:56:19 2007 UTC (16 years, 9 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.3: +3 -1 lines
Log Message:
- put faultcodes into their own namespace
- removed old files
- limited header garbage in atheme.h
- macros to inline bools for connection_t::is_*
- put some connection_t functions into the connection_t class

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.3 2007-08-28 17:08:07 pippijn Exp $
8 */
9
10 #ifndef OBJECT_H
11 #define OBJECT_H
12
13 #include <common/memory.h>
14
15 /* object base class */
16 class object
17 {
18 mutable int refcnt;
19
20 protected:
21 object ()
22 : refcnt (1)
23 {
24 }
25
26 object (const object &other)
27 : refcnt (1)
28 {
29 }
30
31 virtual ~object () { }
32 virtual void _destroy () = 0;
33
34 public:
35 int refcnt_inc ()
36 {
37 return ++refcnt;
38 }
39
40 int refcnt_dec ()
41 {
42 if (!--refcnt)
43 {
44 this->_destroy ();
45 return 0;
46 }
47 else
48 return refcnt;
49 }
50 };
51
52 typedef void (*destructor_t) (void *);
53
54 struct object_t : zero_initialised
55 {
56 char *name;
57 int refcount;
58 destructor_t destructor;
59 };
60
61 E void object_init (object_t *, const char *name, destructor_t destructor);
62 E void *object_ref (void *);
63 E void object_unref (void *);
64
65 #define asobject(x) ((object_t *) x)
66
67 #endif