• R/O
  • SSH
  • HTTPS

cstl: Commit


Commit MetaInfo

Revision394 (tree)
Time2010-07-14 20:45:50
Authorkatono

Log Message

仮想関数呼び出し前にASSERT追加。

Change Summary

Incremental Difference

--- branches/try-vfunc/cstl/common.h (revision 393)
+++ branches/try-vfunc/cstl/common.h (revision 394)
@@ -46,93 +46,96 @@
4646 #include <assert.h>
4747 #define CSTL_MAGIC(x) x
4848 #define CSTL_ASSERT(x) assert(x)
49+#define CSTL_CHK_ITER_IS_MAP(p) ((p).vptr->container & (CSTL_CONTAINER_MAP | CSTL_CONTAINER_UNORDERED_MAP))
50+#define CSTL_CHK_ITER_IS_RAND(p) ((p).vptr->is_rand_iter)
51+#define CSTL_CHK_ITER_IS_BIDIR(p) (!((p).vptr->container & (CSTL_CONTAINER_UNORDERED_SET | CSTL_CONTAINER_UNORDERED_MAP)))
4952 #else
5053 #define CSTL_MAGIC(x)
51-#define CSTL_ASSERT(x)
54+#define CSTL_ASSERT(x) ((void) 0)
5255 #endif
56+#define CSTL_ASSERT_SELF(s) CSTL_ASSERT((s) && (s)->magic == (s))
5357
5458 #define CSTL_UNUSED_PARAM(x) (void) x
5559
56-#define cstl_delete(s) ((s) ? (s)->u.vptr->delete_(s) : (void)0)
57-#define cstl_push_back(s, d) ((s)->u.vptr->push_back(s, d))
58-#define cstl_push_front(s, d) ((s)->u.vptr->push_front(s, d))
59-#define cstl_push_back_ref(s, d) ((s)->u.vptr->push_back_ref(s, d))
60-#define cstl_push_front_ref(s, d) ((s)->u.vptr->push_front_ref(s, d))
61-#define cstl_pop_front(s) ((s)->u.vptr->pop_front(s))
62-#define cstl_pop_back(s) ((s)->u.vptr->pop_back(s))
63-#define cstl_empty(s) ((s)->u.vptr->empty(s))
64-#define cstl_size(s) ((s)->u.vptr->size(s))
65-#define cstl_clear(s) ((s)->u.vptr->clear(s))
66-#define cstl_front(s) ((s)->u.vptr->front(s))
67-#define cstl_back(s) ((s)->u.vptr->back(s))
68-#define cstl_begin(s) ((s)->u.vptr->begin(s))
69-#define cstl_end(s) ((s)->u.vptr->end(s))
70-#define cstl_rbegin(s) ((s)->u.vptr->rbegin(s))
71-#define cstl_rend(s) ((s)->u.vptr->rend(s))
72-#define cstl_insert(s, p, d, i) ((s)->u.vptr->insert(s, (p).internal.data, d, i))
73-#define cstl_insert_ref(s, p, d, i) ((s)->u.vptr->insert_ref(s, (p).internal.data, d, i))
74-#define cstl_insert_n(s, p, n, d) ((s)->u.vptr->insert_n(s, (p).internal.data, n, d))
75-#define cstl_insert_n_ref(s, p, n, d) ((s)->u.vptr->insert_n_ref(s, (p).internal.data, n, d))
76-#define cstl_insert_array(s, p, d, n) ((s)->u.vptr->insert_array(s, (p).internal.data, d, n))
77-#define cstl_insert_range(s, p, f, l) ((s)->u.vptr->insert_range(s, (p).internal.data, (f).internal, (l).internal))
78-#define cstl_erase(s, p) ((s)->u.vptr->erase(s, (p).internal.data))
79-#define cstl_erase_range(s, f, l) ((s)->u.vptr->erase_range(s, (f).internal.data, (l).internal.data))
80-#define cstl_resize(s, n, d) ((s)->u.vptr->resize(s, n, d))
81-#define cstl_swap(s, x) ((s)->u.vptr->swap(s, x))
82-#define cstl_capacity(s) ((s)->u.vptr->capacity(s))
83-#define cstl_reserve(s, n) ((s)->u.vptr->reserve(s, n))
84-#define cstl_shrink(s, n) ((s)->u.vptr->shrink(s, n))
85-#define cstl_at(s, i) ((s)->u.vptr->at(s, i))
86-#define cstl_splice(s, p, x, f, l) ((s)->u.vptr->splice(s, (p).internal.data, x, (f).internal.data, (l).internal.data))
87-#define cstl_sort(s, c) ((s)->u.vptr->sort(s, c))
88-#define cstl_merge(s, x, c) ((s)->u.vptr->merge(s, x, c))
89-#define cstl_reverse(s) ((s)->u.vptr->reverse(s))
90-#define cstl_set_insert(s, d, i, su) ((s)->u.vptr->set_insert(s, d, i, su))
91-#define cstl_multiset_insert(s, d, i) ((s)->u.vptr->multiset_insert(s, d, i))
92-#define cstl_map_insert(s, k, v, i, su) ((s)->u.vptr->map_insert(s, k, v, i, su))
93-#define cstl_multimap_insert(s, k, v, i) ((s)->u.vptr->multimap_insert(s, k, v, i))
94-#define cstl_map_insert_ref(s, k, v, i, su) ((s)->u.vptr->map_insert_ref(s, k, v, i, su))
95-#define cstl_multimap_insert_ref(s, k, v, i) ((s)->u.vptr->multimap_insert_ref(s, k, v, i))
96-#define cstl_assoc_insert_range(s, f, l) ((s)->u.vptr->assoc_insert_range(s, (f).internal, (l).internal))
97-#define cstl_erase_key(s, k) ((s)->u.vptr->erase_key(s, k))
98-#define cstl_count(s, k) ((s)->u.vptr->count(s, k))
99-#define cstl_find(s, k) ((s)->u.vptr->find(s, k))
100-#define cstl_lower_bound(s, k) ((s)->u.vptr->lower_bound(s, k))
101-#define cstl_upper_bound(s, k) ((s)->u.vptr->upper_bound(s, k))
102-#define cstl_equal_range(s, f, l) ((s)->u.vptr->equal_range(s, &(f), &(l)))
60+#define cstl_delete(s) ((s) ? CSTL_ASSERT_SELF(s), (s)->u.vptr->delete_(s) : (void) 0)
61+#define cstl_push_back(s, d) (CSTL_ASSERT_SELF(s), (s)->u.vptr->push_back(s, d))
62+#define cstl_push_front(s, d) (CSTL_ASSERT_SELF(s), (s)->u.vptr->push_front(s, d))
63+#define cstl_push_back_ref(s, d) (CSTL_ASSERT_SELF(s), (s)->u.vptr->push_back_ref(s, d))
64+#define cstl_push_front_ref(s, d) (CSTL_ASSERT_SELF(s), (s)->u.vptr->push_front_ref(s, d))
65+#define cstl_pop_front(s) (CSTL_ASSERT_SELF(s), (s)->u.vptr->pop_front(s))
66+#define cstl_pop_back(s) (CSTL_ASSERT_SELF(s), (s)->u.vptr->pop_back(s))
67+#define cstl_empty(s) (CSTL_ASSERT_SELF(s), (s)->u.vptr->empty(s))
68+#define cstl_size(s) (CSTL_ASSERT_SELF(s), (s)->u.vptr->size(s))
69+#define cstl_clear(s) (CSTL_ASSERT_SELF(s), (s)->u.vptr->clear(s))
70+#define cstl_front(s) (CSTL_ASSERT_SELF(s), (s)->u.vptr->front(s))
71+#define cstl_back(s) (CSTL_ASSERT_SELF(s), (s)->u.vptr->back(s))
72+#define cstl_begin(s) (CSTL_ASSERT_SELF(s), (s)->u.vptr->begin(s))
73+#define cstl_end(s) (CSTL_ASSERT_SELF(s), (s)->u.vptr->end(s))
74+#define cstl_rbegin(s) (CSTL_ASSERT_SELF(s), (s)->u.vptr->rbegin(s))
75+#define cstl_rend(s) (CSTL_ASSERT_SELF(s), (s)->u.vptr->rend(s))
76+#define cstl_insert(s, p, d, i) (CSTL_ASSERT_SELF(s), (s)->u.vptr->insert(s, (p).internal.data, d, i))
77+#define cstl_insert_ref(s, p, d, i) (CSTL_ASSERT_SELF(s), (s)->u.vptr->insert_ref(s, (p).internal.data, d, i))
78+#define cstl_insert_n(s, p, n, d) (CSTL_ASSERT_SELF(s), (s)->u.vptr->insert_n(s, (p).internal.data, n, d))
79+#define cstl_insert_n_ref(s, p, n, d) (CSTL_ASSERT_SELF(s), (s)->u.vptr->insert_n_ref(s, (p).internal.data, n, d))
80+#define cstl_insert_array(s, p, d, n) (CSTL_ASSERT_SELF(s), (s)->u.vptr->insert_array(s, (p).internal.data, d, n))
81+#define cstl_insert_range(s, p, f, l) (CSTL_ASSERT_SELF(s), (s)->u.vptr->insert_range(s, (p).internal.data, (f).internal, (l).internal))
82+#define cstl_erase(s, p) (CSTL_ASSERT_SELF(s), (s)->u.vptr->erase(s, (p).internal.data))
83+#define cstl_erase_range(s, f, l) (CSTL_ASSERT_SELF(s), (s)->u.vptr->erase_range(s, (f).internal.data, (l).internal.data))
84+#define cstl_resize(s, n, d) (CSTL_ASSERT_SELF(s), (s)->u.vptr->resize(s, n, d))
85+#define cstl_swap(s, x) (CSTL_ASSERT_SELF(s), (s)->u.vptr->swap(s, x))
86+#define cstl_capacity(s) (CSTL_ASSERT_SELF(s), (s)->u.vptr->capacity(s))
87+#define cstl_reserve(s, n) (CSTL_ASSERT_SELF(s), (s)->u.vptr->reserve(s, n))
88+#define cstl_shrink(s, n) (CSTL_ASSERT_SELF(s), (s)->u.vptr->shrink(s, n))
89+#define cstl_at(s, i) (CSTL_ASSERT_SELF(s), (s)->u.vptr->at(s, i))
90+#define cstl_splice(s, p, x, f, l) (CSTL_ASSERT_SELF(s), (s)->u.vptr->splice(s, (p).internal.data, x, (f).internal.data, (l).internal.data))
91+#define cstl_sort(s, c) (CSTL_ASSERT_SELF(s), (s)->u.vptr->sort(s, c))
92+#define cstl_merge(s, x, c) (CSTL_ASSERT_SELF(s), (s)->u.vptr->merge(s, x, c))
93+#define cstl_reverse(s) (CSTL_ASSERT_SELF(s), (s)->u.vptr->reverse(s))
94+#define cstl_set_insert(s, d, i, su) (CSTL_ASSERT_SELF(s), (s)->u.vptr->set_insert(s, d, i, su))
95+#define cstl_multiset_insert(s, d, i) (CSTL_ASSERT_SELF(s), (s)->u.vptr->multiset_insert(s, d, i))
96+#define cstl_map_insert(s, k, v, i, su) (CSTL_ASSERT_SELF(s), (s)->u.vptr->map_insert(s, k, v, i, su))
97+#define cstl_multimap_insert(s, k, v, i) (CSTL_ASSERT_SELF(s), (s)->u.vptr->multimap_insert(s, k, v, i))
98+#define cstl_map_insert_ref(s, k, v, i, su) (CSTL_ASSERT_SELF(s), (s)->u.vptr->map_insert_ref(s, k, v, i, su))
99+#define cstl_multimap_insert_ref(s, k, v, i) (CSTL_ASSERT_SELF(s), (s)->u.vptr->multimap_insert_ref(s, k, v, i))
100+#define cstl_assoc_insert_range(s, f, l) (CSTL_ASSERT_SELF(s), (s)->u.vptr->assoc_insert_range(s, (f).internal, (l).internal))
101+#define cstl_erase_key(s, k) (CSTL_ASSERT_SELF(s), (s)->u.vptr->erase_key(s, k))
102+#define cstl_count(s, k) (CSTL_ASSERT_SELF(s), (s)->u.vptr->count(s, k))
103+#define cstl_find(s, k) (CSTL_ASSERT_SELF(s), (s)->u.vptr->find(s, k))
104+#define cstl_lower_bound(s, k) (CSTL_ASSERT_SELF(s), (s)->u.vptr->lower_bound(s, k))
105+#define cstl_upper_bound(s, k) (CSTL_ASSERT_SELF(s), (s)->u.vptr->upper_bound(s, k))
106+#define cstl_equal_range(s, f, l) (CSTL_ASSERT_SELF(s), (s)->u.vptr->equal_range(s, f, l))
103107
104-#define cstl_iter_data(p) ((p).vptr->data((p).internal.data))
105-#define cstl_iter_key(p) ((p).vptr->key((p).internal.data))
106-#define cstl_iter_val(p) ((p).vptr->val((p).internal.data))
108+#define cstl_iter_data(p) (CSTL_ASSERT(!CSTL_CHK_ITER_IS_MAP(p)), (p).vptr->data((p).internal.data))
109+#define cstl_iter_key(p) (CSTL_ASSERT(CSTL_CHK_ITER_IS_MAP(p)), (p).vptr->key((p).internal.data))
110+#define cstl_iter_val(p) (CSTL_ASSERT(CSTL_CHK_ITER_IS_MAP(p)), (p).vptr->val((p).internal.data))
107111 #define cstl_iter_next(p) ((p).vptr->next((p).internal.data))
108-#define cstl_iter_prev(p) ((p).vptr->prev((p).internal.data))
109-#define cstl_iter_inc(pp) ((pp)->vptr->inc(&(pp)->internal.data))
110-#define cstl_iter_dec(pp) ((pp)->vptr->dec(&(pp)->internal.data))
112+#define cstl_iter_prev(p) (CSTL_ASSERT(CSTL_CHK_ITER_IS_BIDIR(p)), (p).vptr->prev((p).internal.data))
113+#define cstl_iter_inc(pp) (CSTL_ASSERT(pp), (pp)->vptr->inc(&(pp)->internal.data))
114+#define cstl_iter_dec(pp) (CSTL_ASSERT((pp) && CSTL_CHK_ITER_IS_BIDIR(*(pp))), (pp)->vptr->dec(&(pp)->internal.data))
111115 #define cstl_iter_eq(p, x) ((p).vptr->eq((p).internal.data, (x).internal.data))
112116 #define cstl_iter_ne(p, x) ((p).vptr->ne((p).internal.data, (x).internal.data))
113-#define cstl_iter_at(p, n) ((p).vptr->at((p).internal.data, n))
114-#define cstl_iter_add(p, n) ((p).vptr->add((p).internal.data, n))
115-#define cstl_iter_sub(p, n) ((p).vptr->sub((p).internal.data, n))
116-#define cstl_iter_inc_n(pp, n) ((pp)->vptr->inc_n(&(pp)->internal.data, n))
117-#define cstl_iter_dec_n(pp, n) ((pp)->vptr->dec_n(&(pp)->internal.data, n))
118-#define cstl_iter_diff(p, x) ((p).vptr->diff((p).internal.data, (x).internal.data))
119-#define cstl_iter_lt(p, x) ((p).vptr->lt((p).internal.data, (x).internal.data))
120-#define cstl_iter_le(p, x) ((p).vptr->le((p).internal.data, (x).internal.data))
121-#define cstl_iter_gt(p, x) ((p).vptr->gt((p).internal.data, (x).internal.data))
122-#define cstl_iter_ge(p, x) ((p).vptr->ge((p).internal.data, (x).internal.data))
123-#define cstl_iter_reverse_iterator(p) ((p).vptr->reverse_iterator((p).internal.data))
124-#define cstl_riter_base(p) ((p).vptr->base((p).internal.data))
117+#define cstl_iter_at(p, n) (CSTL_ASSERT(CSTL_CHK_ITER_IS_RAND(p)), (p).vptr->at((p).internal.data, n))
118+#define cstl_iter_add(p, n) (CSTL_ASSERT(CSTL_CHK_ITER_IS_RAND(p)), (p).vptr->add((p).internal.data, n))
119+#define cstl_iter_sub(p, n) (CSTL_ASSERT(CSTL_CHK_ITER_IS_RAND(p)), (p).vptr->sub((p).internal.data, n))
120+#define cstl_iter_inc_n(pp, n) (CSTL_ASSERT((pp) && CSTL_CHK_ITER_IS_RAND(*(pp))), (pp)->vptr->inc_n(&(pp)->internal.data, n))
121+#define cstl_iter_dec_n(pp, n) (CSTL_ASSERT((pp) && CSTL_CHK_ITER_IS_RAND(*(pp))), (pp)->vptr->dec_n(&(pp)->internal.data, n))
122+#define cstl_iter_diff(p, x) (CSTL_ASSERT(CSTL_CHK_ITER_IS_RAND(p)), (p).vptr->diff((p).internal.data, (x).internal.data))
123+#define cstl_iter_lt(p, x) (CSTL_ASSERT(CSTL_CHK_ITER_IS_RAND(p)), (p).vptr->lt((p).internal.data, (x).internal.data))
124+#define cstl_iter_le(p, x) (CSTL_ASSERT(CSTL_CHK_ITER_IS_RAND(p)), (p).vptr->le((p).internal.data, (x).internal.data))
125+#define cstl_iter_gt(p, x) (CSTL_ASSERT(CSTL_CHK_ITER_IS_RAND(p)), (p).vptr->gt((p).internal.data, (x).internal.data))
126+#define cstl_iter_ge(p, x) (CSTL_ASSERT(CSTL_CHK_ITER_IS_RAND(p)), (p).vptr->ge((p).internal.data, (x).internal.data))
127+#define cstl_iter_reverse_iterator(p) (CSTL_ASSERT(CSTL_CHK_ITER_IS_BIDIR(p)), (p).vptr->reverse_iterator((p).internal.data))
128+#define cstl_riter_base(p) (CSTL_ASSERT(CSTL_CHK_ITER_IS_BIDIR(p)), (p).vptr->base((p).internal.data))
125129
126-
127130 enum {
128- CSTL_CONTAINER_VECTOR,
129- CSTL_CONTAINER_DEQUE,
130- CSTL_CONTAINER_LIST,
131- CSTL_CONTAINER_SET,
132- CSTL_CONTAINER_MAP,
133- CSTL_CONTAINER_UNORDERED_SET,
134- CSTL_CONTAINER_UNORDERED_MAP,
135- CSTL_CONTAINER_STRING
131+ CSTL_CONTAINER_VECTOR = 0x01,
132+ CSTL_CONTAINER_DEQUE = 0x02,
133+ CSTL_CONTAINER_LIST = 0x04,
134+ CSTL_CONTAINER_SET = 0x08,
135+ CSTL_CONTAINER_MAP = 0x10,
136+ CSTL_CONTAINER_UNORDERED_SET = 0x20,
137+ CSTL_CONTAINER_UNORDERED_MAP = 0x40,
138+ CSTL_CONTAINER_STRING = 0x80
136139 };
137140
138141 typedef struct CstlIteratorDummyVtable CstlIteratorDummyVtable;
Show on old repository browser