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.47 by root, Sat Jun 2 03:48:29 2007 UTC vs.
Revision 1.48 by root, Mon Jun 4 12:19:08 2007 UTC

61// very ugly macro that basicaly declares and initialises a variable 61// very ugly macro that basicaly declares and initialises a variable
62// that is in scope for the next statement only 62// that is in scope for the next statement only
63// works only for stuff that can be assigned 0 and converts to false 63// works only for stuff that can be assigned 0 and converts to false
64// (note: works great for pointers) 64// (note: works great for pointers)
65// most ugly macro I ever wrote 65// most ugly macro I ever wrote
66#define declvar(type, name, value) if (type name = 0) { } else if (((name) = (value)), 1) 66#define statementvar(type, name, value) if (type name = 0) { } else if (((name) = (value)), 1)
67 67
68// in range including end 68// in range including end
69#define IN_RANGE_INC(val,beg,end) \ 69#define IN_RANGE_INC(val,beg,end) \
70 ((unsigned int)(val) - (unsigned int)(beg) <= (unsigned int)(end) - (unsigned int)(beg)) 70 ((unsigned int)(val) - (unsigned int)(beg) <= (unsigned int)(end) - (unsigned int)(beg))
71 71
427}; 427};
428 428
429template<class T, int T::* index> 429template<class T, int T::* index>
430struct object_vector : std::vector<T *, slice_allocator<T *> > 430struct object_vector : std::vector<T *, slice_allocator<T *> >
431{ 431{
432 typedef typename object_vector::iterator iterator;
433
434 bool contains (const T *obj) const
435 {
436 return obj->*index;
437 }
438
439 iterator find (const T *obj)
440 {
441 return obj->*index
442 ? this->begin () + obj->*index - 1
443 : this->end ();
444 }
445
432 void insert (T *obj) 446 void insert (T *obj)
433 { 447 {
434 assert (!(obj->*index)); 448 assert (!(obj->*index));
435 push_back (obj); 449 push_back (obj);
436 obj->*index = this->size (); 450 obj->*index = this->size ();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines