ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/object.C
Revision: 1.5
Committed: Sun Sep 16 18:54:45 2007 UTC (16 years, 8 months ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +7 -2 lines
Log Message:
#defines to enum

File Contents

# User Rev Content
1 pippijn 1.1 /*
2     * object.C: Object management.
3 pippijn 1.5 *
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.2 * Rights to this code are documented in doc/pod/license.pod.
10 pippijn 1.4 * Copyright © 2005-2007 Atheme Project (http://www.atheme.org)
11 pippijn 1.1 */
12    
13 pippijn 1.5 static char const rcsid[] = "$Id: object.C,v 1.4 2007-08-28 17:08:12 pippijn Exp $";
14 pippijn 1.1
15     #include "atheme.h"
16    
17     /*
18     * object_init
19     *
20     * Populates the object manager part of an object.
21     *
22     * Inputs:
23     * - pointer to object manager area
24     * - (optional) name of object
25     * - (optional) custom destructor
26     *
27     * Outputs:
28     * - none
29     *
30     * Side Effects:
31     * - none
32     */
33     void
34     object_init (object_t * obj, const char *name, destructor_t des)
35     {
36     return_if_fail (obj != NULL);
37    
38 pippijn 1.4 if (name != NULL)
39     obj->name = sstrdup (name);
40     else
41     obj->name = sstrdup ("");
42 pippijn 1.1
43     obj->destructor = des;
44     obj->refcount = 1;
45     }
46    
47     /*
48     * object_ref
49     *
50     * Increment the reference counter on an object.
51     *
52     * Inputs:
53     * - the object to refcount
54     *
55     * Outputs:
56     * - none
57     *
58     * Side Effects:
59     * - none
60     */
61     void *
62     object_ref (void *object)
63     {
64     return_val_if_fail (object != NULL, NULL);
65    
66     asobject (object)->refcount++;
67    
68     return object;
69     }
70    
71     /*
72     * object_unref
73     *
74     * Decrement the reference counter on an object.
75     *
76     * Inputs:
77     * - the object to refcount
78     *
79     * Outputs:
80     * - none
81     *
82     * Side Effects:
83     * - if the refcount is 0, the object is destroyed.
84     */
85     void
86     object_unref (void *object)
87     {
88     object_t *obj;
89    
90     return_if_fail (object != NULL);
91     obj = asobject (object);
92    
93     obj->refcount--;
94    
95     if (obj->refcount <= 0)
96     {
97 pippijn 1.4 sfree (obj->name);
98 pippijn 1.1
99     if (obj->destructor != NULL)
100     obj->destructor (obj);
101     else
102 pippijn 1.4 sfree (obj);
103 pippijn 1.1 }
104     }