dataflow.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #ifndef BOOST_ARCHIVE_ITERATORS_DATAFLOW_HPP
  2. #define BOOST_ARCHIVE_ITERATORS_DATAFLOW_HPP
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  5. # pragma once
  6. #endif
  7. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  8. // dataflow.hpp
  9. // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
  10. // Use, modification and distribution is subject to the Boost Software
  11. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. // See http://www.boost.org for updates, documentation, and revision history.
  14. #include <cassert>
  15. #include <boost/config.hpp> // for BOOST_DEDUCED_TYPENAME
  16. #include <boost/mpl/eval_if.hpp>
  17. #include <boost/mpl/if.hpp>
  18. #include <boost/mpl/bool.hpp>
  19. #include <boost/mpl/apply.hpp>
  20. #include <boost/mpl/plus.hpp>
  21. #include <boost/mpl/int.hpp>
  22. #include <boost/type_traits/is_convertible.hpp>
  23. #include <boost/type_traits/is_base_and_derived.hpp>
  24. #include <boost/type_traits/is_pointer.hpp>
  25. #include <boost/iterator/iterator_adaptor.hpp>
  26. #include <boost/iterator/iterator_traits.hpp>
  27. #include <boost/static_assert.hpp>
  28. namespace boost {
  29. namespace archive {
  30. namespace iterators {
  31. // poor man's tri-state
  32. struct tri_state {
  33. enum state_enum {
  34. is_false = false,
  35. is_true = true,
  36. is_indeterminant
  37. } m_state;
  38. // convert to bool
  39. operator bool (){
  40. assert(is_indeterminant != m_state);
  41. return is_true == m_state ? true : false;
  42. }
  43. // assign from bool
  44. tri_state & operator=(bool rhs) {
  45. m_state = rhs ? is_true : is_false;
  46. return *this;
  47. }
  48. tri_state(bool rhs) :
  49. m_state(rhs ? is_true : is_false)
  50. {}
  51. tri_state(state_enum state) :
  52. m_state(state)
  53. {}
  54. bool operator==(const tri_state & rhs) const {
  55. return m_state == rhs.m_state;
  56. }
  57. bool operator!=(const tri_state & rhs) const {
  58. return m_state != rhs.m_state;
  59. }
  60. };
  61. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  62. // implement functions common to dataflow iterators
  63. template<class Derived>
  64. class dataflow {
  65. bool m_eoi;
  66. protected:
  67. // test for iterator equality
  68. tri_state equal(const Derived & rhs) const {
  69. if(m_eoi && rhs.m_eoi)
  70. return true;
  71. if(m_eoi || rhs.m_eoi)
  72. return false;
  73. return tri_state(tri_state::is_indeterminant);
  74. }
  75. void eoi(bool tf){
  76. m_eoi = tf;
  77. }
  78. bool eoi() const {
  79. return m_eoi;
  80. }
  81. public:
  82. dataflow(bool tf) :
  83. m_eoi(tf)
  84. {}
  85. dataflow() : // used for iterator end
  86. m_eoi(true)
  87. {}
  88. };
  89. } // namespace iterators
  90. } // namespace archive
  91. } // namespace boost
  92. #endif // BOOST_ARCHIVE_ITERATORS_DATAFLOW_HPP