ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/util.h
(Generate patch)

Comparing deliantra/server/include/util.h (file contents):
Revision 1.20 by root, Sun Dec 17 23:10:35 2006 UTC vs.
Revision 1.24 by root, Mon Dec 25 11:25:49 2006 UTC

53 53
54// also copies src into the new area, like "memdup" 54// also copies src into the new area, like "memdup"
55// if src is 0, clears the memory 55// if src is 0, clears the memory
56template<typename T> 56template<typename T>
57inline T *salloc (int n, T *src) throw (std::bad_alloc) { return (T *)salloc_ (n * sizeof (T), (void *)src); } 57inline T *salloc (int n, T *src) throw (std::bad_alloc) { return (T *)salloc_ (n * sizeof (T), (void *)src); }
58
59// clears the memory
60template<typename T>
61inline T *salloc0(int n = 1) throw (std::bad_alloc) { return (T *)salloc_ (n * sizeof (T), 0); }
58 62
59// for symmetry 63// for symmetry
60template<typename T> 64template<typename T>
61inline void sfree (T *ptr, int n = 1) throw () 65inline void sfree (T *ptr, int n = 1) throw ()
62{ 66{
116 { 120 {
117 p->~Tp (); 121 p->~Tp ();
118 } 122 }
119}; 123};
120 124
121struct refcounted
122{
123 refcounted () : refcnt (0) { }
124// virtual ~refcounted ();
125 void refcnt_inc () { ++refcnt; }
126 void refcnt_dec () { --refcnt; }
127 bool dead () { return refcnt == 0; }
128 mutable int refcnt;
129#if 0
130private:
131 static refcounted *rc_first;
132 refcounted *rc_next;
133#endif
134};
135
136template<class T> 125template<class T>
137struct refptr 126struct refptr
138{ 127{
139 T *p; 128 T *p;
140 129
161 T &operator * () const { return *p; } 150 T &operator * () const { return *p; }
162 T *operator ->() const { return p; } 151 T *operator ->() const { return p; }
163 152
164 operator T *() const { return p; } 153 operator T *() const { return p; }
165}; 154};
155
156typedef refptr<maptile> maptile_ptr;
157typedef refptr<object> object_ptr;
158typedef refptr<archetype> arch_ptr;
159typedef refptr<client> client_ptr;
160typedef refptr<player> player_ptr;
166 161
167struct str_hash 162struct str_hash
168{ 163{
169 std::size_t operator ()(const char *s) const 164 std::size_t operator ()(const char *s) const
170 { 165 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines