Chris@16: // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com) Chris@16: // (C) Copyright 2004-2007 Jonathan Turkanis Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.) Chris@16: Chris@16: // See http://www.boost.org/libs/iostreams for documentation. Chris@16: Chris@16: // Contains the definition of the class template Chris@16: // boost::iostreams::detail::double_object, which is similar to compressed pair Chris@16: // except that both members of the pair have the same type, and Chris@16: // compression occurs only if requested using a boolean template Chris@16: // parameter. Chris@16: Chris@16: #ifndef BOOST_IOSTREAMS_DETAIL_DOUBLE_OBJECT_HPP_INCLUDED Chris@16: #define BOOST_IOSTREAMS_DETAIL_DOUBLE_OBJECT_HPP_INCLUDED Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1020) Chris@16: # pragma once Chris@16: #endif Chris@16: Chris@16: #include // swap. Chris@16: #include Chris@16: #include Chris@16: #if BOOST_WORKAROUND(__MWERKS__, > 0x3003) Chris@16: # include Chris@16: #else Chris@16: # include Chris@16: #endif Chris@16: Chris@16: namespace boost { namespace iostreams { namespace detail { Chris@16: Chris@16: template Chris@16: class single_object_holder { Chris@16: public: Chris@16: #if BOOST_WORKAROUND(__MWERKS__, > 0x3003) Chris@16: typedef Metrowerks::call_traits traits_type; Chris@16: #else Chris@16: typedef boost::call_traits traits_type; Chris@16: #endif Chris@16: typedef typename traits_type::param_type param_type; Chris@16: typedef typename traits_type::reference reference; Chris@16: typedef typename traits_type::const_reference const_reference; Chris@16: single_object_holder() { } Chris@16: single_object_holder(param_type t) : first_(t) { } Chris@16: reference first() { return first_; } Chris@16: const_reference first() const { return first_; } Chris@16: reference second() { return first_; } Chris@16: const_reference second() const { return first_; } Chris@16: void swap(single_object_holder& o) Chris@16: { std::swap(first_, o.first_); } Chris@16: private: Chris@16: T first_; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct double_object_holder { Chris@16: public: Chris@16: #if BOOST_WORKAROUND(__MWERKS__, > 0x3003) Chris@16: typedef Metrowerks::call_traits traits_type; Chris@16: #else Chris@16: typedef boost::call_traits traits_type; Chris@16: #endif Chris@16: typedef typename traits_type::param_type param_type; Chris@16: typedef typename traits_type::reference reference; Chris@16: typedef typename traits_type::const_reference const_reference; Chris@16: double_object_holder() { } Chris@16: double_object_holder(param_type t1, param_type t2) Chris@16: : first_(t1), second_(t2) { } Chris@16: reference first() { return first_; } Chris@16: const_reference first() const { return first_; } Chris@16: reference second() { return second_; } Chris@16: const_reference second() const { return second_; } Chris@16: void swap(double_object_holder& d) Chris@16: { Chris@16: std::swap(first_, d.first_); Chris@16: std::swap(second_, d.second_); Chris@16: } Chris@16: private: Chris@16: T first_, second_; Chris@16: }; Chris@16: Chris@16: template Chris@16: class double_object Chris@16: : public mpl::if_< Chris@16: IsDouble, Chris@16: double_object_holder, Chris@16: single_object_holder Chris@16: >::type Chris@16: { Chris@16: private: Chris@16: typedef typename Chris@16: mpl::if_< Chris@16: IsDouble, Chris@16: double_object_holder, Chris@16: single_object_holder Chris@16: >::type base_type; Chris@16: public: Chris@16: #if BOOST_WORKAROUND(__MWERKS__, > 0x3003) Chris@16: typedef Metrowerks::call_traits traits_type; Chris@16: #else Chris@16: typedef boost::call_traits traits_type; Chris@16: #endif Chris@16: typedef typename traits_type::param_type param_type; Chris@16: typedef typename traits_type::reference reference; Chris@16: typedef typename traits_type::const_reference const_reference; Chris@16: double_object() : base_type() {} Chris@16: double_object(param_type t1, param_type t2) Chris@16: : base_type(t1, t2) { } Chris@16: bool is_double() const { return IsDouble::value; } Chris@16: }; Chris@16: Chris@16: } } } // End namespaces detail, iostreams, boost. Chris@16: Chris@16: #endif // #ifndef BOOST_IOSTREAMS_DETAIL_DOUBLE_OBJECT_HPP_INCLUDED