renamed from stream_facade.hpp

[SVN r30121]
This commit is contained in:
Jonathan Turkanis
2005-07-15 23:44:00 +00:00
parent 57425391a0
commit 59b4ee1213
2 changed files with 312 additions and 0 deletions

View File

@@ -0,0 +1,179 @@
// (C) Copyright Jonathan Turkanis 2003.
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
// See http://www.boost.org/libs/iostreams for documentation.
#ifndef BOOST_IOSTREAMS_DETAIL_BROKEN_OVERLOAD_RESOLUTION_STREAM_HPP_INCLUDED
#define BOOST_IOSTREAMS_DETAIL_BROKEN_OVERLOAD_RESOLUTION_STREAM_HPP_INCLUDED
#include <boost/iostreams/detail/broken_overload_resolution/forward.hpp>
namespace boost { namespace iostreams {
template< typename Device,
typename Tr =
BOOST_IOSTREAMS_CHAR_TRAITS(
BOOST_DEDUCED_TYPENAME char_type_of<Device>::type
),
typename Alloc =
std::allocator<
BOOST_DEDUCED_TYPENAME char_type_of<Device>::type
> >
struct stream : detail::stream_base<Device, Tr, Alloc> {
public:
typedef typename char_type_of<Device>::type char_type;
BOOST_IOSTREAMS_STREAMBUF_TYPEDEFS(Tr)
private:
typedef typename
detail::stream_traits<
Device, Tr
>::type stream_type;
typedef Device policy_type;
public:
stream() { }
template<typename U0>
stream(const U0& u0)
{
open_impl(detail::forward<Device, U0>(), u0);
}
template<typename U0, typename U1>
stream(const U0& u0, const U1& u1)
{
open_impl(detail::forward<Device, U0>(), u0, u1);
}
template<typename U0, typename U1, typename U2>
stream(const U0& u0, const U1& u1, const U2& u2)
{
open_impl(detail::forward<Device, U0>(), u0, u1, u2);
}
#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------------//
template<typename U0>
stream(U0& u0)
{
open_impl(detail::forward<Device, U0>(), u0);
}
template<typename U0, typename U1>
stream(U0& u0, const U1& u1)
{
open_impl(detail::forward<Device, U0>(), u0, u1);
}
template<typename U0, typename U1, typename U2>
stream(U0& u0, const U1& u1, const U2& u2)
{
open_impl(detail::forward<Device, U0>(), u0, u1, u2);
}
#endif // !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------//
template<typename U0>
void open(const U0& u0)
{
open_impl(detail::forward<Device, U0>(), u0);
}
template<typename U0, typename U1>
void open(const U0& u0, const U1& u1)
{
open_impl(detail::forward<Device, U0>(), u0, u1);
}
template<typename U0, typename U1, typename U2>
void open(const U0& u0, const U1& u1, const U2& u2)
{
open_impl(detail::forward<Device, U0>(), u0, u1, u2);
}
#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------------//
template<typename U0>
void open(U0& u0)
{
open_impl(detail::forward<Device, U0>(), u0);
}
template<typename U0, typename U1>
void open(U0& u0, const U1& u1)
{
open_impl(detail::forward<Device, U0>(), u0, u1);
}
template<typename U0, typename U1, typename U2>
void open(U0& u0, const U1& u1, const U2& u2)
{
open_impl(detail::forward<Device, U0>(), u0, u1, u2);
}
#endif // !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------//
bool is_open() const { return this->member.is_open(); }
void close() { this->member.close(); }
bool auto_close() const { return this->member.auto_close(); }
void set_auto_close(bool close) { this->member.set_auto_close(close); }
bool strict_sync() { return this->member.strict_sync(); }
Device& operator*() { return *this->member; }
Device* operator->() { return &*this->member; }
private:
template<typename U0>
void open_impl(mpl::false_, const U0& u0)
{
this->clear();
this->member.open(u0);
}
#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------------//
template<typename U0>
void open_impl(mpl::false_, U0& u0)
{
this->clear();
this->member.open(detail::wrap(u0));
}
#endif // !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------//
template<typename U0>
void open_impl(mpl::true_, const U0& u0)
{
this->clear();
this->member.open(Device(const_cast<U0&>(u0)));
}
#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------------//
template<typename U0>
void open_impl(mpl::true_, U0& u0)
{
this->clear();
this->member.open(Device(u0));
}
#endif // !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------//
template<typename U0, typename U1>
void open_impl(mpl::false_, const U0& u0, const U1& u1)
{
this->clear();
this->member.open(u0, u1);
}
template<typename U0, typename U1>
void open_impl(mpl::true_, const U0& u0, const U1& u1)
{
this->clear();
this->member.open(Device(const_cast<U0&>(u0), u1));
}
#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------------//
template<typename U0, typename U1>
void open_impl(mpl::true_, U0& u0, const U1& u1)
{
this->clear();
this->member.open(Device(u0, u1));
}
#endif // !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------//
template<typename U0, typename U1, typename U2>
void open_impl(mpl::false_, const U0& u0, const U1& u1, const U2& u2)
{
this->clear();
this->member.open(u0, u1, u2);
}
template<typename U0, typename U1, typename U2>
void open_impl(mpl::true_, const U0& u0, const U1& u1, const U2& u2)
{
this->clear();
this->member.open(Device(const_cast<U0&>(u0), u1, u2));
}
#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------------//
template<typename U0, typename U1, typename U2>
void open_impl(mpl::true_, U0& u0, const U1& u1, const U2& u2)
{
this->clear();
this->member.open(Device(u0, u1, u2));
}
#endif
};
} } // End namespaces iostreams, boost.
#endif BOOST_IOSTREAMS_DETAIL_BROKEN_OVERLOAD_RESOLUTION_STREAM_HPP_INCLUDED

