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.25 by root, Sat Dec 30 10:16:10 2006 UTC

6#else 6#else
7# define is_constant(c) 0 7# define is_constant(c) 0
8#endif 8#endif
9 9
10#include <cstddef> 10#include <cstddef>
11#include <new>
12#include <vector>
11 13
12#include <glib.h> 14#include <glib.h>
15
16#include <shstr.h>
17#include <traits.h>
13 18
14// use a gcc extension for auto declarations until ISO C++ sanctifies them 19// use a gcc extension for auto declarations until ISO C++ sanctifies them
15#define AUTODECL(var,expr) typeof(expr) var = (expr) 20#define AUTODECL(var,expr) typeof(expr) var = (expr)
16 21
17// makes dynamically allocated objects zero-initialised 22// makes dynamically allocated objects zero-initialised
53 58
54// also copies src into the new area, like "memdup" 59// also copies src into the new area, like "memdup"
55// if src is 0, clears the memory 60// if src is 0, clears the memory
56template<typename T> 61template<typename T>
57inline T *salloc (int n, T *src) throw (std::bad_alloc) { return (T *)salloc_ (n * sizeof (T), (void *)src); } 62inline T *salloc (int n, T *src) throw (std::bad_alloc) { return (T *)salloc_ (n * sizeof (T), (void *)src); }
63
64// clears the memory
65template<typename T>
66inline T *salloc0(int n = 1) throw (std::bad_alloc) { return (T *)salloc_ (n * sizeof (T), 0); }
58 67
59// for symmetry 68// for symmetry
60template<typename T> 69template<typename T>
61inline void sfree (T *ptr, int n = 1) throw () 70inline void sfree (T *ptr, int n = 1) throw ()
62{ 71{
116 { 125 {
117 p->~Tp (); 126 p->~Tp ();
118 } 127 }
119}; 128};
120 129
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> 130template<class T>
137struct refptr 131struct refptr
138{ 132{
139 T *p; 133 T *p;
140 134
161 T &operator * () const { return *p; } 155 T &operator * () const { return *p; }
162 T *operator ->() const { return p; } 156 T *operator ->() const { return p; }
163 157
164 operator T *() const { return p; } 158 operator T *() const { return p; }
165}; 159};
160
161typedef refptr<maptile> maptile_ptr;
162typedef refptr<object> object_ptr;
163typedef refptr<archetype> arch_ptr;
164typedef refptr<client> client_ptr;
165typedef refptr<player> player_ptr;
166 166
167struct str_hash 167struct str_hash
168{ 168{
169 std::size_t operator ()(const char *s) const 169 std::size_t operator ()(const char *s) const
170 { 170 {
196 { 196 {
197 return !strcmp (a, b); 197 return !strcmp (a, b);
198 } 198 }
199}; 199};
200 200
201#include <vector>
202
203template<class obj> 201template<class obj>
204struct unordered_vector : std::vector<obj, slice_allocator<obj> > 202struct unordered_vector : std::vector<obj, slice_allocator<obj> >
205{ 203{
206 typedef typename unordered_vector::iterator iterator; 204 typedef typename unordered_vector::iterator iterator;
207 205
238typedef double tstamp; 236typedef double tstamp;
239 237
240// return current time as timestampe 238// return current time as timestampe
241tstamp now (); 239tstamp now ();
242 240
241int similar_direction (int a, int b);
242
243#endif 243#endif
244 244

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines