File indexing completed on 2025-01-30 09:34:29
0001
0002
0003
0004
0005
0006
0007
0008
0009 #if !defined(BOOST_CIRCULAR_BUFFER_DEBUG_HPP)
0010 #define BOOST_CIRCULAR_BUFFER_DEBUG_HPP
0011
0012 #if defined(_MSC_VER)
0013 #pragma once
0014 #endif
0015
0016 #if BOOST_CB_ENABLE_DEBUG
0017 #include <cstring>
0018
0019 #if defined(BOOST_NO_STDC_NAMESPACE)
0020 namespace std {
0021 using ::memset;
0022 }
0023 #endif
0024
0025 #endif
0026 namespace boost {
0027
0028 namespace cb_details {
0029
0030 #if BOOST_CB_ENABLE_DEBUG
0031
0032
0033 const int UNINITIALIZED = 0xcc;
0034
0035 template <class T>
0036 inline void do_fill_uninitialized_memory(T* data, std::size_t size_in_bytes) BOOST_NOEXCEPT {
0037 std::memset(static_cast<void*>(data), UNINITIALIZED, size_in_bytes);
0038 }
0039
0040 template <class T>
0041 inline void do_fill_uninitialized_memory(T& , std::size_t ) BOOST_NOEXCEPT {
0042
0043 }
0044
0045
0046 class debug_iterator_registry;
0047
0048
0049
0050
0051
0052
0053
0054 class debug_iterator_base {
0055
0056 private:
0057
0058
0059
0060 mutable const debug_iterator_registry* m_registry;
0061
0062
0063 mutable const debug_iterator_base* m_next;
0064
0065 public:
0066
0067
0068
0069 debug_iterator_base();
0070
0071
0072 debug_iterator_base(const debug_iterator_registry* registry);
0073
0074
0075 debug_iterator_base(const debug_iterator_base& rhs);
0076
0077
0078 ~debug_iterator_base();
0079
0080
0081
0082
0083 debug_iterator_base& operator = (const debug_iterator_base& rhs);
0084
0085
0086 bool is_valid(const debug_iterator_registry* registry) const;
0087
0088
0089
0090
0091
0092 void invalidate() const;
0093
0094
0095 const debug_iterator_base* next() const;
0096
0097
0098
0099
0100
0101 void set_next(const debug_iterator_base* it) const;
0102
0103 private:
0104
0105
0106
0107 void register_self();
0108
0109
0110 void unregister_self();
0111 };
0112
0113
0114
0115
0116
0117
0118
0119 class debug_iterator_registry {
0120
0121
0122 mutable const debug_iterator_base* m_iterators;
0123
0124 public:
0125
0126
0127
0128 debug_iterator_registry() : m_iterators(0) {}
0129
0130
0131
0132
0133
0134 void register_iterator(const debug_iterator_base* it) const {
0135 it->set_next(m_iterators);
0136 m_iterators = it;
0137 }
0138
0139
0140
0141
0142
0143 void unregister_iterator(const debug_iterator_base* it) const {
0144 const debug_iterator_base* previous = 0;
0145 for (const debug_iterator_base* p = m_iterators; p != it; previous = p, p = p->next()) {}
0146 remove(it, previous);
0147 }
0148
0149
0150 template <class Iterator>
0151 void invalidate_iterators(const Iterator& it) {
0152 const debug_iterator_base* previous = 0;
0153 for (const debug_iterator_base* p = m_iterators; p != 0; p = p->next()) {
0154 if (((Iterator*)p)->m_it == it.m_it) {
0155 p->invalidate();
0156 remove(p, previous);
0157 continue;
0158 }
0159 previous = p;
0160 }
0161 }
0162
0163
0164 template <class Iterator>
0165 void invalidate_iterators_except(const Iterator& it) {
0166 const debug_iterator_base* previous = 0;
0167 for (const debug_iterator_base* p = m_iterators; p != 0; p = p->next()) {
0168 if (((Iterator*)p)->m_it != it.m_it) {
0169 p->invalidate();
0170 remove(p, previous);
0171 continue;
0172 }
0173 previous = p;
0174 }
0175 }
0176
0177
0178 void invalidate_all_iterators() {
0179 for (const debug_iterator_base* p = m_iterators; p != 0; p = p->next())
0180 p->invalidate();
0181 m_iterators = 0;
0182 }
0183
0184 private:
0185
0186
0187
0188 void remove(const debug_iterator_base* current,
0189 const debug_iterator_base* previous) const {
0190 if (previous == 0)
0191 m_iterators = m_iterators->next();
0192 else
0193 previous->set_next(current->next());
0194 }
0195 };
0196
0197
0198
0199 inline debug_iterator_base::debug_iterator_base() : m_registry(0), m_next(0) {}
0200
0201 inline debug_iterator_base::debug_iterator_base(const debug_iterator_registry* registry)
0202 : m_registry(registry), m_next(0) {
0203 register_self();
0204 }
0205
0206 inline debug_iterator_base::debug_iterator_base(const debug_iterator_base& rhs)
0207 : m_registry(rhs.m_registry), m_next(0) {
0208 register_self();
0209 }
0210
0211 inline debug_iterator_base::~debug_iterator_base() { unregister_self(); }
0212
0213 inline debug_iterator_base& debug_iterator_base::operator = (const debug_iterator_base& rhs) {
0214 if (m_registry == rhs.m_registry)
0215 return *this;
0216 unregister_self();
0217 m_registry = rhs.m_registry;
0218 register_self();
0219 return *this;
0220 }
0221
0222 inline bool debug_iterator_base::is_valid(const debug_iterator_registry* registry) const {
0223 return m_registry == registry;
0224 }
0225
0226 inline void debug_iterator_base::invalidate() const { m_registry = 0; }
0227
0228 inline const debug_iterator_base* debug_iterator_base::next() const { return m_next; }
0229
0230 inline void debug_iterator_base::set_next(const debug_iterator_base* it) const { m_next = it; }
0231
0232 inline void debug_iterator_base::register_self() {
0233 if (m_registry != 0)
0234 m_registry->register_iterator(this);
0235 }
0236
0237 inline void debug_iterator_base::unregister_self() {
0238 if (m_registry != 0)
0239 m_registry->unregister_iterator(this);
0240 }
0241
0242 #endif
0243
0244 }
0245
0246 }
0247
0248 #endif