File indexing completed on 2025-01-18 09:51:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_RANGE_DETAIL_ANY_ITERATOR_WRAPPER_HPP_INCLUDED
0011 #define BOOST_RANGE_DETAIL_ANY_ITERATOR_WRAPPER_HPP_INCLUDED
0012
0013 #include <boost/polymorphic_cast.hpp>
0014 #include <boost/range/config.hpp>
0015 #include <boost/range/detail/any_iterator_interface.hpp>
0016 #include <boost/range/concepts.hpp>
0017
0018 namespace boost
0019 {
0020 namespace range_detail
0021 {
0022 template<typename TargetT, typename SourceT>
0023 TargetT& polymorphic_ref_downcast(SourceT& source)
0024 {
0025 #ifdef BOOST_NO_RTTI
0026 return static_cast<TargetT&>(source);
0027 #else
0028 return *boost::polymorphic_downcast<TargetT*>(&source);
0029 #endif
0030 }
0031
0032 template<class Reference, class T>
0033 Reference dereference_cast(T& x)
0034 {
0035 return static_cast<Reference>(x);
0036 }
0037 template<class Reference, class T>
0038 Reference dereference_cast(const T& x)
0039 {
0040 return static_cast<Reference>(const_cast<T&>(x));
0041 }
0042
0043 template<
0044 class WrappedIterator
0045 , class Reference
0046 , class Buffer
0047 >
0048 class any_incrementable_iterator_wrapper
0049 : public any_incrementable_iterator_interface<
0050 Reference
0051 , Buffer
0052 >
0053 {
0054 BOOST_RANGE_CONCEPT_ASSERT(( IncrementableIteratorConcept<WrappedIterator> ));
0055 public:
0056 typedef WrappedIterator wrapped_type;
0057
0058 BOOST_STATIC_ASSERT(( is_convertible<
0059 typename iterator_reference<WrappedIterator>::type
0060 , Reference
0061 >::value ));
0062
0063 any_incrementable_iterator_wrapper()
0064 : m_it()
0065 {}
0066
0067 explicit any_incrementable_iterator_wrapper(wrapped_type it)
0068 : m_it(it)
0069 {}
0070
0071
0072 virtual any_incrementable_iterator_wrapper* clone(
0073 typename any_incrementable_iterator_wrapper::buffer_type& buffer
0074 ) const
0075 {
0076 return new (buffer.allocate(sizeof(*this)))
0077 any_incrementable_iterator_wrapper(m_it);
0078 }
0079
0080 virtual any_incrementable_iterator_wrapper<
0081 WrappedIterator
0082 , typename any_incrementable_iterator_wrapper::const_reference
0083 , Buffer
0084 >* clone_const_ref(
0085 typename any_incrementable_iterator_wrapper::buffer_type& buffer
0086 ) const
0087 {
0088 typedef any_incrementable_iterator_wrapper<
0089 WrappedIterator
0090 , typename any_incrementable_iterator_wrapper::const_reference
0091 , Buffer
0092 > result_type;
0093
0094 return new (buffer.allocate(sizeof(result_type)))
0095 result_type(m_it);
0096 }
0097
0098 virtual any_incrementable_iterator_wrapper<
0099 WrappedIterator
0100 , typename any_incrementable_iterator_wrapper::reference_as_value_type
0101 , Buffer
0102 >* clone_reference_as_value(
0103 typename any_incrementable_iterator_wrapper::buffer_type& buffer
0104 ) const
0105 {
0106 typedef any_incrementable_iterator_wrapper<
0107 WrappedIterator
0108 , typename any_incrementable_iterator_wrapper::reference_as_value_type
0109 , Buffer
0110 > result_type;
0111
0112 return new (buffer.allocate(sizeof(result_type)))
0113 result_type(m_it);
0114 }
0115
0116 virtual void increment()
0117 {
0118 ++m_it;
0119 }
0120
0121 private:
0122 wrapped_type m_it;
0123 };
0124
0125 template<
0126 class WrappedIterator
0127 , class Reference
0128 , class Buffer
0129 >
0130 class any_single_pass_iterator_wrapper
0131 : public any_single_pass_iterator_interface<
0132 Reference
0133 , Buffer
0134 >
0135 {
0136 struct disabler {};
0137 BOOST_RANGE_CONCEPT_ASSERT(( SinglePassIteratorConcept<WrappedIterator> ));
0138 typedef any_single_pass_iterator_interface<
0139 Reference,
0140 Buffer
0141 > base_type;
0142
0143 public:
0144 typedef typename base_type::reference reference;
0145
0146 any_single_pass_iterator_wrapper()
0147 : m_it()
0148 {}
0149
0150 explicit any_single_pass_iterator_wrapper(const WrappedIterator& it)
0151 : m_it(it)
0152 {}
0153
0154 virtual any_single_pass_iterator_wrapper* clone(
0155 typename any_single_pass_iterator_wrapper::buffer_type& buffer
0156 ) const
0157 {
0158 return new (buffer.allocate(sizeof(*this)))
0159 any_single_pass_iterator_wrapper(m_it);
0160 }
0161
0162 virtual any_single_pass_iterator_wrapper<
0163 WrappedIterator
0164 , typename any_single_pass_iterator_wrapper::const_reference
0165 , Buffer
0166 >* clone_const_ref(
0167 typename any_single_pass_iterator_wrapper::buffer_type& buffer
0168 ) const
0169 {
0170 typedef any_single_pass_iterator_wrapper<
0171 WrappedIterator
0172 , typename any_single_pass_iterator_wrapper::const_reference
0173 , Buffer
0174 > result_type;
0175
0176 return new (buffer.allocate(sizeof(result_type)))
0177 result_type(m_it);
0178 }
0179
0180 virtual any_single_pass_iterator_wrapper<
0181 WrappedIterator
0182 , typename any_single_pass_iterator_wrapper::reference_as_value_type
0183 , Buffer
0184 >* clone_reference_as_value(
0185 typename any_single_pass_iterator_wrapper::buffer_type& buffer
0186 ) const
0187 {
0188 typedef any_single_pass_iterator_wrapper<
0189 WrappedIterator
0190 , typename any_single_pass_iterator_wrapper::reference_as_value_type
0191 , Buffer
0192 > result_type;
0193
0194 return new (buffer.allocate(sizeof(result_type)))
0195 result_type(m_it);
0196 }
0197
0198 virtual void increment()
0199 {
0200 ++m_it;
0201 }
0202
0203 virtual bool equal(const any_single_pass_iterator_interface<Reference, Buffer>& other) const
0204 {
0205 return m_it == range_detail::polymorphic_ref_downcast<const any_single_pass_iterator_wrapper>(other).m_it;
0206 }
0207
0208 virtual reference dereference() const
0209 {
0210 return dereference_cast<reference>(*m_it);
0211 }
0212
0213 private:
0214 WrappedIterator m_it;
0215 };
0216
0217 template<
0218 class WrappedIterator
0219 , class Reference
0220 , class Buffer
0221 >
0222 class any_forward_iterator_wrapper
0223 : public any_forward_iterator_interface<
0224 Reference
0225 , Buffer
0226 >
0227 {
0228 BOOST_RANGE_CONCEPT_ASSERT(( ForwardIteratorConcept<WrappedIterator> ));
0229 typedef any_forward_iterator_interface<
0230 Reference,
0231 Buffer
0232 > base_type;
0233
0234 public:
0235 typedef typename base_type::reference reference;
0236
0237 any_forward_iterator_wrapper()
0238 : m_it()
0239 {}
0240
0241 explicit any_forward_iterator_wrapper(const WrappedIterator& it)
0242 : m_it(it)
0243 {}
0244
0245
0246 virtual any_forward_iterator_wrapper* clone(
0247 typename any_forward_iterator_wrapper::buffer_type& buffer
0248 ) const
0249 {
0250 return new (buffer.allocate(sizeof(*this)))
0251 any_forward_iterator_wrapper(m_it);
0252 }
0253
0254 virtual any_forward_iterator_wrapper<
0255 WrappedIterator
0256 , typename any_forward_iterator_wrapper::const_reference
0257 , Buffer
0258 >* clone_const_ref(
0259 typename any_forward_iterator_wrapper::buffer_type& buffer
0260 ) const
0261 {
0262 typedef any_forward_iterator_wrapper<
0263 WrappedIterator
0264 , typename any_forward_iterator_wrapper::const_reference
0265 , Buffer
0266 > result_type;
0267
0268 return new (buffer.allocate(sizeof(result_type)))
0269 result_type(m_it);
0270 }
0271
0272 virtual any_forward_iterator_wrapper<
0273 WrappedIterator
0274 , typename any_forward_iterator_wrapper::reference_as_value_type
0275 , Buffer
0276 >* clone_reference_as_value(
0277 typename any_forward_iterator_wrapper::buffer_type& buffer
0278 ) const
0279 {
0280 typedef any_forward_iterator_wrapper<
0281 WrappedIterator
0282 , typename any_forward_iterator_wrapper::reference_as_value_type
0283 , Buffer
0284 > result_type;
0285
0286 return new (buffer.allocate(sizeof(result_type)))
0287 result_type(m_it);
0288 }
0289
0290 virtual void increment()
0291 {
0292 ++m_it;
0293 }
0294
0295 virtual bool equal(const any_single_pass_iterator_interface<Reference, Buffer>& other) const
0296 {
0297 return m_it == range_detail::polymorphic_ref_downcast<const any_forward_iterator_wrapper>(other).m_it;
0298 }
0299
0300 virtual reference dereference() const
0301 {
0302 return dereference_cast<reference>(*m_it);
0303 }
0304 private:
0305 WrappedIterator m_it;
0306 };
0307
0308 template<
0309 class WrappedIterator
0310 , class Reference
0311 , class Buffer
0312 >
0313 class any_bidirectional_iterator_wrapper
0314 : public any_bidirectional_iterator_interface<
0315 Reference
0316 , Buffer
0317 >
0318 {
0319 BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalIteratorConcept<WrappedIterator> ));
0320 typedef any_bidirectional_iterator_interface<
0321 Reference,
0322 Buffer
0323 > base_type;
0324
0325 public:
0326 typedef typename base_type::reference reference;
0327
0328 any_bidirectional_iterator_wrapper()
0329 : m_it()
0330 {
0331 }
0332
0333 explicit any_bidirectional_iterator_wrapper(const WrappedIterator& it)
0334 : m_it(it)
0335 {
0336 }
0337
0338 virtual any_bidirectional_iterator_wrapper* clone(
0339 typename any_bidirectional_iterator_wrapper::buffer_type& buffer
0340 ) const
0341 {
0342 return new (buffer.allocate(sizeof(*this)))
0343 any_bidirectional_iterator_wrapper(*this);
0344 }
0345
0346 virtual any_bidirectional_iterator_wrapper<
0347 WrappedIterator
0348 , typename any_bidirectional_iterator_wrapper::const_reference
0349 , Buffer
0350 >* clone_const_ref(
0351 typename any_bidirectional_iterator_wrapper::buffer_type& buffer
0352 ) const
0353 {
0354 typedef any_bidirectional_iterator_wrapper<
0355 WrappedIterator
0356 , typename any_bidirectional_iterator_wrapper::const_reference
0357 , Buffer
0358 > result_type;
0359
0360 return new (buffer.allocate(sizeof(result_type)))
0361 result_type(m_it);
0362 }
0363
0364 virtual any_bidirectional_iterator_wrapper<
0365 WrappedIterator
0366 , typename any_bidirectional_iterator_wrapper::reference_as_value_type
0367 , Buffer
0368 >* clone_reference_as_value(
0369 typename any_bidirectional_iterator_wrapper::buffer_type& buffer
0370 ) const
0371 {
0372 typedef any_bidirectional_iterator_wrapper<
0373 WrappedIterator
0374 , typename any_bidirectional_iterator_wrapper::reference_as_value_type
0375 , Buffer
0376 > result_type;
0377
0378 return new (buffer.allocate(sizeof(result_type)))
0379 result_type(m_it);
0380 }
0381
0382 virtual void increment()
0383 {
0384 ++m_it;
0385 }
0386
0387 virtual void decrement()
0388 {
0389 --m_it;
0390 }
0391
0392 virtual bool equal(const any_single_pass_iterator_interface<Reference, Buffer>& other) const
0393 {
0394 return m_it == range_detail::polymorphic_ref_downcast<const any_bidirectional_iterator_wrapper>(other).m_it;
0395 }
0396
0397 virtual reference dereference() const
0398 {
0399 return dereference_cast<reference>(*m_it);
0400 }
0401
0402 private:
0403 WrappedIterator m_it;
0404 };
0405
0406 template<
0407 class WrappedIterator
0408 , class Reference
0409 , class Difference
0410 , class Buffer
0411 >
0412 class any_random_access_iterator_wrapper
0413 : public any_random_access_iterator_interface<
0414 Reference
0415 , Difference
0416 , Buffer
0417 >
0418 {
0419 BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessIteratorConcept<WrappedIterator> ));
0420 typedef any_random_access_iterator_interface<
0421 Reference,
0422 Difference,
0423 Buffer
0424 > base_type;
0425
0426 public:
0427 typedef typename base_type::reference reference;
0428 typedef Difference difference_type;
0429
0430 any_random_access_iterator_wrapper()
0431 : m_it()
0432 {
0433 }
0434
0435 explicit any_random_access_iterator_wrapper(const WrappedIterator& other)
0436 : m_it(other)
0437 {
0438 }
0439
0440 virtual any_random_access_iterator_wrapper* clone(
0441 typename any_random_access_iterator_wrapper::buffer_type& buffer
0442 ) const
0443 {
0444 return new (buffer.allocate(sizeof(*this)))
0445 any_random_access_iterator_wrapper(*this);
0446 }
0447
0448 virtual any_random_access_iterator_wrapper<
0449 WrappedIterator
0450 , typename any_random_access_iterator_wrapper::const_reference
0451 , Difference
0452 , Buffer
0453 >* clone_const_ref(
0454 typename any_random_access_iterator_wrapper::buffer_type& buffer
0455 ) const
0456 {
0457 typedef any_random_access_iterator_wrapper<
0458 WrappedIterator
0459 , typename any_random_access_iterator_wrapper::const_reference
0460 , Difference
0461 , Buffer
0462 > result_type;
0463
0464 return new (buffer.allocate(sizeof(result_type)))
0465 result_type(m_it);
0466 }
0467
0468 virtual any_random_access_iterator_wrapper<
0469 WrappedIterator
0470 , typename any_random_access_iterator_wrapper::reference_as_value_type
0471 , Difference
0472 , Buffer
0473 >* clone_reference_as_value(
0474 typename any_random_access_iterator_wrapper::buffer_type& buffer
0475 ) const
0476 {
0477 typedef any_random_access_iterator_wrapper<
0478 WrappedIterator
0479 , typename any_random_access_iterator_wrapper::reference_as_value_type
0480 , Difference
0481 , Buffer
0482 > result_type;
0483
0484 return new (buffer.allocate(sizeof(result_type)))
0485 result_type(m_it);
0486 }
0487
0488 virtual void increment()
0489 {
0490 ++m_it;
0491 }
0492
0493 virtual bool equal(const any_single_pass_iterator_interface<Reference, Buffer>& other) const
0494 {
0495 return m_it == range_detail::polymorphic_ref_downcast<const any_random_access_iterator_wrapper>(other).m_it;
0496 }
0497
0498 virtual void decrement()
0499 {
0500 --m_it;
0501 }
0502
0503 virtual void advance(Difference offset)
0504 {
0505 m_it += offset;
0506 }
0507
0508 virtual reference dereference() const
0509 {
0510 return dereference_cast<reference>(*m_it);
0511 }
0512
0513 virtual Difference distance_to(const any_random_access_iterator_interface<Reference, Difference, Buffer>& other) const
0514 {
0515 return range_detail::polymorphic_ref_downcast<const any_random_access_iterator_wrapper>(other).m_it - m_it;
0516 }
0517
0518 private:
0519 WrappedIterator m_it;
0520 };
0521
0522 template<
0523 class WrappedIterator
0524 , class Traversal
0525 , class Reference
0526 , class Difference
0527 , class Buffer
0528 >
0529 struct any_iterator_wrapper_type_generator;
0530
0531 template<
0532 class WrappedIterator
0533 , class Reference
0534 , class Difference
0535 , class Buffer
0536 >
0537 struct any_iterator_wrapper_type_generator<
0538 WrappedIterator
0539 , incrementable_traversal_tag
0540 , Reference
0541 , Difference
0542 , Buffer
0543 >
0544 {
0545 typedef any_incrementable_iterator_wrapper<
0546 WrappedIterator
0547 , Reference
0548 , Buffer
0549 > type;
0550 };
0551
0552 template<
0553 class WrappedIterator
0554 , class Reference
0555 , class Difference
0556 , class Buffer
0557 >
0558 struct any_iterator_wrapper_type_generator<
0559 WrappedIterator
0560 , single_pass_traversal_tag
0561 , Reference
0562 , Difference
0563 , Buffer
0564 >
0565 {
0566 typedef any_single_pass_iterator_wrapper<
0567 WrappedIterator
0568 , Reference
0569 , Buffer
0570 > type;
0571 };
0572
0573 template<
0574 class WrappedIterator
0575 , class Reference
0576 , class Difference
0577 , class Buffer
0578 >
0579 struct any_iterator_wrapper_type_generator<
0580 WrappedIterator
0581 , forward_traversal_tag
0582 , Reference
0583 , Difference
0584 , Buffer
0585 >
0586 {
0587 typedef any_forward_iterator_wrapper<
0588 WrappedIterator
0589 , Reference
0590 , Buffer
0591 > type;
0592 };
0593
0594 template<
0595 class WrappedIterator
0596 , class Reference
0597 , class Difference
0598 , class Buffer
0599 >
0600 struct any_iterator_wrapper_type_generator<
0601 WrappedIterator
0602 , bidirectional_traversal_tag
0603 , Reference
0604 , Difference
0605 , Buffer
0606 >
0607 {
0608 typedef any_bidirectional_iterator_wrapper<
0609 WrappedIterator
0610 , Reference
0611 , Buffer
0612 > type;
0613 };
0614
0615 template<
0616 class WrappedIterator
0617 , class Reference
0618 , class Difference
0619 , class Buffer
0620 >
0621 struct any_iterator_wrapper_type_generator<
0622 WrappedIterator
0623 , random_access_traversal_tag
0624 , Reference
0625 , Difference
0626 , Buffer
0627 >
0628 {
0629 typedef any_random_access_iterator_wrapper<
0630 WrappedIterator
0631 , Reference
0632 , Difference
0633 , Buffer
0634 > type;
0635 };
0636
0637 }
0638 }
0639
0640 #endif