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