View File

@@ -0,0 +1,133 @@
// (C) Copyright Jonathan Turkanis 2003.
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
// See http://www.boost.org/libs/iostreams for documentation.
#ifndef BOOST_IOSTREAMS_STREAM_HPP_INCLUDED
#define BOOST_IOSTREAMS_STREAM_HPP_INCLUDED
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif
#include <boost/iostreams/constants.hpp>
#include <boost/iostreams/detail/char_traits.hpp>
#include <boost/iostreams/detail/config/overload_resolution.hpp>
#include <boost/iostreams/detail/forward.hpp>
#include <boost/iostreams/detail/iostream.hpp> // standard streams.
#include <boost/iostreams/detail/select.hpp>
#include <boost/iostreams/stream_buffer.hpp>
#include <boost/mpl/and.hpp>
#include <boost/type_traits/is_convertible.hpp>
namespace boost { namespace iostreams { namespace detail {
template<typename Device, typename Tr>
struct stream_traits {
typedef typename char_type_of<Device>::type char_type;
typedef Tr traits_type;
typedef typename category_of<Device>::type mode;
typedef typename
iostreams::select< // Dismbiguation required for Tru64.
mpl::and_<
is_convertible<mode, input>,
is_convertible<mode, output>
>,
BOOST_IOSTREAMS_BASIC_IOSTREAM(char_type, traits_type),
is_convertible<mode, input>,
BOOST_IOSTREAMS_BASIC_ISTREAM(char_type, traits_type),
else_,
BOOST_IOSTREAMS_BASIC_OSTREAM(char_type, traits_type)
>::type type;
};
// By encapsulating initialization in a base, we can define the macro
// BOOST_IOSTREAMS_DEFINE_FORWARDING_FUNCTIONS to generate constuctors
// without base member initializer lists.
template< typename Device,
typename Tr =
BOOST_IOSTREAMS_CHAR_TRAITS(
BOOST_DEDUCED_TYPENAME char_type_of<Device>::type
),
typename Alloc =
std::allocator<
BOOST_DEDUCED_TYPENAME char_type_of<Device>::type
>,
typename Base = // VC6 Workaround.
BOOST_DEDUCED_TYPENAME
detail::stream_traits<Device, Tr>::type >
class stream_base
: protected base_from_member< stream_buffer<Device, Tr, Alloc> >,
public Base
{
private:
typedef base_from_member< stream_buffer<Device, Tr, Alloc> > pbase_type;
typedef typename stream_traits<Device, Tr>::type stream_type;
protected:
using pbase_type::member; // Avoid warning about 'this' in initializer list.
public:
stream_base() : pbase_type(), stream_type(&member) { }
};
} } } // End namespaces detail, iostreams, boost.
#ifdef BOOST_IOSTREAMS_BROKEN_OVERLOAD_RESOLUTION
# include <boost/iostreams/detail/broken_overload_resolution/stream.hpp>
#else
namespace boost { namespace iostreams {
//
// Template name: stream.
// Description: A iostream which reads from and writes to an instance of a
// designated device type.
// Template paramters:
// Device - A device type.
// Alloc - The allocator type.
//
template< typename Device,
typename Tr =
BOOST_IOSTREAMS_CHAR_TRAITS(
BOOST_DEDUCED_TYPENAME char_type_of<Device>::type
),
typename Alloc =
std::allocator<
BOOST_DEDUCED_TYPENAME char_type_of<Device>::type
> >
struct stream : detail::stream_base<Device, Tr, Alloc> {
public:
typedef typename char_type_of<Device>::type char_type;
BOOST_IOSTREAMS_STREAMBUF_TYPEDEFS(Tr)
private:
typedef typename
detail::stream_traits<
Device, Tr
>::type stream_type;
typedef Device policy_type;
public:
stream() { }
BOOST_IOSTREAMS_FORWARD( stream, open_impl, Device,
BOOST_IOSTREAMS_PUSH_PARAMS,
BOOST_IOSTREAMS_PUSH_ARGS )
bool is_open() const { return this->member.is_open(); }
void close() { this->member.close(); }
bool auto_close() const { return this->member.auto_close(); }
void set_auto_close(bool close) { this->member.set_auto_close(close); }
bool strict_sync() { return this->member.strict_sync(); }
Device& operator*() { return *this->member; }
Device* operator->() { return &*this->member; }
Device* component() { return this->member.component(); }
private:
void open_impl(const Device& dev BOOST_IOSTREAMS_PUSH_PARAMS()) // For forwarding.
{
this->clear();
this->member.open(dev BOOST_IOSTREAMS_PUSH_ARGS());
}
};
} } // End namespaces iostreams, boost.
#endif // #ifdef BOOST_IOSTREAMS_BROKEN_OVERLOAD_RESOLUTION
#endif // #ifndef BOOST_IOSTREAMS_stream_HPP_INCLUDED