dataflow.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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)
  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 <boost/assert.hpp>
  15. #include <boost/mpl/eval_if.hpp>
  16. #include <boost/mpl/if.hpp>
  17. #include <boost/mpl/apply.hpp>
  18. #include <boost/mpl/plus.hpp>
  19. #include <boost/mpl/int.hpp>
  20. #include <boost/type_traits/is_convertible.hpp>
  21. #include <boost/type_traits/is_base_and_derived.hpp>
  22. #include <boost/type_traits/is_pointer.hpp>
  23. #include <boost/iterator/iterator_adaptor.hpp>
  24. #include <boost/iterator/iterator_traits.hpp>
  25. #include <boost/static_assert.hpp>
  26. namespace boost {
  27. namespace archive {
  28. namespace iterators {
  29. // poor man's tri-state
  30. struct tri_state {
  31. enum state_enum {
  32. is_false = false,
  33. is_true = true,
  34. is_indeterminant
  35. } m_state;
  36. // convert to bool
  37. operator bool (){
  38. BOOST_ASSERT(is_indeterminant != m_state);
  39. return is_true == m_state ? true : false;
  40. }
  41. // assign from bool
  42. tri_state & operator=(bool rhs) {
  43. m_state = rhs ? is_true : is_false;
  44. return *this;
  45. }
  46. tri_state(bool rhs) :
  47. m_state(rhs ? is_true : is_false)
  48. {}
  49. tri_state(state_enum state) :
  50. m_state(state)
  51. {}
  52. bool operator==(const tri_state & rhs) const {
  53. return m_state == rhs.m_state;
  54. }
  55. bool operator!=(const tri_state & rhs) const {
  56. return m_state != rhs.m_state;
  57. }
  58. };
  59. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  60. // implement functions common to dataflow iterators
  61. template<class Derived>
  62. class dataflow {
  63. bool m_eoi;
  64. protected:
  65. // test for iterator equality
  66. tri_state equal(const Derived & rhs) const {
  67. if(m_eoi && rhs.m_eoi)
  68. return true;
  69. if(m_eoi || rhs.m_eoi)
  70. return false;
  71. return tri_state(tri_state::is_indeterminant);
  72. }
  73. void eoi(bool tf){
  74. m_eoi = tf;
  75. }
  76. bool eoi() const {
  77. return m_eoi;
  78. }
  79. public:
  80. dataflow(bool tf) :
  81. m_eoi(tf)
  82. {}
  83. dataflow() : // used for iterator end
  84. m_eoi(true)
  85. {}
  86. };
  87. } // namespace iterators
  88. } // namespace archive
  89. } // namespace boost
  90. #endif // BOOST_ARCHIVE_ITERATORS_DATAFLOW_HPP