stabilize build system: depends, installer, boost/bdb fixes, cross targets groundwork

This commit is contained in:
2026-02-24 18:38:47 +00:00
parent da8c28aaeb
commit 65cb2619a7
13106 changed files with 2484322 additions and 1804 deletions
@@ -0,0 +1,287 @@
// (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
// (C) Copyright 2003-2007 Jonathan Turkanis
// 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_CONCEPT_ADAPTER_HPP_INCLUDED
#define BOOST_IOSTREAMS_DETAIL_CONCEPT_ADAPTER_HPP_INCLUDED
#include <boost/config.hpp> // SFINAE.
#include <boost/iostreams/concepts.hpp>
#include <boost/iostreams/categories.hpp>
#include <boost/iostreams/detail/adapter/non_blocking_adapter.hpp>
#include <boost/iostreams/detail/call_traits.hpp>
#include <boost/iostreams/detail/char_traits.hpp>
#include <boost/iostreams/detail/dispatch.hpp>
#include <boost/iostreams/detail/error.hpp>
#include <boost/iostreams/detail/streambuf.hpp> // pubsync.
#include <boost/iostreams/detail/config/unreachable_return.hpp>
#include <boost/iostreams/device/null.hpp>
#include <boost/iostreams/traits.hpp>
#include <boost/iostreams/operations.hpp>
#include <boost/mpl/if.hpp>
#include <boost/static_assert.hpp>
#include <boost/throw_exception.hpp>
// Must come last.
#include <boost/iostreams/detail/config/disable_warnings.hpp> // MSVC.
namespace boost { namespace iostreams { namespace detail {
template<typename Category> struct device_wrapper_impl;
template<typename Category> struct flt_wrapper_impl;
template<typename T>
class concept_adapter {
private:
typedef typename detail::value_type<T>::type value_type;
typedef typename dispatch<T, input, output>::type input_tag;
typedef typename dispatch<T, output, input>::type output_tag;
typedef typename
mpl::if_<
is_device<T>,
device_wrapper_impl<input_tag>,
flt_wrapper_impl<input_tag>
>::type input_impl;
typedef typename
mpl::if_<
is_device<T>,
device_wrapper_impl<output_tag>,
flt_wrapper_impl<output_tag>
>::type output_impl;
typedef typename
mpl::if_<
is_device<T>,
device_wrapper_impl<any_tag>,
flt_wrapper_impl<any_tag>
>::type any_impl;
public:
typedef typename char_type_of<T>::type char_type;
typedef typename category_of<T>::type category;
explicit concept_adapter(const reference_wrapper<T>& ref) : t_(ref.get())
{ BOOST_STATIC_ASSERT(is_std_io<T>::value); }
explicit concept_adapter(const T& t) : t_(t)
{ BOOST_STATIC_ASSERT(!is_std_io<T>::value); }
T& operator*() { return t_; }
T* operator->() { return &t_; }
std::streamsize read(char_type* s, std::streamsize n)
{ return this->read(s, n, (basic_null_source<char_type>*) 0); }
template<typename Source>
std::streamsize read(char_type* s, std::streamsize n, Source* src)
{ return input_impl::read(t_, src, s, n); }
std::streamsize write(const char_type* s, std::streamsize n)
{ return this->write(s, n, (basic_null_sink<char_type>*) 0); }
template<typename Sink>
std::streamsize write(const char_type* s, std::streamsize n, Sink* snk)
{ return output_impl::write(t_, snk, s, n); }
std::streampos seek( stream_offset off, BOOST_IOS::seekdir way,
BOOST_IOS::openmode which )
{
return this->seek( off, way, which,
(basic_null_device<char_type, seekable>*) 0);
}
template<typename Device>
std::streampos seek( stream_offset off, BOOST_IOS::seekdir way,
BOOST_IOS::openmode which, Device* dev )
{ return any_impl::seek(t_, dev, off, way, which); }
void close(BOOST_IOS::openmode which)
{ this->close(which, (basic_null_device<char_type, seekable>*) 0); }
template<typename Device>
void close(BOOST_IOS::openmode which, Device* dev)
{ any_impl::close(t_, dev, which); }
template<typename Device>
bool flush( Device* dev )
{
bool result = any_impl::flush(t_, dev);
if (dev && dev->BOOST_IOSTREAMS_PUBSYNC() == -1)
result = false;
return result;
}
template<typename Locale> // Avoid dependency on <locale>
void imbue(const Locale& loc) { iostreams::imbue(t_, loc); }
std::streamsize optimal_buffer_size() const
{ return iostreams::optimal_buffer_size(t_); }
public:
concept_adapter& operator=(const concept_adapter&);
value_type t_;
};
//------------------Specializations of device_wrapper_impl--------------------//
template<>
struct device_wrapper_impl<any_tag> {
template<typename Device, typename Dummy>
static std::streampos
seek( Device& dev, Dummy*, stream_offset off,
BOOST_IOS::seekdir way, BOOST_IOS::openmode which )
{
typedef typename category_of<Device>::type category;
return seek(dev, off, way, which, category());
}
template<typename Device>
static std::streampos
seek( Device&, stream_offset, BOOST_IOS::seekdir,
BOOST_IOS::openmode, any_tag )
{
boost::throw_exception(cant_seek());
BOOST_IOSTREAMS_UNREACHABLE_RETURN(0)
}
template<typename Device>
static std::streampos
seek( Device& dev, stream_offset off,
BOOST_IOS::seekdir way, BOOST_IOS::openmode which,
random_access )
{
return iostreams::seek(dev, off, way, which);
}
template<typename Device, typename Dummy>
static void close(Device& dev, Dummy*, BOOST_IOS::openmode which)
{ iostreams::close(dev, which); }
template<typename Device, typename Dummy>
static bool flush(Device& dev, Dummy*)
{ return iostreams::flush(dev); }
};
template<>
struct device_wrapper_impl<input> : device_wrapper_impl<any_tag> {
template<typename Device, typename Dummy>
static std::streamsize
read( Device& dev, Dummy*, typename char_type_of<Device>::type* s,
std::streamsize n )
{ return iostreams::read(dev, s, n); }
template<typename Device, typename Dummy>
static std::streamsize
write( Device&, Dummy*, const typename char_type_of<Device>::type*,
std::streamsize )
{ boost::throw_exception(cant_write());
BOOST_IOSTREAMS_UNREACHABLE_RETURN(0) }
};
template<>
struct device_wrapper_impl<output> {
template<typename Device, typename Dummy>
static std::streamsize
read(Device&, Dummy*, typename char_type_of<Device>::type*, std::streamsize)
{ boost::throw_exception(cant_read());
BOOST_IOSTREAMS_UNREACHABLE_RETURN(0) }
template<typename Device, typename Dummy>
static std::streamsize
write( Device& dev, Dummy*, const typename char_type_of<Device>::type* s,
std::streamsize n )
{ return iostreams::write(dev, s, n); }
};
//------------------Specializations of flt_wrapper_impl--------------------//
template<>
struct flt_wrapper_impl<any_tag> {
template<typename Filter, typename Device>
static std::streampos
seek( Filter& f, Device* dev, stream_offset off,
BOOST_IOS::seekdir way, BOOST_IOS::openmode which )
{
typedef typename category_of<Filter>::type category;
return seek(f, dev, off, way, which, category());
}
template<typename Filter, typename Device>
static std::streampos
seek( Filter&, Device*, stream_offset,
BOOST_IOS::seekdir, BOOST_IOS::openmode, any_tag )
{ boost::throw_exception(cant_seek());
BOOST_IOSTREAMS_UNREACHABLE_RETURN(0) }
template<typename Filter, typename Device>
static std::streampos
seek( Filter& f, Device* dev, stream_offset off,
BOOST_IOS::seekdir way, BOOST_IOS::openmode which,
random_access tag )
{
typedef typename category_of<Filter>::type category;
return seek(f, dev, off, way, which, tag, category());
}
template<typename Filter, typename Device>
static std::streampos
seek( Filter& f, Device* dev, stream_offset off,
BOOST_IOS::seekdir way, BOOST_IOS::openmode,
random_access, any_tag )
{ return f.seek(*dev, off, way); }
template<typename Filter, typename Device>
static std::streampos
seek( Filter& f, Device* dev, stream_offset off,
BOOST_IOS::seekdir way, BOOST_IOS::openmode which,
random_access, two_sequence )
{ return f.seek(*dev, off, way, which); }
template<typename Filter, typename Device>
static void close(Filter& f, Device* dev, BOOST_IOS::openmode which)
{ iostreams::close(f, *dev, which); }
template<typename Filter, typename Device>
static bool flush(Filter& f, Device* dev)
{ return iostreams::flush(f, *dev); }
};
template<>
struct flt_wrapper_impl<input> {
template<typename Filter, typename Source>
static std::streamsize
read( Filter& f, Source* src, typename char_type_of<Filter>::type* s,
std::streamsize n )
{ return iostreams::read(f, *src, s, n); }
template<typename Filter, typename Sink>
static std::streamsize
write( Filter&, Sink*, const typename char_type_of<Filter>::type*,
std::streamsize )
{ boost::throw_exception(cant_write());
BOOST_IOSTREAMS_UNREACHABLE_RETURN(0) }
};
template<>
struct flt_wrapper_impl<output> {
template<typename Filter, typename Source>
static std::streamsize
read(Filter&, Source*, typename char_type_of<Filter>::type*,std::streamsize)
{ boost::throw_exception(cant_read());
BOOST_IOSTREAMS_UNREACHABLE_RETURN(0) }
template<typename Filter, typename Sink>
static std::streamsize
write( Filter& f, Sink* snk, const typename char_type_of<Filter>::type* s,
std::streamsize n )
{ return iostreams::write(f, *snk, s, n); }
};
//----------------------------------------------------------------------------//
} } } // End namespaces detail, iostreams, boost.
#include <boost/iostreams/detail/config/enable_warnings.hpp> // MSVC.
#endif // #ifndef BOOST_IOSTREAMS_DETAIL_CONCEPT_ADAPTER_HPP_INCLUDED
@@ -0,0 +1,67 @@
/*
* Defines the class template boost::iostreams::detail::device_adapter,
* a convenience base class for device adapters.
*
* File: boost/iostreams/detail/adapter/filter_adapter.hpp
* Date: Mon Nov 26 14:35:48 MST 2007
*
* Copyright: 2007-2008 CodeRage, LLC
* Author: Jonathan Turkanis
* Contact: turkanis at coderage dot com
*
* 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_DEVICE_ADAPTER_HPP_INCLUDED
#define BOOST_IOSTREAMS_DETAIL_DEVICE_ADAPTER_HPP_INCLUDED
#include <boost/iostreams/categories.hpp>
#include <boost/iostreams/detail/call_traits.hpp>
#include <boost/iostreams/detail/ios.hpp>
#include <boost/iostreams/operations.hpp>
#include <boost/iostreams/traits.hpp>
#include <boost/static_assert.hpp>
namespace boost { namespace iostreams { namespace detail {
template<typename T>
class device_adapter {
private:
typedef typename detail::value_type<T>::type value_type;
typedef typename detail::param_type<T>::type param_type;
public:
explicit device_adapter(param_type t) : t_(t) { }
T& component() { return t_; }
void close()
{
detail::close_all(t_);
}
void close(BOOST_IOS::openmode which)
{
iostreams::close(t_, which);
}
bool flush()
{
return iostreams::flush(t_);
}
template<typename Locale> // Avoid dependency on <locale>
void imbue(const Locale& loc) { iostreams::imbue(t_, loc); }
std::streamsize optimal_buffer_size() const
{ return iostreams::optimal_buffer_size(t_); }
public:
value_type t_;
};
//----------------------------------------------------------------------------//
} } } // End namespaces detail, iostreams, boost.
#endif // #ifndef BOOST_IOSTREAMS_DETAIL_DEVICE_ADAPTER_HPP_INCLUDED
@@ -0,0 +1,281 @@
// (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
// (C) Copyright 2003-2007 Jonathan Turkanis
// 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_DIRECT_ADAPTER_HPP_INCLUDED
#define BOOST_IOSTREAMS_DETAIL_DIRECT_ADAPTER_HPP_INCLUDED
#if defined(_MSC_VER)
# pragma once
#endif
#include <boost/config.hpp> // SFINAE, MSVC, put ptrdiff_t in std.
#include <algorithm> // copy, min.
#include <cstddef> // ptrdiff_t.
#include <boost/detail/workaround.hpp>
#include <boost/iostreams/categories.hpp>
#include <boost/iostreams/detail/config/limits.hpp> // forwarding.
#include <boost/iostreams/detail/config/wide_streams.hpp> // locale.
#include <boost/iostreams/detail/double_object.hpp>
#include <boost/iostreams/detail/error.hpp>
#include <boost/iostreams/detail/ios.hpp> // openmode, seekdir, int types.
#include <boost/iostreams/traits.hpp> // mode_of, is_direct.
#include <boost/iostreams/operations.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/mpl/or.hpp>
#include <boost/preprocessor/iteration/local.hpp>
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/static_assert.hpp>
#include <boost/throw_exception.hpp>
#include <boost/type_traits/is_convertible.hpp>
// Must come last.
#include <boost/iostreams/detail/config/disable_warnings.hpp> // VC7.1
namespace boost { namespace iostreams { namespace detail {
//------------------Definition of direct_adapter_base-------------------------//
// Put all initialization in base class to faciliate forwarding.
template<typename Direct>
class direct_adapter_base {
public:
typedef typename char_type_of<Direct>::type char_type;
typedef typename mode_of<Direct>::type mode_type;
struct category
: mode_type,
device_tag,
closable_tag
#ifndef BOOST_IOSTREAMS_NO_LOCALE
, localizable_tag
#endif
{ };
protected:
explicit direct_adapter_base(const Direct& d);
typedef is_convertible<category, two_sequence> is_double;
struct pointers {
char_type *beg, *ptr, *end;
};
void init_input(mpl::true_);
void init_input(mpl::false_) { }
void init_output(mpl::true_);
void init_output(mpl::false_) { }
double_object<pointers, is_double> ptrs_;
Direct d_;
};
template<typename Direct>
class direct_adapter : private direct_adapter_base<Direct> {
private:
typedef direct_adapter_base<Direct> base_type;
typedef typename base_type::pointers pointers;
typedef typename base_type::is_double is_double;
using base_type::ptrs_;
using base_type::d_;
public:
typedef typename base_type::char_type char_type;
typedef typename base_type::category category;
// Constructors
#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1310)
direct_adapter(const Direct& d) : base_type(d) { }
direct_adapter(const direct_adapter& d) : base_type(d) { }
# define BOOST_PP_LOCAL_LIMITS (1, BOOST_IOSTREAMS_MAX_FORWARDING_ARITY)
#else
template<typename U>
struct is_direct
: mpl::or_<
is_same<U, direct_adapter<Direct> >,
is_same<U, Direct>
>
{ };
template<typename U>
direct_adapter(const U& u)
: base_type(forward(u, is_direct<U>()))
{ }
# define BOOST_PP_LOCAL_LIMITS (2, BOOST_IOSTREAMS_MAX_FORWARDING_ARITY)
#endif
#define BOOST_PP_LOCAL_MACRO(n) \
template<BOOST_PP_ENUM_PARAMS(n, typename P)> \
direct_adapter(BOOST_PP_ENUM_BINARY_PARAMS(n, const P, &p)) \
: base_type(Direct(BOOST_PP_ENUM_PARAMS(n, p))) \
{ } \
/**/
#include BOOST_PP_LOCAL_ITERATE()
#undef BOOST_PP_LOCAL_MACRO
// Device interface.
std::streamsize read(char_type* s, std::streamsize n);
std::streamsize write(const char_type* s, std::streamsize n);
std::streampos seek( stream_offset, BOOST_IOS::seekdir,
BOOST_IOS::openmode = BOOST_IOS::in | BOOST_IOS::out );
void close();
void close(BOOST_IOS::openmode which);
#ifndef BOOST_IOSTREAMS_NO_LOCALE
void imbue(const std::locale&);
#endif
// Direct device access.
Direct& operator*() { return d_; }
Direct* operator->() { return &d_; }
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1310)
private:
template<typename U>
static Direct forward(const U& u, mpl::true_) { return u; }
template<typename U>
static Direct forward(const U& u, mpl::false_) { return Direct(u); }
#endif
};
//--------------Definition of wrap_direct and unwrap_direct-------------------//
template<typename Device>
struct wrap_direct_traits
: mpl::if_<
is_direct<Device>,
direct_adapter<Device>,
Device
>
{ };
template<typename Device>
typename wrap_direct_traits<Device>::type
inline wrap_direct(Device dev)
{
typedef typename wrap_direct_traits<Device>::type type;
return type(dev);
}
template<typename Device>
inline Device& unwrap_direct(Device& d) { return d; }
template<typename Device>
inline Device& unwrap_direct(direct_adapter<Device>& d) { return *d; }
//--------------Implementation of direct_adapter_base-------------------------//
template<typename Direct>
direct_adapter_base<Direct>::direct_adapter_base(const Direct& d) : d_(d)
{
init_input(is_convertible<category, input>());
init_output(is_convertible<category, output>());
}
template<typename Direct>
void direct_adapter_base<Direct>::init_input(mpl::true_)
{
std::pair<char_type*, char_type*> seq = iostreams::input_sequence(d_);
ptrs_.first().beg = seq.first;
ptrs_.first().ptr = seq.first;
ptrs_.first().end = seq.second;
}
template<typename Direct>
void direct_adapter_base<Direct>::init_output(mpl::true_)
{
std::pair<char_type*, char_type*> seq = iostreams::output_sequence(d_);
ptrs_.second().beg = seq.first;
ptrs_.second().ptr = seq.first;
ptrs_.second().end = seq.second;
}
//--------------Implementation of direct_adapter------------------------------//
template<typename Direct>
inline std::streamsize direct_adapter<Direct>::read
(char_type* s, std::streamsize n)
{
using namespace std;
pointers& get = ptrs_.first();
std::streamsize avail =
static_cast<std::streamsize>(get.end - get.ptr);
std::streamsize result = (std::min)(n, avail);
std::copy(get.ptr, get.ptr + result, s);
get.ptr += result;
return result != 0 ? result : -1;
}
template<typename Direct>
inline std::streamsize direct_adapter<Direct>::write
(const char_type* s, std::streamsize n)
{
using namespace std;
pointers& put = ptrs_.second();
if (n > static_cast<std::streamsize>(put.end - put.ptr))
boost::throw_exception(write_area_exhausted());
std::copy(s, s + n, put.ptr);
put.ptr += n;
return n;
}
template<typename Direct>
inline std::streampos direct_adapter<Direct>::seek
( stream_offset off, BOOST_IOS::seekdir way,
BOOST_IOS::openmode which )
{
using namespace std;
pointers& get = ptrs_.first();
pointers& put = ptrs_.second();
if (way == BOOST_IOS::cur && get.ptr != put.ptr)
boost::throw_exception(bad_seek());
ptrdiff_t next = 0;
if ((which & BOOST_IOS::in) || !is_double::value) {
if (way == BOOST_IOS::beg)
next = off;
else if (way == BOOST_IOS::cur)
next = get.ptr - get.beg + off;
else
next = get.end - get.beg + off;
if (next >= 0 && next <= get.end - get.beg)
get.ptr = get.beg + next;
else
boost::throw_exception(bad_seek());
}
if ((which & BOOST_IOS::out) && is_double::value) {
if (way == BOOST_IOS::beg)
next = off;
else if (way == BOOST_IOS::cur)
next = put.ptr - put.beg + off;
else
next = put.end - put.beg + off;
if (next >= 0 && next <= put.end - put.beg)
put.ptr = put.beg + next;
else
boost::throw_exception(bad_seek());
}
return offset_to_position(next);
}
template<typename Direct>
void direct_adapter<Direct>::close()
{
BOOST_STATIC_ASSERT((!is_convertible<category, two_sequence>::value));
detail::close_all(d_);
}
template<typename Direct>
void direct_adapter<Direct>::close(BOOST_IOS::openmode which)
{
BOOST_STATIC_ASSERT((is_convertible<category, two_sequence>::value));
boost::iostreams::close(d_, which);
}
#ifndef BOOST_IOSTREAMS_NO_LOCALE
template<typename Direct>
void direct_adapter<Direct>::imbue(const std::locale& loc)
{ boost::iostreams::imbue(d_, loc); }
#endif
} } } // End namespaces detail, iostreams, boost.
#include <boost/iostreams/detail/config/enable_warnings.hpp>
#endif // #ifndef BOOST_IOSTREAMS_DETAIL_DIRECT_ADAPTER_HPP_INCLUDED
@@ -0,0 +1,69 @@
/*
* Defines the class template boost::iostreams::detail::filter_adapter,
* a convenience base class for filter adapters.
*
* File: boost/iostreams/detail/adapter/filter_adapter.hpp
* Date: Mon Nov 26 14:35:48 MST 2007
* Copyright: 2007-2008 CodeRage, LLC
* Author: Jonathan Turkanis
* Contact: turkanis at coderage dot com
*
* 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_FILTER_ADAPTER_HPP_INCLUDED
#define BOOST_IOSTREAMS_DETAIL_FILTER_ADAPTER_HPP_INCLUDED
#include <boost/iostreams/categories.hpp>
#include <boost/iostreams/detail/call_traits.hpp>
#include <boost/iostreams/detail/ios.hpp>
#include <boost/iostreams/operations.hpp>
#include <boost/iostreams/traits.hpp>
#include <boost/static_assert.hpp>
namespace boost { namespace iostreams { namespace detail {
template<typename T>
class filter_adapter {
private:
typedef typename detail::value_type<T>::type value_type;
typedef typename detail::param_type<T>::type param_type;
public:
explicit filter_adapter(param_type t) : t_(t) { }
T& component() { return t_; }
template<typename Device>
void close(Device& dev)
{
detail::close_all(t_, dev);
}
template<typename Device>
void close(Device& dev, BOOST_IOS::openmode which)
{
iostreams::close(t_, dev, which);
}
template<typename Device>
void flush(Device& dev)
{
return iostreams::flush(t_, dev);
}
template<typename Locale> // Avoid dependency on <locale>
void imbue(const Locale& loc) { iostreams::imbue(t_, loc); }
std::streamsize optimal_buffer_size() const
{ return iostreams::optimal_buffer_size(t_); }
public:
value_type t_;
};
//----------------------------------------------------------------------------//
} } } // End namespaces detail, iostreams, boost.
#endif // #ifndef BOOST_IOSTREAMS_DETAIL_FILTER_ADAPTER_HPP_INCLUDED
@@ -0,0 +1,117 @@
// (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
// (C) Copyright 2003-2007 Jonathan Turkanis
// 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_MODE_ADAPTER_HPP_INCLUDED
#define BOOST_IOSTREAMS_DETAIL_MODE_ADAPTER_HPP_INCLUDED
#if defined(_MSC_VER)
# pragma once
#endif
// Contains the definition of the class template mode_adapter, which allows
// a filter or device to function as if it has a different i/o mode than that
// deduced by the metafunction mode_of.
#include <boost/config.hpp> // BOOST_MSVC.
#include <boost/detail/workaround.hpp>
#include <boost/iostreams/categories.hpp>
#include <boost/iostreams/detail/ios.hpp> // openmode, seekdir, int types.
#include <boost/iostreams/traits.hpp>
#include <boost/iostreams/operations.hpp>
#include <boost/mpl/if.hpp>
namespace boost { namespace iostreams { namespace detail {
template<typename Mode, typename T>
class mode_adapter {
private:
struct empty_base { };
public:
typedef typename wrapped_type<T>::type component_type;
typedef typename char_type_of<T>::type char_type;
struct category
: Mode,
device_tag,
mpl::if_<is_filter<T>, filter_tag, device_tag>,
mpl::if_<is_filter<T>, multichar_tag, empty_base>,
closable_tag,
localizable_tag
{ };
explicit mode_adapter(const component_type& t) : t_(t) { }
// Device member functions.
std::streamsize read(char_type* s, std::streamsize n);
std::streamsize write(const char_type* s, std::streamsize n);
std::streampos seek( stream_offset off, BOOST_IOS::seekdir way,
BOOST_IOS::openmode which =
BOOST_IOS::in | BOOST_IOS::out );
void close();
void close(BOOST_IOS::openmode which);
// Filter member functions.
template<typename Source>
std::streamsize read(Source& src, char_type* s, std::streamsize n)
{ return iostreams::read(t_, src, s, n); }
template<typename Sink>
std::streamsize write(Sink& snk, const char_type* s, std::streamsize n)
{ return iostreams::write(t_, snk, s, n); }
template<typename Device>
std::streampos seek(Device& dev, stream_offset off, BOOST_IOS::seekdir way)
{ return iostreams::seek(t_, dev, off, way); }
template<typename Device>
std::streampos seek( Device& dev, stream_offset off,
BOOST_IOS::seekdir way, BOOST_IOS::openmode which )
{ return iostreams::seek(t_, dev, off, way, which); }
template<typename Device>
void close(Device& dev)
{ detail::close_all(t_, dev); }
template<typename Device>
void close(Device& dev, BOOST_IOS::openmode which)
{ iostreams::close(t_, dev, which); }
template<typename Locale>
void imbue(const Locale& loc)
{ iostreams::imbue(t_, loc); }
private:
component_type t_;
};
//------------------Implementation of mode_adapter----------------------------//
template<typename Mode, typename T>
std::streamsize mode_adapter<Mode, T>::read
(char_type* s, std::streamsize n)
{ return boost::iostreams::read(t_, s, n); }
template<typename Mode, typename T>
std::streamsize mode_adapter<Mode, T>::write
(const char_type* s, std::streamsize n)
{ return boost::iostreams::write(t_, s, n); }
template<typename Mode, typename T>
std::streampos mode_adapter<Mode, T>::seek
(stream_offset off, BOOST_IOS::seekdir way, BOOST_IOS::openmode which)
{ return boost::iostreams::seek(t_, off, way, which); }
template<typename Mode, typename T>
void mode_adapter<Mode, T>::close()
{ detail::close_all(t_); }
template<typename Mode, typename T>
void mode_adapter<Mode, T>::close(BOOST_IOS::openmode which)
{ iostreams::close(t_, which); }
} } } // End namespaces detail, iostreams, boost.
#endif // #ifndef BOOST_IOSTREAMS_DETAIL_MODE_ADAPTER_HPP_INCLUDED //-----//
@@ -0,0 +1,59 @@
// (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
// (C) Copyright 2005-2007 Jonathan Turkanis
// 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_NON_BLOCKING_ADAPTER_HPP_INCLUDED
#define BOOST_IOSTREAMS_DETAIL_NON_BLOCKING_ADAPTER_HPP_INCLUDED
#include <boost/iostreams/detail/ios.hpp> // streamsize, seekdir, openmode.
#include <boost/iostreams/read.hpp>
#include <boost/iostreams/seek.hpp>
#include <boost/iostreams/traits.hpp>
#include <boost/iostreams/write.hpp>
namespace boost { namespace iostreams {
template<typename Device>
class non_blocking_adapter {
public:
typedef typename char_type_of<Device>::type char_type;
struct category
: mode_of<Device>::type, device_tag
{ };
explicit non_blocking_adapter(Device& dev) : device_(dev) { }
std::streamsize read(char_type* s, std::streamsize n)
{
std::streamsize result = 0;
while (result < n) {
std::streamsize amt = iostreams::read(device_, s, n);
if (amt == -1)
break;
result += amt;
}
return result != 0 ? result : -1;
}
std::streamsize write(const char_type* s, std::streamsize n)
{
std::streamsize result = 0;
while (result < n) {
std::streamsize amt =
iostreams::write(device_, s + result, n - result);
result += amt;
}
return result;
}
std::streampos seek( stream_offset off, BOOST_IOS::seekdir way,
BOOST_IOS::openmode which =
BOOST_IOS::in | BOOST_IOS::out )
{ return iostreams::seek(device_, off, way, which); }
public:
non_blocking_adapter& operator=(const non_blocking_adapter&);
Device& device_;
};
} } // End namespace iostreams.
#endif // #ifndef BOOST_IOSTREAMS_DETAIL_NON_BLOCKING_ADAPTER_HPP_INCLUDED
@@ -0,0 +1,41 @@
// (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
// (C) Copyright 2003-2007 Jonathan Turkanis
// 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_OUTPUT_ITERATOR_ADAPTER_HPP_INCLUDED
#define BOOST_IOSTREAMS_DETAIL_OUTPUT_ITERATOR_ADAPTER_HPP_INCLUDED
#if defined(_MSC_VER)
# pragma once
#endif
#include <algorithm> // copy.
#include <iosfwd> // streamsize.
#include <boost/iostreams/categories.hpp> // tags.
#include <boost/static_assert.hpp>
#include <boost/type_traits/is_convertible.hpp>
namespace boost { namespace iostreams { namespace detail {
template<typename Mode, typename Ch, typename OutIt>
class output_iterator_adapter {
public:
BOOST_STATIC_ASSERT((is_convertible<Mode, output>::value));
typedef Ch char_type;
typedef sink_tag category;
explicit output_iterator_adapter(OutIt out) : out_(out) { }
std::streamsize write(const char_type* s, std::streamsize n)
{
std::copy(s, s + n, out_);
return n;
}
private:
OutIt out_;
};
} } } // End namespaces detail, iostreams, boost.
#endif // #ifndef BOOST_IOSTREAMS_DETAIL_OUTPUT_ITERATOR_ADAPTER_HPP_INCLUDED //-----//
@@ -0,0 +1,187 @@
// (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
// (C) Copyright 2003-2007 Jonathan Turkanis
// 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_RANGE_ADAPTER_HPP_INCLUDED
#define BOOST_IOSTREAMS_DETAIL_RANGE_ADAPTER_HPP_INCLUDED
#if defined(_MSC_VER)
# pragma once
#endif
#include <algorithm> // min.
#include <boost/assert.hpp>
#include <cstddef> // ptrdiff_t.
#include <iosfwd> // streamsize, streamoff.
#include <boost/detail/iterator.hpp> // boost::iterator_traits.
#include <boost/iostreams/categories.hpp>
#include <boost/iostreams/detail/error.hpp>
#include <boost/iostreams/positioning.hpp>
#include <boost/mpl/if.hpp>
#include <boost/throw_exception.hpp>
#include <boost/type_traits/is_convertible.hpp>
#include <boost/utility/enable_if.hpp>
// Must come last.
#include <boost/iostreams/detail/config/disable_warnings.hpp> // MSVC.
namespace boost { namespace iostreams { namespace detail {
// Used for simulated tag dispatch.
template<typename Traversal> struct range_adapter_impl;
//
// Template name: range_adapter
// Description: Device based on an instance of boost::iterator_range.
// Template parameters:
// Mode - A mode tag.
// Range - An instance of iterator_range.
//
template<typename Mode, typename Range>
class range_adapter {
private:
typedef typename Range::iterator iterator;
typedef boost::detail::iterator_traits<iterator> iter_traits;
typedef typename iter_traits::iterator_category iter_cat;
public:
typedef typename Range::value_type char_type;
struct category : Mode, device_tag { };
typedef typename
mpl::if_<
is_convertible<
iter_cat,
std::random_access_iterator_tag
>,
std::random_access_iterator_tag,
std::forward_iterator_tag
>::type tag;
typedef range_adapter_impl<tag> impl;
explicit range_adapter(const Range& rng);
range_adapter(iterator first, iterator last);
std::streamsize read(char_type* s, std::streamsize n);
std::streamsize write(const char_type* s, std::streamsize n);
std::streampos seek(stream_offset off, BOOST_IOS::seekdir way);
private:
iterator first_, cur_, last_;
};
//------------------Implementation of range_adapter---------------------------//
template<typename Mode, typename Range>
range_adapter<Mode, Range>::range_adapter(const Range& rng)
: first_(rng.begin()), cur_(rng.begin()), last_(rng.end()) { }
template<typename Mode, typename Range>
range_adapter<Mode, Range>::range_adapter(iterator first, iterator last)
: first_(first), cur_(first), last_(last) { }
template<typename Mode, typename Range>
inline std::streamsize range_adapter<Mode, Range>::read
(char_type* s, std::streamsize n)
{ return impl::read(cur_, last_, s, n); }
template<typename Mode, typename Range>
inline std::streamsize range_adapter<Mode, Range>::write
(const char_type* s, std::streamsize n)
{ return impl::write(cur_, last_, s, n); }
template<typename Mode, typename Range>
std::streampos range_adapter<Mode, Range>::seek
(stream_offset off, BOOST_IOS::seekdir way)
{
impl::seek(first_, cur_, last_, off, way);
return offset_to_position(cur_ - first_);
}
//------------------Implementation of range_adapter_impl----------------------//
template<>
struct range_adapter_impl<std::forward_iterator_tag> {
template<typename Iter, typename Ch>
static std::streamsize read
(Iter& cur, Iter& last, Ch* s,std::streamsize n)
{
std::streamsize rem = n; // No. of chars remaining.
while (cur != last && rem-- > 0) *s++ = *cur++;
return n - rem != 0 ? n - rem : -1;
}
template<typename Iter, typename Ch>
static std::streamsize write
(Iter& cur, Iter& last, const Ch* s, std::streamsize n)
{
while (cur != last && n-- > 0) *cur++ = *s++;
if (cur == last && n > 0)
boost::throw_exception(write_area_exhausted());
return n;
}
};
template<>
struct range_adapter_impl<std::random_access_iterator_tag> {
template<typename Iter, typename Ch>
static std::streamsize read
(Iter& cur, Iter& last, Ch* s,std::streamsize n)
{
std::streamsize result =
(std::min)(static_cast<std::streamsize>(last - cur), n);
if (result)
std::copy(cur, cur + result, s);
cur += result;
return result != 0 ? result : -1;
}
template<typename Iter, typename Ch>
static std::streamsize write
(Iter& cur, Iter& last, const Ch* s, std::streamsize n)
{
std::streamsize count =
(std::min)(static_cast<std::streamsize>(last - cur), n);
std::copy(s, s + count, cur);
cur += count;
if (count < n)
boost::throw_exception(write_area_exhausted());
return n;
}
template<typename Iter>
static void seek
( Iter& first, Iter& cur, Iter& last, stream_offset off,
BOOST_IOS::seekdir way )
{
using namespace std;
switch (way) {
case BOOST_IOS::beg:
if (off > last - first || off < 0)
boost::throw_exception(bad_seek());
cur = first + off;
break;
case BOOST_IOS::cur:
{
std::ptrdiff_t newoff = cur - first + off;
if (newoff > last - first || newoff < 0)
boost::throw_exception(bad_seek());
cur += off;
break;
}
case BOOST_IOS::end:
if (last - first + off < 0 || off > 0)
boost::throw_exception(bad_seek());
cur = last + off;
break;
default:
BOOST_ASSERT(0);
}
}
};
} } } // End namespaces detail, iostreams, boost.
#include <boost/iostreams/detail/config/enable_warnings.hpp> // MSVC.
#endif // #ifndef BOOST_IOSTREAMS_DETAIL_RANGE_ADAPTER_HPP_INCLUDED //---------------//