fixed: gcc8 compile issues
[opensg.git] / Source / Contrib / ComplexSceneManager / External / boost / circular_buffer / debug.hpp
blob7f99659f5f7a7db996a930e2e1830cd838d62781
1 // Debug support for the circular buffer library.
3 // Copyright (c) 2003-2008 Jan Gaspar
5 // Use, modification, and distribution is subject to the Boost Software
6 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 #if !defined(BOOST_CIRCULAR_BUFFER_DEBUG_HPP)
10 #define BOOST_CIRCULAR_BUFFER_DEBUG_HPP
12 #if defined(_MSC_VER) && _MSC_VER >= 1200
13 #pragma once
14 #endif
16 namespace boost {
18 namespace cb_details {
20 #if BOOST_CB_ENABLE_DEBUG
22 // The value the uninitialized memory is filled with.
23 const int UNINITIALIZED = 0xcc;
25 class debug_iterator_registry;
27 /*!
28 \class debug_iterator_base
29 \brief Registers/unregisters iterators into the registry of valid iterators.
31 This class is intended to be a base class of an iterator.
33 class debug_iterator_base {
35 private:
36 // Members
38 //! Iterator registry.
39 mutable const debug_iterator_registry* m_registry;
41 //! Next iterator in the iterator chain.
42 mutable const debug_iterator_base* m_next;
44 public:
45 // Construction/destruction
47 //! Default constructor.
48 debug_iterator_base();
50 //! Constructor taking the iterator registry as a parameter.
51 debug_iterator_base(const debug_iterator_registry* registry);
53 //! Copy constructor.
54 debug_iterator_base(const debug_iterator_base& rhs);
56 //! Destructor.
57 ~debug_iterator_base();
59 // Methods
61 //! Assign operator.
62 debug_iterator_base& operator = (const debug_iterator_base& rhs);
64 //! Is the iterator valid?
65 bool is_valid(const debug_iterator_registry* registry) const;
67 //! Invalidate the iterator.
68 /*!
69 \note The method is const in order to invalidate const iterators, too.
71 void invalidate() const;
73 //! Return the next iterator in the iterator chain.
74 const debug_iterator_base* next() const;
76 //! Set the next iterator in the iterator chain.
77 /*!
78 \note The method is const in order to set a next iterator to a const iterator, too.
80 void set_next(const debug_iterator_base* it) const;
82 private:
83 // Helpers
85 //! Register self as a valid iterator.
86 void register_self();
88 //! Unregister self from valid iterators.
89 void unregister_self();
92 /*!
93 \class debug_iterator_registry
94 \brief Registry of valid iterators.
96 This class is intended to be a base class of a container.
98 class debug_iterator_registry {
100 //! Pointer to the chain of valid iterators.
101 mutable const debug_iterator_base* m_iterators;
103 public:
104 // Methods
106 //! Default constructor.
107 debug_iterator_registry() : m_iterators(0) {}
109 //! Register an iterator into the list of valid iterators.
111 \note The method is const in order to register iterators into const containers, too.
113 void register_iterator(const debug_iterator_base* it) const {
114 it->set_next(m_iterators);
115 m_iterators = it;
118 //! Unregister an iterator from the list of valid iterators.
120 \note The method is const in order to unregister iterators from const containers, too.
122 void unregister_iterator(const debug_iterator_base* it) const {
123 const debug_iterator_base* previous = 0;
124 for (const debug_iterator_base* p = m_iterators; p != it; previous = p, p = p->next()) {}
125 remove(it, previous);
128 //! Invalidate every iterator pointing to the same element as the iterator passed as a parameter.
129 template <class Iterator>
130 void invalidate_iterators(const Iterator& it) {
131 const debug_iterator_base* previous = 0;
132 for (const debug_iterator_base* p = m_iterators; p != 0; p = p->next()) {
133 if (static_cast<Iterator*>(p)->m_it == it.m_it) {
134 p->invalidate();
135 remove(p, previous);
136 continue;
138 previous = p;
142 //! Invalidate all iterators except an iterator poining to the same element as the iterator passed as a parameter.
143 template <class Iterator>
144 void invalidate_iterators_except(const Iterator& it) {
145 const debug_iterator_base* previous = 0;
146 for (const debug_iterator_base* p = m_iterators; p != 0; p = p->next()) {
147 if (static_cast<Iterator*>(p)->m_it != it.m_it) {
148 p->invalidate();
149 remove(p, previous);
150 continue;
152 previous = p;
156 //! Invalidate all iterators.
157 void invalidate_all_iterators() {
158 for (const debug_iterator_base* p = m_iterators; p != 0; p = p->next())
159 p->invalidate();
160 m_iterators = 0;
163 private:
164 // Helpers
166 //! Remove the current iterator from the iterator chain.
167 void remove(const debug_iterator_base* current,
168 const debug_iterator_base* previous) const {
169 if (previous == 0)
170 m_iterators = m_iterators->next();
171 else
172 previous->set_next(current->next());
176 // Implementation of the debug_iterator_base methods.
178 inline debug_iterator_base::debug_iterator_base() : m_registry(0), m_next(0) {}
180 inline debug_iterator_base::debug_iterator_base(const debug_iterator_registry* registry)
181 : m_registry(registry), m_next(0) {
182 register_self();
185 inline debug_iterator_base::debug_iterator_base(const debug_iterator_base& rhs)
186 : m_registry(rhs.m_registry), m_next(0) {
187 register_self();
190 inline debug_iterator_base::~debug_iterator_base() { unregister_self(); }
192 inline debug_iterator_base& debug_iterator_base::operator = (const debug_iterator_base& rhs) {
193 if (m_registry == rhs.m_registry)
194 return *this;
195 unregister_self();
196 m_registry = rhs.m_registry;
197 register_self();
198 return *this;
201 inline bool debug_iterator_base::is_valid(const debug_iterator_registry* registry) const {
202 return m_registry == registry;
205 inline void debug_iterator_base::invalidate() const { m_registry = 0; }
207 inline const debug_iterator_base* debug_iterator_base::next() const { return m_next; }
209 inline void debug_iterator_base::set_next(const debug_iterator_base* it) const { m_next = it; }
211 inline void debug_iterator_base::register_self() {
212 if (m_registry != 0)
213 m_registry->register_iterator(this);
216 inline void debug_iterator_base::unregister_self() {
217 if (m_registry != 0)
218 m_registry->unregister_iterator(this);
221 #endif // #if BOOST_CB_ENABLE_DEBUG
223 } // namespace cb_details
225 } // namespace boost
227 #endif // #if !defined(BOOST_CIRCULAR_BUFFER_DEBUG_HPP)