… | |
… | |
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 | |
429 | template<class T, int T::* index> |
429 | template<class T, int T::* index> |
430 | struct object_vector : std::vector<T *, slice_allocator<T *> > |
430 | struct 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 (); |