… | |
… | |
8 | #endif |
8 | #endif |
9 | |
9 | |
10 | #include <cstddef> |
10 | #include <cstddef> |
11 | |
11 | |
12 | #include <glib.h> |
12 | #include <glib.h> |
|
|
13 | |
|
|
14 | // use a gcc extension for auto declarations until ISO C++ sanctifies them |
|
|
15 | #define AUTODECL(var,expr) typeof(expr) var = (expr) |
13 | |
16 | |
14 | // makes dynamically allocated objects zero-initialised |
17 | // makes dynamically allocated objects zero-initialised |
15 | struct zero_initialised |
18 | struct zero_initialised |
16 | { |
19 | { |
17 | void *operator new (size_t s, void *p) |
20 | void *operator new (size_t s, void *p) |
… | |
… | |
104 | } |
107 | } |
105 | }; |
108 | }; |
106 | |
109 | |
107 | struct refcounted |
110 | struct refcounted |
108 | { |
111 | { |
|
|
112 | refcounted () : refcnt (0) { } |
|
|
113 | // virtual ~refcounted (); |
|
|
114 | void refcnt_inc () { ++refcnt; } |
|
|
115 | void refcnt_dec () { --refcnt; } |
|
|
116 | bool dead () { return refcnt == 0; } |
109 | mutable int refcnt; |
117 | mutable int refcnt; |
110 | refcounted () : refcnt (0) { } |
118 | #if 0 |
111 | void refcnt_inc () { ++refcnt; } |
119 | private: |
112 | void refcnt_dec () { --refcnt; |
120 | static refcounted *rc_first; |
113 | if (refcnt < 0)abort();}//D |
121 | refcounted *rc_next; |
|
|
122 | #endif |
114 | }; |
123 | }; |
115 | |
124 | |
116 | template<class T> |
125 | template<class T> |
117 | struct refptr |
126 | struct refptr |
118 | { |
127 | { |