]> git.sesse.net Git - casparcg/blob - dependencies/boost/boost/archive/iterators/dataflow.hpp
Manually merged pull request #222
[casparcg] / dependencies / boost / boost / archive / iterators / dataflow.hpp
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) && (_MSC_VER >= 1020)
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/config.hpp> // for BOOST_DEDUCED_TYPENAME
22
23 #include <boost/mpl/eval_if.hpp>
24 #include <boost/mpl/if.hpp>
25 #include <boost/mpl/bool.hpp>
26 #include <boost/mpl/apply.hpp>
27 #include <boost/mpl/plus.hpp>
28 #include <boost/mpl/int.hpp>
29
30 #include <boost/type_traits/is_convertible.hpp>
31 #include <boost/type_traits/is_base_and_derived.hpp>
32 #include <boost/type_traits/is_pointer.hpp>
33 #include <boost/iterator/iterator_adaptor.hpp>
34 #include <boost/iterator/iterator_traits.hpp>
35 #include <boost/static_assert.hpp>
36
37 namespace boost { 
38 namespace archive {
39 namespace iterators {
40
41 // poor man's tri-state
42 struct tri_state {
43     enum state_enum {
44         is_false = false,
45         is_true = true,
46         is_indeterminant
47     } m_state;
48     // convert to bool
49     operator bool (){
50         BOOST_ASSERT(is_indeterminant != m_state);
51         return is_true == m_state ? true : false;
52     }
53     // assign from bool
54     tri_state & operator=(bool rhs) {
55         m_state = rhs ? is_true : is_false;
56         return *this;
57     }
58     tri_state(bool rhs) :
59         m_state(rhs ? is_true : is_false)
60     {}
61     tri_state(state_enum state) :
62         m_state(state)
63     {}
64     bool operator==(const tri_state & rhs) const {
65         return m_state == rhs.m_state;
66     }
67     bool operator!=(const tri_state & rhs) const {
68         return m_state != rhs.m_state;
69     }
70 };
71
72 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
73 // implement functions common to dataflow iterators
74 template<class Derived>
75 class dataflow {
76     bool m_eoi;
77 protected:
78     // test for iterator equality
79     tri_state equal(const Derived & rhs) const {
80         if(m_eoi && rhs.m_eoi)
81             return true;
82         if(m_eoi || rhs.m_eoi)
83             return false;
84         return tri_state(tri_state::is_indeterminant);
85     }
86     void eoi(bool tf){
87         m_eoi = tf;
88     }
89     bool eoi() const {
90         return m_eoi;
91     }
92 public:
93     dataflow(bool tf) :
94         m_eoi(tf)
95     {}
96     dataflow() : // used for iterator end
97         m_eoi(true)
98     {}
99 };
100
101 } // namespace iterators
102 } // namespace archive
103 } // namespace boost
104
105 #endif // BOOST_ARCHIVE_ITERATORS_DATAFLOW_HPP