]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/libc++/include/__debug
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / libc++ / include / __debug
1 // -*- 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 #if _LIBCPP_DEBUG_LEVEL >= 1
15
16 #   include <cstdlib>
17 #   include <cstdio>
18 #   include <cstddef>
19 #   ifndef _LIBCPP_ASSERT
20 #      define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : (_VSTD::printf("%s\n", m), _VSTD::abort()))
21 #   endif
22
23 #endif
24
25 #if _LIBCPP_DEBUG_LEVEL >= 2
26
27 _LIBCPP_BEGIN_NAMESPACE_STD
28
29 struct _LIBCPP_TYPE_VIS __c_node;
30
31 struct _LIBCPP_TYPE_VIS __i_node
32 {
33     void* __i_;
34     __i_node* __next_;
35     __c_node* __c_;
36
37     __i_node(const __i_node&) = delete;
38     __i_node& operator=(const __i_node&) = delete;
39     _LIBCPP_INLINE_VISIBILITY
40     __i_node(void* __i, __i_node* __next, __c_node* __c)
41         : __i_(__i), __next_(__next), __c_(__c) {}
42     ~__i_node();
43 };
44
45 struct _LIBCPP_TYPE_VIS __c_node
46 {
47     void* __c_;
48     __c_node* __next_;
49     __i_node** beg_;
50     __i_node** end_;
51     __i_node** cap_;
52
53     __c_node(const __c_node&) = delete;
54     __c_node& operator=(const __c_node&) = delete;
55     _LIBCPP_INLINE_VISIBILITY
56     __c_node(void* __c, __c_node* __next)
57         : __c_(__c), __next_(__next), beg_(nullptr), end_(nullptr), cap_(nullptr) {}
58     virtual ~__c_node();
59
60     virtual bool __dereferenceable(const void*) const = 0;
61     virtual bool __decrementable(const void*) const = 0;
62     virtual bool __addable(const void*, ptrdiff_t) const = 0;
63     virtual bool __subscriptable(const void*, ptrdiff_t) const = 0;
64
65     void __add(__i_node* __i);
66     _LIBCPP_HIDDEN void __remove(__i_node* __i);
67 };
68
69 template <class _Cont>
70 struct _C_node
71     : public __c_node
72 {
73     _C_node(void* __c, __c_node* __n)
74         : __c_node(__c, __n) {}
75
76     virtual bool __dereferenceable(const void*) const;
77     virtual bool __decrementable(const void*) const;
78     virtual bool __addable(const void*, ptrdiff_t) const;
79     virtual bool __subscriptable(const void*, ptrdiff_t) const;
80 };
81
82 template <class _Cont>
83 bool
84 _C_node<_Cont>::__dereferenceable(const void* __i) const
85 {
86     typedef typename _Cont::const_iterator iterator;
87     const iterator* __j = static_cast<const iterator*>(__i);
88     _Cont* _Cp = static_cast<_Cont*>(__c_);
89     return _Cp->__dereferenceable(__j);
90 }
91
92 template <class _Cont>
93 bool
94 _C_node<_Cont>::__decrementable(const void* __i) const
95 {
96     typedef typename _Cont::const_iterator iterator;
97     const iterator* __j = static_cast<const iterator*>(__i);
98     _Cont* _Cp = static_cast<_Cont*>(__c_);
99     return _Cp->__decrementable(__j);
100 }
101
102 template <class _Cont>
103 bool
104 _C_node<_Cont>::__addable(const void* __i, ptrdiff_t __n) const
105 {
106     typedef typename _Cont::const_iterator iterator;
107     const iterator* __j = static_cast<const iterator*>(__i);
108     _Cont* _Cp = static_cast<_Cont*>(__c_);
109     return _Cp->__addable(__j, __n);
110 }
111
112 template <class _Cont>
113 bool
114 _C_node<_Cont>::__subscriptable(const void* __i, ptrdiff_t __n) const
115 {
116     typedef typename _Cont::const_iterator iterator;
117     const iterator* __j = static_cast<const iterator*>(__i);
118     _Cont* _Cp = static_cast<_Cont*>(__c_);
119     return _Cp->__subscriptable(__j, __n);
120 }
121
122 class _LIBCPP_TYPE_VIS __libcpp_db
123 {
124     __c_node** __cbeg_;
125     __c_node** __cend_;
126     size_t   __csz_;
127     __i_node** __ibeg_;
128     __i_node** __iend_;
129     size_t   __isz_;
130
131     __libcpp_db();
132 public:
133     __libcpp_db(const __libcpp_db&) = delete;
134     __libcpp_db& operator=(const __libcpp_db&) = delete;
135     ~__libcpp_db();
136
137     class __db_c_iterator;
138     class __db_c_const_iterator;
139     class __db_i_iterator;
140     class __db_i_const_iterator;
141
142     __db_c_const_iterator __c_end() const;
143     __db_i_const_iterator __i_end() const;
144
145     template <class _Cont>
146     _LIBCPP_INLINE_VISIBILITY
147     void __insert_c(_Cont* __c)
148     {
149         __c_node* __n = __insert_c(static_cast<void*>(__c));
150         ::new(__n) _C_node<_Cont>(__n->__c_, __n->__next_);
151     }
152
153     void __insert_i(void* __i);
154     __c_node* __insert_c(void* __c);
155     void __erase_c(void* __c);
156
157     void __insert_ic(void* __i, const void* __c);
158     void __iterator_copy(void* __i, const void* __i0);
159     void __erase_i(void* __i);
160
161     void* __find_c_from_i(void* __i) const;
162     void __invalidate_all(void* __c);
163     __c_node* __find_c_and_lock(void* __c) const;
164     __c_node* __find_c(void* __c) const;
165     void unlock() const;
166
167     void swap(void* __c1, void* __c2);
168
169
170     bool __dereferenceable(const void* __i) const;
171     bool __decrementable(const void* __i) const;
172     bool __addable(const void* __i, ptrdiff_t __n) const;
173     bool __subscriptable(const void* __i, ptrdiff_t __n) const;
174     bool __comparable(const void* __i, const void* __j) const;
175 private:
176     _LIBCPP_HIDDEN
177     __i_node* __insert_iterator(void* __i);
178     _LIBCPP_HIDDEN
179     __i_node* __find_iterator(const void* __i) const;
180
181     friend _LIBCPP_FUNC_VIS __libcpp_db* __get_db();
182 };
183
184 _LIBCPP_FUNC_VIS __libcpp_db* __get_db();
185 _LIBCPP_FUNC_VIS const __libcpp_db* __get_const_db();
186
187
188 _LIBCPP_END_NAMESPACE_STD
189
190 #endif
191
192 #endif  // _LIBCPP_DEBUG_H
193