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