1f554add5SHoward Hinnant// -*- C++ -*-
2f554add5SHoward Hinnant//===--------------------------- __debug ----------------------------------===//
3f554add5SHoward Hinnant//
4f554add5SHoward Hinnant//                     The LLVM Compiler Infrastructure
5f554add5SHoward Hinnant//
6f554add5SHoward Hinnant// This file is dual licensed under the MIT and the University of Illinois Open
7f554add5SHoward Hinnant// Source Licenses. See LICENSE.TXT for details.
8f554add5SHoward Hinnant//
9f554add5SHoward Hinnant//===----------------------------------------------------------------------===//
10f554add5SHoward Hinnant
11f554add5SHoward Hinnant#ifndef _LIBCPP_DEBUG_H
12f554add5SHoward Hinnant#define _LIBCPP_DEBUG_H
13f554add5SHoward Hinnant
14*fc88dbd2SHoward Hinnant#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15*fc88dbd2SHoward Hinnant#pragma GCC system_header
16*fc88dbd2SHoward Hinnant#endif
17*fc88dbd2SHoward Hinnant
18cec9af9eSHoward Hinnant#if _LIBCPP_DEBUG_LEVEL >= 1
19cec9af9eSHoward Hinnant
20f554add5SHoward Hinnant#   include <cstdlib>
21f554add5SHoward Hinnant#   include <cstdio>
22f554add5SHoward Hinnant#   include <cstddef>
2392bd7c03SHoward Hinnant#   ifndef _LIBCPP_ASSERT
24f554add5SHoward Hinnant#      define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : (_VSTD::printf("%s\n", m), _VSTD::abort()))
2592bd7c03SHoward Hinnant#   endif
26f554add5SHoward Hinnant
27cec9af9eSHoward Hinnant#endif
28cec9af9eSHoward Hinnant
29cec9af9eSHoward Hinnant#if _LIBCPP_DEBUG_LEVEL >= 2
30cec9af9eSHoward Hinnant
31f554add5SHoward Hinnant_LIBCPP_BEGIN_NAMESPACE_STD
32f554add5SHoward Hinnant
336e41256fSHoward Hinnantstruct _LIBCPP_TYPE_VIS __c_node;
34f554add5SHoward Hinnant
356e41256fSHoward Hinnantstruct _LIBCPP_TYPE_VIS __i_node
36f554add5SHoward Hinnant{
37f554add5SHoward Hinnant    void* __i_;
38f554add5SHoward Hinnant    __i_node* __next_;
39f554add5SHoward Hinnant    __c_node* __c_;
40f554add5SHoward Hinnant
41*fc88dbd2SHoward Hinnant#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
42f554add5SHoward Hinnant    __i_node(const __i_node&) = delete;
43f554add5SHoward Hinnant    __i_node& operator=(const __i_node&) = delete;
44*fc88dbd2SHoward Hinnant#else
45*fc88dbd2SHoward Hinnantprivate:
46*fc88dbd2SHoward Hinnant    __i_node(const __i_node&);
47*fc88dbd2SHoward Hinnant    __i_node& operator=(const __i_node&);
48*fc88dbd2SHoward Hinnantpublic:
49*fc88dbd2SHoward Hinnant#endif
50f554add5SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
51f554add5SHoward Hinnant    __i_node(void* __i, __i_node* __next, __c_node* __c)
52f554add5SHoward Hinnant        : __i_(__i), __next_(__next), __c_(__c) {}
53f554add5SHoward Hinnant    ~__i_node();
54f554add5SHoward Hinnant};
55f554add5SHoward Hinnant
566e41256fSHoward Hinnantstruct _LIBCPP_TYPE_VIS __c_node
57f554add5SHoward Hinnant{
58f554add5SHoward Hinnant    void* __c_;
59f554add5SHoward Hinnant    __c_node* __next_;
60f554add5SHoward Hinnant    __i_node** beg_;
61f554add5SHoward Hinnant    __i_node** end_;
62f554add5SHoward Hinnant    __i_node** cap_;
63f554add5SHoward Hinnant
64*fc88dbd2SHoward Hinnant#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
65f554add5SHoward Hinnant    __c_node(const __c_node&) = delete;
66f554add5SHoward Hinnant    __c_node& operator=(const __c_node&) = delete;
67*fc88dbd2SHoward Hinnant#else
68*fc88dbd2SHoward Hinnantprivate:
69*fc88dbd2SHoward Hinnant    __c_node(const __c_node&);
70*fc88dbd2SHoward Hinnant    __c_node& operator=(const __c_node&);
71*fc88dbd2SHoward Hinnantpublic:
72*fc88dbd2SHoward Hinnant#endif
73f554add5SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
74f554add5SHoward Hinnant    __c_node(void* __c, __c_node* __next)
75f554add5SHoward Hinnant        : __c_(__c), __next_(__next), beg_(nullptr), end_(nullptr), cap_(nullptr) {}
76f554add5SHoward Hinnant    virtual ~__c_node();
77f554add5SHoward Hinnant
78f554add5SHoward Hinnant    virtual bool __dereferenceable(const void*) const = 0;
79f554add5SHoward Hinnant    virtual bool __decrementable(const void*) const = 0;
80f554add5SHoward Hinnant    virtual bool __addable(const void*, ptrdiff_t) const = 0;
81f554add5SHoward Hinnant    virtual bool __subscriptable(const void*, ptrdiff_t) const = 0;
82f554add5SHoward Hinnant
83920b56caSHoward Hinnant    void __add(__i_node* __i);
84f554add5SHoward Hinnant    _LIBCPP_HIDDEN void __remove(__i_node* __i);
85f554add5SHoward Hinnant};
86f554add5SHoward Hinnant
87f554add5SHoward Hinnanttemplate <class _Cont>
88f554add5SHoward Hinnantstruct _C_node
89f554add5SHoward Hinnant    : public __c_node
90f554add5SHoward Hinnant{
91f554add5SHoward Hinnant    _C_node(void* __c, __c_node* __n)
92f554add5SHoward Hinnant        : __c_node(__c, __n) {}
93f554add5SHoward Hinnant
94f554add5SHoward Hinnant    virtual bool __dereferenceable(const void*) const;
95f554add5SHoward Hinnant    virtual bool __decrementable(const void*) const;
96f554add5SHoward Hinnant    virtual bool __addable(const void*, ptrdiff_t) const;
97f554add5SHoward Hinnant    virtual bool __subscriptable(const void*, ptrdiff_t) const;
98f554add5SHoward Hinnant};
99f554add5SHoward Hinnant
100f554add5SHoward Hinnanttemplate <class _Cont>
101f554add5SHoward Hinnantbool
102f554add5SHoward Hinnant_C_node<_Cont>::__dereferenceable(const void* __i) const
103f554add5SHoward Hinnant{
104f554add5SHoward Hinnant    typedef typename _Cont::const_iterator iterator;
105f554add5SHoward Hinnant    const iterator* __j = static_cast<const iterator*>(__i);
106c003db1fSHoward Hinnant    _Cont* _Cp = static_cast<_Cont*>(__c_);
107c003db1fSHoward Hinnant    return _Cp->__dereferenceable(__j);
108f554add5SHoward Hinnant}
109f554add5SHoward Hinnant
110f554add5SHoward Hinnanttemplate <class _Cont>
111f554add5SHoward Hinnantbool
112f554add5SHoward Hinnant_C_node<_Cont>::__decrementable(const void* __i) const
113f554add5SHoward Hinnant{
114f554add5SHoward Hinnant    typedef typename _Cont::const_iterator iterator;
115f554add5SHoward Hinnant    const iterator* __j = static_cast<const iterator*>(__i);
116c003db1fSHoward Hinnant    _Cont* _Cp = static_cast<_Cont*>(__c_);
117c003db1fSHoward Hinnant    return _Cp->__decrementable(__j);
118f554add5SHoward Hinnant}
119f554add5SHoward Hinnant
120f554add5SHoward Hinnanttemplate <class _Cont>
121f554add5SHoward Hinnantbool
122f554add5SHoward Hinnant_C_node<_Cont>::__addable(const void* __i, ptrdiff_t __n) const
123f554add5SHoward Hinnant{
124f554add5SHoward Hinnant    typedef typename _Cont::const_iterator iterator;
125f554add5SHoward Hinnant    const iterator* __j = static_cast<const iterator*>(__i);
126c003db1fSHoward Hinnant    _Cont* _Cp = static_cast<_Cont*>(__c_);
127c003db1fSHoward Hinnant    return _Cp->__addable(__j, __n);
128f554add5SHoward Hinnant}
129f554add5SHoward Hinnant
130f554add5SHoward Hinnanttemplate <class _Cont>
131f554add5SHoward Hinnantbool
132f554add5SHoward Hinnant_C_node<_Cont>::__subscriptable(const void* __i, ptrdiff_t __n) const
133f554add5SHoward Hinnant{
134f554add5SHoward Hinnant    typedef typename _Cont::const_iterator iterator;
135f554add5SHoward Hinnant    const iterator* __j = static_cast<const iterator*>(__i);
136c003db1fSHoward Hinnant    _Cont* _Cp = static_cast<_Cont*>(__c_);
137c003db1fSHoward Hinnant    return _Cp->__subscriptable(__j, __n);
138f554add5SHoward Hinnant}
139f554add5SHoward Hinnant
1406e41256fSHoward Hinnantclass _LIBCPP_TYPE_VIS __libcpp_db
141f554add5SHoward Hinnant{
142f554add5SHoward Hinnant    __c_node** __cbeg_;
143f554add5SHoward Hinnant    __c_node** __cend_;
144f554add5SHoward Hinnant    size_t   __csz_;
145f554add5SHoward Hinnant    __i_node** __ibeg_;
146f554add5SHoward Hinnant    __i_node** __iend_;
147f554add5SHoward Hinnant    size_t   __isz_;
148f554add5SHoward Hinnant
149f554add5SHoward Hinnant    __libcpp_db();
150f554add5SHoward Hinnantpublic:
151*fc88dbd2SHoward Hinnant#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
152f554add5SHoward Hinnant    __libcpp_db(const __libcpp_db&) = delete;
153f554add5SHoward Hinnant    __libcpp_db& operator=(const __libcpp_db&) = delete;
154*fc88dbd2SHoward Hinnant#else
155*fc88dbd2SHoward Hinnantprivate:
156*fc88dbd2SHoward Hinnant    __libcpp_db(const __libcpp_db&);
157*fc88dbd2SHoward Hinnant    __libcpp_db& operator=(const __libcpp_db&);
158*fc88dbd2SHoward Hinnantpublic:
159*fc88dbd2SHoward Hinnant#endif
160f554add5SHoward Hinnant    ~__libcpp_db();
161f554add5SHoward Hinnant
162f554add5SHoward Hinnant    class __db_c_iterator;
163f554add5SHoward Hinnant    class __db_c_const_iterator;
164f554add5SHoward Hinnant    class __db_i_iterator;
165f554add5SHoward Hinnant    class __db_i_const_iterator;
166f554add5SHoward Hinnant
167f554add5SHoward Hinnant    __db_c_const_iterator __c_end() const;
168f554add5SHoward Hinnant    __db_i_const_iterator __i_end() const;
169f554add5SHoward Hinnant
170f554add5SHoward Hinnant    template <class _Cont>
171f554add5SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
172f554add5SHoward Hinnant    void __insert_c(_Cont* __c)
173f554add5SHoward Hinnant    {
174f554add5SHoward Hinnant        __c_node* __n = __insert_c(static_cast<void*>(__c));
175f554add5SHoward Hinnant        ::new(__n) _C_node<_Cont>(__n->__c_, __n->__next_);
176f554add5SHoward Hinnant    }
177f554add5SHoward Hinnant
178c36bfc49SHoward Hinnant    void __insert_i(void* __i);
179f554add5SHoward Hinnant    __c_node* __insert_c(void* __c);
180f554add5SHoward Hinnant    void __erase_c(void* __c);
181f554add5SHoward Hinnant
182f554add5SHoward Hinnant    void __insert_ic(void* __i, const void* __c);
183f554add5SHoward Hinnant    void __iterator_copy(void* __i, const void* __i0);
184f554add5SHoward Hinnant    void __erase_i(void* __i);
185f554add5SHoward Hinnant
186f554add5SHoward Hinnant    void* __find_c_from_i(void* __i) const;
187f554add5SHoward Hinnant    void __invalidate_all(void* __c);
188f554add5SHoward Hinnant    __c_node* __find_c_and_lock(void* __c) const;
189920b56caSHoward Hinnant    __c_node* __find_c(void* __c) const;
190f554add5SHoward Hinnant    void unlock() const;
191f554add5SHoward Hinnant
192f554add5SHoward Hinnant    void swap(void* __c1, void* __c2);
193f554add5SHoward Hinnant
194f554add5SHoward Hinnant
195f554add5SHoward Hinnant    bool __dereferenceable(const void* __i) const;
196f554add5SHoward Hinnant    bool __decrementable(const void* __i) const;
197f554add5SHoward Hinnant    bool __addable(const void* __i, ptrdiff_t __n) const;
198f554add5SHoward Hinnant    bool __subscriptable(const void* __i, ptrdiff_t __n) const;
19942a3046eSHoward Hinnant    bool __less_than_comparable(const void* __i, const void* __j) const;
200f554add5SHoward Hinnantprivate:
201f554add5SHoward Hinnant    _LIBCPP_HIDDEN
202f554add5SHoward Hinnant    __i_node* __insert_iterator(void* __i);
203f554add5SHoward Hinnant    _LIBCPP_HIDDEN
204f554add5SHoward Hinnant    __i_node* __find_iterator(const void* __i) const;
205f554add5SHoward Hinnant
2066e41256fSHoward Hinnant    friend _LIBCPP_FUNC_VIS __libcpp_db* __get_db();
207f554add5SHoward Hinnant};
208f554add5SHoward Hinnant
2096e41256fSHoward Hinnant_LIBCPP_FUNC_VIS __libcpp_db* __get_db();
2106e41256fSHoward Hinnant_LIBCPP_FUNC_VIS const __libcpp_db* __get_const_db();
211f554add5SHoward Hinnant
212f554add5SHoward Hinnant
213f554add5SHoward Hinnant_LIBCPP_END_NAMESPACE_STD
214f554add5SHoward Hinnant
215cec9af9eSHoward Hinnant#endif
216cec9af9eSHoward Hinnant
217f554add5SHoward Hinnant#endif  // _LIBCPP_DEBUG_H
218f554add5SHoward Hinnant
219