1 | // (C) Copyright Jonathan Turkanis 2004
|
---|
2 | // Distributed under the Boost Software License, Version 1.0. (See accompanying
|
---|
3 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
|
---|
4 |
|
---|
5 | // See http://www.boost.org/libs/iostreams for documentation.
|
---|
6 |
|
---|
7 | // Contains the definition of the class template
|
---|
8 | // boost::iostreams::detail::double_object, which is similar to compressed pair
|
---|
9 | // except that both members of the pair have the same type, and
|
---|
10 | // compression occurs only if requested using a boolean template
|
---|
11 | // parameter.
|
---|
12 |
|
---|
13 | #ifndef BOOST_IOSTREAMS_DETAIL_DOUBLE_OBJECT_HPP_INCLUDED
|
---|
14 | #define BOOST_IOSTREAMS_DETAIL_DOUBLE_OBJECT_HPP_INCLUDED
|
---|
15 |
|
---|
16 | #if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
---|
17 | # pragma once
|
---|
18 | #endif
|
---|
19 |
|
---|
20 | #include <algorithm> // swap.
|
---|
21 | #include <boost/detail/workaround.hpp>
|
---|
22 | #include <boost/mpl/if.hpp>
|
---|
23 | #if BOOST_WORKAROUND(__MWERKS__, > 0x3003)
|
---|
24 | # include <msl_utility>
|
---|
25 | #else
|
---|
26 | # include <boost/call_traits.hpp>
|
---|
27 | #endif
|
---|
28 |
|
---|
29 | namespace boost { namespace iostreams { namespace detail {
|
---|
30 |
|
---|
31 | template<typename T>
|
---|
32 | class single_object_holder {
|
---|
33 | public:
|
---|
34 | #if BOOST_WORKAROUND(__MWERKS__, > 0x3003)
|
---|
35 | typedef Metrowerks::call_traits<T> traits_type;
|
---|
36 | #else
|
---|
37 | typedef boost::call_traits<T> traits_type;
|
---|
38 | #endif
|
---|
39 | typedef typename traits_type::param_type param_type;
|
---|
40 | typedef typename traits_type::reference reference;
|
---|
41 | typedef typename traits_type::const_reference const_reference;
|
---|
42 | single_object_holder() { }
|
---|
43 | single_object_holder(param_type t) : first_(t) { }
|
---|
44 | reference first() { return first_; }
|
---|
45 | const_reference first() const { return first_; }
|
---|
46 | reference second() { return first_; }
|
---|
47 | const_reference second() const { return first_; }
|
---|
48 | void swap(single_object_holder& o)
|
---|
49 | { std::swap(first_, o.first_); }
|
---|
50 | private:
|
---|
51 | T first_;
|
---|
52 | };
|
---|
53 |
|
---|
54 | template<typename T>
|
---|
55 | struct double_object_holder {
|
---|
56 | public:
|
---|
57 | #if BOOST_WORKAROUND(__MWERKS__, > 0x3003)
|
---|
58 | typedef Metrowerks::call_traits<T> traits_type;
|
---|
59 | #else
|
---|
60 | typedef boost::call_traits<T> traits_type;
|
---|
61 | #endif
|
---|
62 | typedef typename traits_type::param_type param_type;
|
---|
63 | typedef typename traits_type::reference reference;
|
---|
64 | typedef typename traits_type::const_reference const_reference;
|
---|
65 | double_object_holder() { }
|
---|
66 | double_object_holder(param_type t1, param_type t2)
|
---|
67 | : first_(t1), second_(t2) { }
|
---|
68 | reference first() { return first_; }
|
---|
69 | const_reference first() const { return first_; }
|
---|
70 | reference second() { return second_; }
|
---|
71 | const_reference second() const { return second_; }
|
---|
72 | void swap(double_object_holder& d)
|
---|
73 | {
|
---|
74 | std::swap(first_, d.first_);
|
---|
75 | std::swap(second_, d.second_);
|
---|
76 | }
|
---|
77 | private:
|
---|
78 | T first_, second_;
|
---|
79 | };
|
---|
80 |
|
---|
81 | template<typename T, typename IsDouble>
|
---|
82 | class double_object
|
---|
83 | : public mpl::if_<
|
---|
84 | IsDouble,
|
---|
85 | double_object_holder<T>,
|
---|
86 | single_object_holder<T>
|
---|
87 | >::type
|
---|
88 | {
|
---|
89 | private:
|
---|
90 | typedef typename
|
---|
91 | mpl::if_<
|
---|
92 | IsDouble,
|
---|
93 | double_object_holder<T>,
|
---|
94 | single_object_holder<T>
|
---|
95 | >::type base_type;
|
---|
96 | public:
|
---|
97 | #if BOOST_WORKAROUND(__MWERKS__, > 0x3003)
|
---|
98 | typedef Metrowerks::call_traits<T> traits_type;
|
---|
99 | #else
|
---|
100 | typedef boost::call_traits<T> traits_type;
|
---|
101 | #endif
|
---|
102 | typedef typename traits_type::param_type param_type;
|
---|
103 | typedef typename traits_type::reference reference;
|
---|
104 | typedef typename traits_type::const_reference const_reference;
|
---|
105 | double_object() : base_type() {}
|
---|
106 | double_object(param_type t1, param_type t2)
|
---|
107 | : base_type(t1, t2) { }
|
---|
108 | bool is_double() const { return IsDouble::value; }
|
---|
109 | };
|
---|
110 |
|
---|
111 | } } } // End namespaces detail, iostreams, boost.
|
---|
112 |
|
---|
113 | #endif // #ifndef BOOST_IOSTREAMS_DETAIL_DOUBLE_OBJECT_HPP_INCLUDED
|
---|