ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/include/object.h
Revision: 1.1
Committed: Thu Jul 19 08:24:50 2007 UTC (16 years, 10 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Log Message:
initial import. the most important changes since Atheme are:
- fixed many memory leaks
- fixed many bugs
- converted to C++ and use more STL containers
- added a (not very enhanced yet) perl module
- greatly improved XML-RPC speed
- added a JSON-RPC module with code from json-cpp
- added a valgrind memcheck module to operserv
- added a more object oriented base64 implementation
- added a specialised unit test framework
- improved stability
- use gettimeofday() if available
- reworked adding/removing commands
- MemoServ IGNORE DEL can now remove indices

File Contents

# User Rev Content
1 pippijn 1.1 /*
2     * Copyright © 2007 William Pitcock <nenolod -at- atheme.org>
3     * Rights to this code are as documented in doc/LICENSE.
4     *
5     * Object management.
6     *
7     * $Id: object.h 7779 2007-03-03 13:55:42Z pippijn $
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