source: NonGTP/Boost/boost/archive/iterators/dataflow.hpp @ 857

Revision 857, 2.8 KB checked in by igarcia, 19 years ago (diff)
RevLine 
[857]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 <cassert>
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
37namespace boost {
38namespace archive {
39namespace iterators {
40
41// poor man's tri-state
42struct 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        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    }
57    tri_state(bool rhs) :
58        m_state(rhs ? is_true : is_false)
59    {}
60    tri_state(state_enum state) :
61        m_state(state)
62    {}
63    bool operator==(const tri_state & rhs) const {
64        return m_state == rhs.m_state;
65    }
66    bool operator!=(const tri_state & rhs) const {
67        return m_state != rhs.m_state;
68    }
69};
70
71/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
72// implement functions common to dataflow iterators
73template<class Derived>
74class dataflow {
75    bool m_eoi;
76protected:
77    // test for iterator equality
78    tri_state equal(const Derived & rhs) const {
79        if(m_eoi && rhs.m_eoi)
80            return true;
81        if(m_eoi || rhs.m_eoi)
82            return false;
83        return tri_state(tri_state::is_indeterminant);
84    }
85    void eoi(bool tf){
86        m_eoi = tf;
87    }
88    bool eoi() const {
89        return m_eoi;
90    }
91public:
92    dataflow(bool tf) :
93        m_eoi(tf)
94    {}
95    dataflow() : // used for iterator end
96        m_eoi(true)
97    {}
98};
99
100} // namespace iterators
101} // namespace archive
102} // namespace boost
103
104#endif // BOOST_ARCHIVE_ITERATORS_DATAFLOW_HPP
Note: See TracBrowser for help on using the repository browser.