blob: e7d027add1550f5d79348b2b5f05d46a646308f5 [file] [log] [blame]
Howard Hinnant7a563db2011-09-14 18:33:51 +00001// -*- C++ -*-
2//===--------------------------- __debug ----------------------------------===//
3//
4// The LLVM Compiler Infrastructure
5//
6// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
8//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_DEBUG_H
12#define _LIBCPP_DEBUG_H
13
14# include <cstdlib>
15# include <cstdio>
16# include <cstddef>
17# define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : (_VSTD::printf("%s\n", m), _VSTD::abort()))
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21struct _LIBCPP_VISIBLE __c_node;
22
23struct _LIBCPP_VISIBLE __i_node
24{
25 void* __i_;
26 __i_node* __next_;
27 __c_node* __c_;
28
29 __i_node(const __i_node&) = delete;
30 __i_node& operator=(const __i_node&) = delete;
31 _LIBCPP_INLINE_VISIBILITY
32 __i_node(void* __i, __i_node* __next, __c_node* __c)
33 : __i_(__i), __next_(__next), __c_(__c) {}
34 ~__i_node();
35};
36
37struct _LIBCPP_VISIBLE __c_node
38{
39 void* __c_;
40 __c_node* __next_;
41 __i_node** beg_;
42 __i_node** end_;
43 __i_node** cap_;
44
45 __c_node(const __c_node&) = delete;
46 __c_node& operator=(const __c_node&) = delete;
47 _LIBCPP_INLINE_VISIBILITY
48 __c_node(void* __c, __c_node* __next)
49 : __c_(__c), __next_(__next), beg_(nullptr), end_(nullptr), cap_(nullptr) {}
50 virtual ~__c_node();
51
52 virtual bool __dereferenceable(const void*) const = 0;
53 virtual bool __decrementable(const void*) const = 0;
54 virtual bool __addable(const void*, ptrdiff_t) const = 0;
55 virtual bool __subscriptable(const void*, ptrdiff_t) const = 0;
56
57 _LIBCPP_HIDDEN void __add(__i_node* __i);
58 _LIBCPP_HIDDEN void __remove(__i_node* __i);
59};
60
61template <class _Cont>
62struct _C_node
63 : public __c_node
64{
65 _C_node(void* __c, __c_node* __n)
66 : __c_node(__c, __n) {}
67
68 virtual bool __dereferenceable(const void*) const;
69 virtual bool __decrementable(const void*) const;
70 virtual bool __addable(const void*, ptrdiff_t) const;
71 virtual bool __subscriptable(const void*, ptrdiff_t) const;
72};
73
74template <class _Cont>
75bool
76_C_node<_Cont>::__dereferenceable(const void* __i) const
77{
78 typedef typename _Cont::const_iterator iterator;
79 const iterator* __j = static_cast<const iterator*>(__i);
80 _Cont* _C = static_cast<_Cont*>(__c_);
81 return _C->__dereferenceable(__j);
82}
83
84template <class _Cont>
85bool
86_C_node<_Cont>::__decrementable(const void* __i) const
87{
88 typedef typename _Cont::const_iterator iterator;
89 const iterator* __j = static_cast<const iterator*>(__i);
90 _Cont* _C = static_cast<_Cont*>(__c_);
91 return _C->__decrementable(__j);
92}
93
94template <class _Cont>
95bool
96_C_node<_Cont>::__addable(const void* __i, ptrdiff_t __n) const
97{
98 typedef typename _Cont::const_iterator iterator;
99 const iterator* __j = static_cast<const iterator*>(__i);
100 _Cont* _C = static_cast<_Cont*>(__c_);
101 return _C->__addable(__j, __n);
102}
103
104template <class _Cont>
105bool
106_C_node<_Cont>::__subscriptable(const void* __i, ptrdiff_t __n) const
107{
108 typedef typename _Cont::const_iterator iterator;
109 const iterator* __j = static_cast<const iterator*>(__i);
110 _Cont* _C = static_cast<_Cont*>(__c_);
111 return _C->__subscriptable(__j, __n);
112}
113
114class _LIBCPP_VISIBLE __libcpp_db
115{
116 __c_node** __cbeg_;
117 __c_node** __cend_;
118 size_t __csz_;
119 __i_node** __ibeg_;
120 __i_node** __iend_;
121 size_t __isz_;
122
123 __libcpp_db();
124public:
125 __libcpp_db(const __libcpp_db&) = delete;
126 __libcpp_db& operator=(const __libcpp_db&) = delete;
127 ~__libcpp_db();
128
129 class __db_c_iterator;
130 class __db_c_const_iterator;
131 class __db_i_iterator;
132 class __db_i_const_iterator;
133
134 __db_c_const_iterator __c_end() const;
135 __db_i_const_iterator __i_end() const;
136
137 template <class _Cont>
138 _LIBCPP_INLINE_VISIBILITY
139 void __insert_c(_Cont* __c)
140 {
141 __c_node* __n = __insert_c(static_cast<void*>(__c));
142 ::new(__n) _C_node<_Cont>(__n->__c_, __n->__next_);
143 }
144
145 __c_node* __insert_c(void* __c);
146 void __erase_c(void* __c);
147
148 void __insert_ic(void* __i, const void* __c);
149 void __iterator_copy(void* __i, const void* __i0);
150 void __erase_i(void* __i);
151
152 void* __find_c_from_i(void* __i) const;
153 void __invalidate_all(void* __c);
154 __c_node* __find_c_and_lock(void* __c) const;
155 void unlock() const;
156
157 void swap(void* __c1, void* __c2);
158
159
160 bool __dereferenceable(const void* __i) const;
161 bool __decrementable(const void* __i) const;
162 bool __addable(const void* __i, ptrdiff_t __n) const;
163 bool __subscriptable(const void* __i, ptrdiff_t __n) const;
164 bool __comparable(const void* __i, const void* __j) const;
165private:
166 _LIBCPP_HIDDEN
167 __i_node* __insert_iterator(void* __i);
168 _LIBCPP_HIDDEN
169 __i_node* __find_iterator(const void* __i) const;
170
171 friend _LIBCPP_VISIBLE __libcpp_db* __get_db();
172};
173
174_LIBCPP_VISIBLE __libcpp_db* __get_db();
175_LIBCPP_VISIBLE const __libcpp_db* __get_const_db();
176
177
178_LIBCPP_END_NAMESPACE_STD
179
180#endif // _LIBCPP_DEBUG_H
181