Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:50

0001 // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
0002 // (C) Copyright 2004-2007 Jonathan Turkanis
0003 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0004 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
0005 
0006 // See http://www.boost.org/libs/iostreams for documentation.
0007 
0008 // Contains the definition of the class template 
0009 // boost::iostreams::detail::double_object, which is similar to compressed pair
0010 // except that both members of the pair have the same type, and 
0011 // compression occurs only if requested using a boolean template
0012 // parameter.
0013 
0014 #ifndef BOOST_IOSTREAMS_DETAIL_DOUBLE_OBJECT_HPP_INCLUDED
0015 #define BOOST_IOSTREAMS_DETAIL_DOUBLE_OBJECT_HPP_INCLUDED
0016 
0017 #if defined(_MSC_VER)
0018 # pragma once
0019 #endif              
0020 
0021 #include <algorithm>              // swap.
0022 #include <boost/detail/workaround.hpp>
0023 #include <boost/mpl/if.hpp>
0024 #if BOOST_WORKAROUND(__MWERKS__, > 0x3003)
0025 # include <msl_utility>
0026 #else
0027 # include <boost/call_traits.hpp>
0028 #endif
0029 
0030 namespace boost { namespace iostreams { namespace detail {
0031 
0032 template<typename T>
0033 class single_object_holder {
0034 public:
0035 #if BOOST_WORKAROUND(__MWERKS__, > 0x3003)
0036     typedef Metrowerks::call_traits<T>             traits_type;
0037 #else
0038     typedef boost::call_traits<T>                  traits_type;
0039 #endif
0040     typedef typename traits_type::param_type       param_type;
0041     typedef typename traits_type::reference        reference;
0042     typedef typename traits_type::const_reference  const_reference;
0043     single_object_holder() { }
0044     single_object_holder(param_type t) : first_(t) { }
0045     reference first() { return first_; }
0046     const_reference first() const { return first_; }
0047     reference second() { return first_; }
0048     const_reference second() const { return first_; }
0049     void swap(single_object_holder& o)
0050     { std::swap(first_, o.first_); }
0051 private:
0052     T first_;
0053 };
0054 
0055 template<typename T>
0056 struct double_object_holder {
0057 public:
0058 #if BOOST_WORKAROUND(__MWERKS__, > 0x3003)
0059     typedef Metrowerks::call_traits<T>             traits_type;
0060 #else
0061     typedef boost::call_traits<T>                  traits_type;
0062 #endif
0063     typedef typename traits_type::param_type       param_type;
0064     typedef typename traits_type::reference        reference;
0065     typedef typename traits_type::const_reference  const_reference;
0066     double_object_holder() { }
0067     double_object_holder(param_type t1, param_type t2)
0068         : first_(t1), second_(t2) { }
0069     reference first() { return first_; }
0070     const_reference first() const { return first_; }
0071     reference second() { return second_; }
0072     const_reference second() const { return second_; }
0073     void swap(double_object_holder& d)
0074     { 
0075         std::swap(first_, d.first_); 
0076         std::swap(second_, d.second_); 
0077     }
0078 private:
0079     T first_, second_;
0080 };
0081 
0082 template<typename T, typename IsDouble>
0083 class double_object 
0084     : public mpl::if_<
0085                  IsDouble, 
0086                  double_object_holder<T>, 
0087                  single_object_holder<T>
0088              >::type
0089 {
0090 private:
0091     typedef typename 
0092             mpl::if_<
0093                 IsDouble, 
0094                 double_object_holder<T>, 
0095                 single_object_holder<T>
0096             >::type                                base_type;
0097 public:
0098 #if BOOST_WORKAROUND(__MWERKS__, > 0x3003)
0099     typedef Metrowerks::call_traits<T>             traits_type;
0100 #else
0101     typedef boost::call_traits<T>                  traits_type;
0102 #endif
0103     typedef typename traits_type::param_type       param_type;
0104     typedef typename traits_type::reference        reference;
0105     typedef typename traits_type::const_reference  const_reference;
0106     double_object() : base_type() {}
0107     double_object(param_type t1, param_type t2)
0108         : base_type(t1, t2) { }
0109     bool is_double() const { return IsDouble::value; }
0110 };
0111 
0112 } } } // End namespaces detail, iostreams, boost.
0113 
0114 #endif // #ifndef BOOST_IOSTREAMS_DETAIL_DOUBLE_OBJECT_HPP_INCLUDED