… | |
… | |
33 | # define is_constant(c) 0 |
33 | # define is_constant(c) 0 |
34 | # define expect(expr,value) (expr) |
34 | # define expect(expr,value) (expr) |
35 | # define prefetch(addr,rw,locality) |
35 | # define prefetch(addr,rw,locality) |
36 | #endif |
36 | #endif |
37 | |
37 | |
|
|
38 | #if __GNUC__ < 4 || (__GNUC__ == 4 || __GNUC_MINOR__ < 4) |
|
|
39 | # define decltype(x) typeof(x) |
|
|
40 | #endif |
|
|
41 | |
38 | // put into ifs if you are very sure that the expression |
42 | // put into ifs if you are very sure that the expression |
39 | // is mostly true or mosty false. note that these return |
43 | // is mostly true or mosty false. note that these return |
40 | // booleans, not the expression. |
44 | // booleans, not the expression. |
41 | #define expect_false(expr) expect ((expr) != 0, 0) |
45 | #define expect_false(expr) expect ((expr) != 0, 0) |
42 | #define expect_true(expr) expect ((expr) != 0, 1) |
46 | #define expect_true(expr) expect ((expr) != 0, 1) |
… | |
… | |
50 | |
54 | |
51 | #include <shstr.h> |
55 | #include <shstr.h> |
52 | #include <traits.h> |
56 | #include <traits.h> |
53 | |
57 | |
54 | // use a gcc extension for auto declarations until ISO C++ sanctifies them |
58 | // use a gcc extension for auto declarations until ISO C++ sanctifies them |
55 | #define auto(var,expr) typeof(expr) var = (expr) |
59 | #define auto(var,expr) decltype(expr) var = (expr) |
56 | |
60 | |
57 | // very ugly macro that basicaly declares and initialises a variable |
61 | // very ugly macro that basicaly declares and initialises a variable |
58 | // that is in scope for the next statement only |
62 | // that is in scope for the next statement only |
59 | // 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 |
60 | // (note: works great for pointers) |
64 | // (note: works great for pointers) |
61 | // most ugly macro I ever wrote |
65 | // most ugly macro I ever wrote |
62 | #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) |
63 | |
67 | |
64 | // in range including end |
68 | // in range including end |
65 | #define IN_RANGE_INC(val,beg,end) \ |
69 | #define IN_RANGE_INC(val,beg,end) \ |
66 | ((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)) |
67 | |
71 | |
… | |
… | |
423 | }; |
427 | }; |
424 | |
428 | |
425 | template<class T, int T::* index> |
429 | template<class T, int T::* index> |
426 | struct object_vector : std::vector<T *, slice_allocator<T *> > |
430 | struct object_vector : std::vector<T *, slice_allocator<T *> > |
427 | { |
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 | |
428 | void insert (T *obj) |
446 | void insert (T *obj) |
429 | { |
447 | { |
430 | assert (!(obj->*index)); |
448 | assert (!(obj->*index)); |
431 | push_back (obj); |
449 | push_back (obj); |
432 | obj->*index = this->size (); |
450 | obj->*index = this->size (); |