safe_ctr_proxy.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* Copyright 2003-2008 Joaquin M Lopez Munoz.
  2. * Distributed under the Boost Software License, Version 1.0.
  3. * (See accompanying file LICENSE_1_0.txt or copy at
  4. * http://www.boost.org/LICENSE_1_0.txt)
  5. *
  6. * See http://www.boost.org/libs/multi_index for library home page.
  7. */
  8. #ifndef BOOST_MULTI_INDEX_DETAIL_SAFE_CTR_PROXY_HPP
  9. #define BOOST_MULTI_INDEX_DETAIL_SAFE_CTR_PROXY_HPP
  10. #if defined(_MSC_VER)&&(_MSC_VER>=1200)
  11. #pragma once
  12. #endif
  13. #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
  14. #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
  15. #include <boost/detail/workaround.hpp>
  16. #if BOOST_WORKAROUND(BOOST_MSVC,<1300)
  17. #include <boost/multi_index/detail/safe_mode.hpp>
  18. namespace boost{
  19. namespace multi_index{
  20. namespace detail{
  21. /* A safe iterator is instantiated in the form
  22. * safe_iterator<Iterator,Container>: MSVC++ 6.0 has serious troubles with
  23. * the resulting symbols names, given that index names (which stand for
  24. * Container) are fairly long themselves. safe_ctr_proxy does not statically
  25. * depend on Container, and provides the necessary methods (begin and end) to
  26. * the safe mode framework via an abstract interface. With safe_ctr_proxy,
  27. * instead of deriving from safe_container<Container> the following base class
  28. * must be used:
  29. *
  30. * safe_ctr_proxy_impl<Iterator,Container>
  31. *
  32. * where Iterator is the type of the *unsafe* iterator being wrapped.
  33. * The corresponding safe iterator instantiation is then
  34. *
  35. * safe_iterator<Iterator,safe_ctr_proxy<Iterator> >,
  36. *
  37. * which does not include the name of Container.
  38. */
  39. template<typename Iterator>
  40. class safe_ctr_proxy:
  41. public safe_mode::safe_container<safe_ctr_proxy<Iterator> >
  42. {
  43. public:
  44. typedef safe_mode::safe_iterator<Iterator,safe_ctr_proxy> iterator;
  45. typedef iterator const_iterator;
  46. iterator begin(){return begin_impl();}
  47. const_iterator begin()const{return begin_impl();}
  48. iterator end(){return end_impl();}
  49. const_iterator end()const{return end_impl();}
  50. protected:
  51. virtual iterator begin_impl()=0;
  52. virtual const_iterator begin_impl()const=0;
  53. virtual iterator end_impl()=0;
  54. virtual const_iterator end_impl()const=0;
  55. };
  56. template<typename Iterator,typename Container>
  57. class safe_ctr_proxy_impl:public safe_ctr_proxy<Iterator>
  58. {
  59. typedef safe_ctr_proxy<Iterator> super;
  60. typedef Container container_type;
  61. public:
  62. typedef typename super::iterator iterator;
  63. typedef typename super::const_iterator const_iterator;
  64. virtual iterator begin_impl(){return container().begin();}
  65. virtual const_iterator begin_impl()const{return container().begin();}
  66. virtual iterator end_impl(){return container().end();}
  67. virtual const_iterator end_impl()const{return container().end();}
  68. private:
  69. container_type& container()
  70. {
  71. return *static_cast<container_type*>(this);
  72. }
  73. const container_type& container()const
  74. {
  75. return *static_cast<const container_type*>(this);
  76. }
  77. };
  78. } /* namespace multi_index::detail */
  79. } /* namespace multi_index */
  80. } /* namespace boost */
  81. #endif /* workaround */
  82. #endif /* BOOST_MULTI_INDEX_ENABLE_SAFE_MODE */
  83. #endif