__debug revision 249998
1227825Stheraven// -*- C++ -*-
2227825Stheraven//===--------------------------- __debug ----------------------------------===//
3227825Stheraven//
4227825Stheraven//                     The LLVM Compiler Infrastructure
5227825Stheraven//
6227825Stheraven// This file is dual licensed under the MIT and the University of Illinois Open
7227825Stheraven// Source Licenses. See LICENSE.TXT for details.
8227825Stheraven//
9227825Stheraven//===----------------------------------------------------------------------===//
10227825Stheraven
11227825Stheraven#ifndef _LIBCPP_DEBUG_H
12227825Stheraven#define _LIBCPP_DEBUG_H
13227825Stheraven
14227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 1
15227825Stheraven
16227825Stheraven#   include <cstdlib>
17227825Stheraven#   include <cstdio>
18227825Stheraven#   include <cstddef>
19249998Sdim#   ifndef _LIBCPP_ASSERT
20249998Sdim#      define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : (_VSTD::printf("%s\n", m), _VSTD::abort()))
21249998Sdim#   endif
22227825Stheraven
23227825Stheraven#endif
24227825Stheraven
25227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
26227825Stheraven
27227825Stheraven_LIBCPP_BEGIN_NAMESPACE_STD
28227825Stheraven
29249998Sdimstruct _LIBCPP_TYPE_VIS __c_node;
30227825Stheraven
31249998Sdimstruct _LIBCPP_TYPE_VIS __i_node
32227825Stheraven{
33227825Stheraven    void* __i_;
34227825Stheraven    __i_node* __next_;
35227825Stheraven    __c_node* __c_;
36227825Stheraven
37227825Stheraven    __i_node(const __i_node&) = delete;
38227825Stheraven    __i_node& operator=(const __i_node&) = delete;
39227825Stheraven    _LIBCPP_INLINE_VISIBILITY
40227825Stheraven    __i_node(void* __i, __i_node* __next, __c_node* __c)
41227825Stheraven        : __i_(__i), __next_(__next), __c_(__c) {}
42227825Stheraven    ~__i_node();
43227825Stheraven};
44227825Stheraven
45249998Sdimstruct _LIBCPP_TYPE_VIS __c_node
46227825Stheraven{
47227825Stheraven    void* __c_;
48227825Stheraven    __c_node* __next_;
49227825Stheraven    __i_node** beg_;
50227825Stheraven    __i_node** end_;
51227825Stheraven    __i_node** cap_;
52227825Stheraven
53227825Stheraven    __c_node(const __c_node&) = delete;
54227825Stheraven    __c_node& operator=(const __c_node&) = delete;
55227825Stheraven    _LIBCPP_INLINE_VISIBILITY
56227825Stheraven    __c_node(void* __c, __c_node* __next)
57227825Stheraven        : __c_(__c), __next_(__next), beg_(nullptr), end_(nullptr), cap_(nullptr) {}
58227825Stheraven    virtual ~__c_node();
59227825Stheraven
60227825Stheraven    virtual bool __dereferenceable(const void*) const = 0;
61227825Stheraven    virtual bool __decrementable(const void*) const = 0;
62227825Stheraven    virtual bool __addable(const void*, ptrdiff_t) const = 0;
63227825Stheraven    virtual bool __subscriptable(const void*, ptrdiff_t) const = 0;
64227825Stheraven
65227825Stheraven    void __add(__i_node* __i);
66227825Stheraven    _LIBCPP_HIDDEN void __remove(__i_node* __i);
67227825Stheraven};
68227825Stheraven
69227825Stheraventemplate <class _Cont>
70227825Stheravenstruct _C_node
71227825Stheraven    : public __c_node
72227825Stheraven{
73227825Stheraven    _C_node(void* __c, __c_node* __n)
74227825Stheraven        : __c_node(__c, __n) {}
75227825Stheraven
76227825Stheraven    virtual bool __dereferenceable(const void*) const;
77227825Stheraven    virtual bool __decrementable(const void*) const;
78227825Stheraven    virtual bool __addable(const void*, ptrdiff_t) const;
79227825Stheraven    virtual bool __subscriptable(const void*, ptrdiff_t) const;
80227825Stheraven};
81227825Stheraven
82227825Stheraventemplate <class _Cont>
83227825Stheravenbool
84227825Stheraven_C_node<_Cont>::__dereferenceable(const void* __i) const
85227825Stheraven{
86227825Stheraven    typedef typename _Cont::const_iterator iterator;
87227825Stheraven    const iterator* __j = static_cast<const iterator*>(__i);
88232950Stheraven    _Cont* _Cp = static_cast<_Cont*>(__c_);
89232950Stheraven    return _Cp->__dereferenceable(__j);
90227825Stheraven}
91227825Stheraven
92227825Stheraventemplate <class _Cont>
93227825Stheravenbool
94227825Stheraven_C_node<_Cont>::__decrementable(const void* __i) const
95227825Stheraven{
96227825Stheraven    typedef typename _Cont::const_iterator iterator;
97227825Stheraven    const iterator* __j = static_cast<const iterator*>(__i);
98232950Stheraven    _Cont* _Cp = static_cast<_Cont*>(__c_);
99232950Stheraven    return _Cp->__decrementable(__j);
100227825Stheraven}
101227825Stheraven
102227825Stheraventemplate <class _Cont>
103227825Stheravenbool
104227825Stheraven_C_node<_Cont>::__addable(const void* __i, ptrdiff_t __n) const
105227825Stheraven{
106227825Stheraven    typedef typename _Cont::const_iterator iterator;
107227825Stheraven    const iterator* __j = static_cast<const iterator*>(__i);
108232950Stheraven    _Cont* _Cp = static_cast<_Cont*>(__c_);
109232950Stheraven    return _Cp->__addable(__j, __n);
110227825Stheraven}
111227825Stheraven
112227825Stheraventemplate <class _Cont>
113227825Stheravenbool
114227825Stheraven_C_node<_Cont>::__subscriptable(const void* __i, ptrdiff_t __n) const
115227825Stheraven{
116227825Stheraven    typedef typename _Cont::const_iterator iterator;
117227825Stheraven    const iterator* __j = static_cast<const iterator*>(__i);
118232950Stheraven    _Cont* _Cp = static_cast<_Cont*>(__c_);
119232950Stheraven    return _Cp->__subscriptable(__j, __n);
120227825Stheraven}
121227825Stheraven
122249998Sdimclass _LIBCPP_TYPE_VIS __libcpp_db
123227825Stheraven{
124227825Stheraven    __c_node** __cbeg_;
125227825Stheraven    __c_node** __cend_;
126227825Stheraven    size_t   __csz_;
127227825Stheraven    __i_node** __ibeg_;
128227825Stheraven    __i_node** __iend_;
129227825Stheraven    size_t   __isz_;
130227825Stheraven
131227825Stheraven    __libcpp_db();
132227825Stheravenpublic:
133227825Stheraven    __libcpp_db(const __libcpp_db&) = delete;
134227825Stheraven    __libcpp_db& operator=(const __libcpp_db&) = delete;
135227825Stheraven    ~__libcpp_db();
136227825Stheraven
137227825Stheraven    class __db_c_iterator;
138227825Stheraven    class __db_c_const_iterator;
139227825Stheraven    class __db_i_iterator;
140227825Stheraven    class __db_i_const_iterator;
141227825Stheraven
142227825Stheraven    __db_c_const_iterator __c_end() const;
143227825Stheraven    __db_i_const_iterator __i_end() const;
144227825Stheraven
145227825Stheraven    template <class _Cont>
146227825Stheraven    _LIBCPP_INLINE_VISIBILITY
147227825Stheraven    void __insert_c(_Cont* __c)
148227825Stheraven    {
149227825Stheraven        __c_node* __n = __insert_c(static_cast<void*>(__c));
150227825Stheraven        ::new(__n) _C_node<_Cont>(__n->__c_, __n->__next_);
151227825Stheraven    }
152227825Stheraven
153227825Stheraven    void __insert_i(void* __i);
154227825Stheraven    __c_node* __insert_c(void* __c);
155227825Stheraven    void __erase_c(void* __c);
156227825Stheraven
157227825Stheraven    void __insert_ic(void* __i, const void* __c);
158227825Stheraven    void __iterator_copy(void* __i, const void* __i0);
159227825Stheraven    void __erase_i(void* __i);
160227825Stheraven
161227825Stheraven    void* __find_c_from_i(void* __i) const;
162227825Stheraven    void __invalidate_all(void* __c);
163227825Stheraven    __c_node* __find_c_and_lock(void* __c) const;
164227825Stheraven    __c_node* __find_c(void* __c) const;
165227825Stheraven    void unlock() const;
166227825Stheraven
167227825Stheraven    void swap(void* __c1, void* __c2);
168227825Stheraven
169227825Stheraven
170227825Stheraven    bool __dereferenceable(const void* __i) const;
171227825Stheraven    bool __decrementable(const void* __i) const;
172227825Stheraven    bool __addable(const void* __i, ptrdiff_t __n) const;
173227825Stheraven    bool __subscriptable(const void* __i, ptrdiff_t __n) const;
174227825Stheraven    bool __comparable(const void* __i, const void* __j) const;
175227825Stheravenprivate:
176227825Stheraven    _LIBCPP_HIDDEN
177227825Stheraven    __i_node* __insert_iterator(void* __i);
178227825Stheraven    _LIBCPP_HIDDEN
179227825Stheraven    __i_node* __find_iterator(const void* __i) const;
180227825Stheraven
181249998Sdim    friend _LIBCPP_FUNC_VIS __libcpp_db* __get_db();
182227825Stheraven};
183227825Stheraven
184249998Sdim_LIBCPP_FUNC_VIS __libcpp_db* __get_db();
185249998Sdim_LIBCPP_FUNC_VIS const __libcpp_db* __get_const_db();
186227825Stheraven
187227825Stheraven
188227825Stheraven_LIBCPP_END_NAMESPACE_STD
189227825Stheraven
190227825Stheraven#endif
191227825Stheraven
192227825Stheraven#endif  // _LIBCPP_DEBUG_H
193227825Stheraven
194