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,113 @@
// (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_CHAINBUF_HPP_INCLUDED
#define BOOST_IOSTREAMS_DETAIL_CHAINBUF_HPP_INCLUDED
#if defined(_MSC_VER)
# pragma once
#endif
#include <boost/config.hpp> // BOOST_MSVC, template friends.
#include <boost/detail/workaround.hpp>
#include <boost/iostreams/chain.hpp>
#include <boost/iostreams/detail/access_control.hpp>
#include <boost/iostreams/detail/config/wide_streams.hpp>
#include <boost/iostreams/detail/streambuf.hpp>
#include <boost/iostreams/detail/streambuf/linked_streambuf.hpp>
#include <boost/iostreams/detail/translate_int_type.hpp>
#include <boost/iostreams/traits.hpp>
#include <boost/noncopyable.hpp>
namespace boost { namespace iostreams { namespace detail {
//--------------Definition of chainbuf----------------------------------------//
//
// Template name: chainbuf.
// Description: Stream buffer which operates by delegating to the first
// linked_streambuf in a chain.
// Template parameters:
// Chain - The chain type.
//
template<typename Chain, typename Mode, typename Access>
class chainbuf
: public BOOST_IOSTREAMS_BASIC_STREAMBUF(
typename Chain::char_type,
typename Chain::traits_type
),
public access_control<typename Chain::client_type, Access>,
private noncopyable
{
private:
typedef access_control<chain_client<Chain>, Access> client_type;
public:
typedef typename Chain::char_type char_type;
BOOST_IOSTREAMS_STREAMBUF_TYPEDEFS(typename Chain::traits_type)
protected:
typedef linked_streambuf<char_type, traits_type> delegate_type;
chainbuf() { client_type::set_chain(&chain_); }
int_type underflow()
{ sentry t(this); return translate(delegate().underflow()); }
int_type pbackfail(int_type c)
{ sentry t(this); return translate(delegate().pbackfail(c)); }
std::streamsize xsgetn(char_type* s, std::streamsize n)
{ sentry t(this); return delegate().xsgetn(s, n); }
int_type overflow(int_type c)
{ sentry t(this); return translate(delegate().overflow(c)); }
std::streamsize xsputn(const char_type* s, std::streamsize n)
{ sentry t(this); return delegate().xsputn(s, n); }
int sync() { sentry t(this); return delegate().sync(); }
pos_type seekoff( off_type off, BOOST_IOS::seekdir way,
BOOST_IOS::openmode which =
BOOST_IOS::in | BOOST_IOS::out )
{ sentry t(this); return delegate().seekoff(off, way, which); }
pos_type seekpos( pos_type sp,
BOOST_IOS::openmode which =
BOOST_IOS::in | BOOST_IOS::out )
{ sentry t(this); return delegate().seekpos(sp, which); }
protected:
typedef BOOST_IOSTREAMS_BASIC_STREAMBUF(
typename Chain::char_type,
typename Chain::traits_type
) base_type;
private:
// Translate from std int_type to chain's int_type.
typedef BOOST_IOSTREAMS_CHAR_TRAITS(char_type) std_traits;
typedef typename Chain::traits_type chain_traits;
static typename chain_traits::int_type
translate(typename std_traits::int_type c)
{ return translate_int_type<std_traits, chain_traits>(c); }
delegate_type& delegate()
{ return static_cast<delegate_type&>(chain_.front()); }
void get_pointers()
{
this->setg(delegate().eback(), delegate().gptr(), delegate().egptr());
this->setp(delegate().pbase(), delegate().epptr());
this->pbump((int) (delegate().pptr() - delegate().pbase()));
}
void set_pointers()
{
delegate().setg(this->eback(), this->gptr(), this->egptr());
delegate().setp(this->pbase(), this->epptr());
delegate().pbump((int) (this->pptr() - this->pbase()));
}
struct sentry {
sentry(chainbuf<Chain, Mode, Access>* buf) : buf_(buf)
{ buf_->set_pointers(); }
~sentry() { buf_->get_pointers(); }
chainbuf<Chain, Mode, Access>* buf_;
};
friend struct sentry;
Chain chain_;
};
} } } // End namespaces detail, iostreams, boost.
#endif // #ifndef BOOST_IOSTREAMS_DETAIL_CHAINBUF_HPP_INCLUDED
@@ -0,0 +1,311 @@
// (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_STREAMBUF_HPP_INCLUDED
#define BOOST_IOSTREAMS_DETAIL_DIRECT_STREAMBUF_HPP_INCLUDED
#if defined(_MSC_VER)
# pragma once
#endif
#include <boost/assert.hpp>
#include <cstddef>
#include <typeinfo>
#include <utility> // pair.
#include <boost/config.hpp> // BOOST_DEDUCED_TYPENAME,
#include <boost/iostreams/detail/char_traits.hpp> // member template friends.
#include <boost/iostreams/detail/config/wide_streams.hpp>
#include <boost/iostreams/detail/error.hpp>
#include <boost/iostreams/detail/execute.hpp>
#include <boost/iostreams/detail/functional.hpp>
#include <boost/iostreams/detail/ios.hpp>
#include <boost/iostreams/detail/optional.hpp>
#include <boost/iostreams/detail/streambuf.hpp>
#include <boost/iostreams/detail/streambuf/linked_streambuf.hpp>
#include <boost/iostreams/operations.hpp>
#include <boost/iostreams/positioning.hpp>
#include <boost/iostreams/traits.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 T,
typename Tr =
BOOST_IOSTREAMS_CHAR_TRAITS(
BOOST_DEDUCED_TYPENAME char_type_of<T>::type
) >
class direct_streambuf
: public linked_streambuf<BOOST_DEDUCED_TYPENAME char_type_of<T>::type, Tr>
{
public:
typedef typename char_type_of<T>::type char_type;
BOOST_IOSTREAMS_STREAMBUF_TYPEDEFS(Tr)
private:
typedef linked_streambuf<char_type, traits_type> base_type;
typedef typename category_of<T>::type category;
typedef BOOST_IOSTREAMS_BASIC_STREAMBUF(
char_type, traits_type
) streambuf_type;
public: // stream needs access.
void open(const T& t, std::streamsize buffer_size,
std::streamsize pback_size);
bool is_open() const;
void close();
bool auto_close() const { return auto_close_; }
void set_auto_close(bool close) { auto_close_ = close; }
bool strict_sync() { return true; }
// Declared in linked_streambuf.
T* component() { return storage_.get(); }
protected:
BOOST_IOSTREAMS_USING_PROTECTED_STREAMBUF_MEMBERS(base_type)
direct_streambuf();
//--------------Virtual functions-----------------------------------------//
// Declared in linked_streambuf.
void close_impl(BOOST_IOS::openmode m);
const std::type_info& component_type() const { return typeid(T); }
void* component_impl() { return component(); }
#ifdef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES
public:
#endif
// Declared in basic_streambuf.
int_type underflow();
int_type pbackfail(int_type c);
int_type overflow(int_type c);
pos_type seekoff( off_type off, BOOST_IOS::seekdir way,
BOOST_IOS::openmode which );
pos_type seekpos(pos_type sp, BOOST_IOS::openmode which);
private:
pos_type seek_impl( stream_offset off, BOOST_IOS::seekdir way,
BOOST_IOS::openmode which );
void init_input(any_tag) { }
void init_input(input);
void init_output(any_tag) { }
void init_output(output);
void init_get_area();
void init_put_area();
bool one_head() const;
bool two_head() const;
optional<T> storage_;
char_type *ibeg_, *iend_, *obeg_, *oend_;
bool auto_close_;
};
//------------------Implementation of direct_streambuf------------------------//
template<typename T, typename Tr>
direct_streambuf<T, Tr>::direct_streambuf()
: ibeg_(0), iend_(0), obeg_(0), oend_(0), auto_close_(true)
{ this->set_true_eof(true); }
template<typename T, typename Tr>
void direct_streambuf<T, Tr>::open
(const T& t, std::streamsize, std::streamsize)
{
storage_.reset(t);
init_input(category());
init_output(category());
setg(0, 0, 0);
setp(0, 0);
this->set_needs_close();
}
template<typename T, typename Tr>
bool direct_streambuf<T, Tr>::is_open() const
{ return ibeg_ != 0 || obeg_ != 0; }
template<typename T, typename Tr>
void direct_streambuf<T, Tr>::close()
{
base_type* self = this;
detail::execute_all( detail::call_member_close(*self, BOOST_IOS::in),
detail::call_member_close(*self, BOOST_IOS::out),
detail::call_reset(storage_) );
}
template<typename T, typename Tr>
typename direct_streambuf<T, Tr>::int_type
direct_streambuf<T, Tr>::underflow()
{
if (!ibeg_)
boost::throw_exception(cant_read());
if (!gptr())
init_get_area();
return gptr() != iend_ ?
traits_type::to_int_type(*gptr()) :
traits_type::eof();
}
template<typename T, typename Tr>
typename direct_streambuf<T, Tr>::int_type
direct_streambuf<T, Tr>::pbackfail(int_type c)
{
using namespace std;
if (!ibeg_)
boost::throw_exception(cant_read());
if (gptr() != 0 && gptr() != ibeg_) {
gbump(-1);
if (!traits_type::eq_int_type(c, traits_type::eof()))
*gptr() = traits_type::to_char_type(c);
return traits_type::not_eof(c);
}
boost::throw_exception(bad_putback());
}
template<typename T, typename Tr>
typename direct_streambuf<T, Tr>::int_type
direct_streambuf<T, Tr>::overflow(int_type c)
{
using namespace std;
if (!obeg_)
boost::throw_exception(BOOST_IOSTREAMS_FAILURE("no write access"));
if (!pptr()) init_put_area();
if (!traits_type::eq_int_type(c, traits_type::eof())) {
if (pptr() == oend_)
boost::throw_exception(
BOOST_IOSTREAMS_FAILURE("write area exhausted")
);
*pptr() = traits_type::to_char_type(c);
pbump(1);
return c;
}
return traits_type::not_eof(c);
}
template<typename T, typename Tr>
inline typename direct_streambuf<T, Tr>::pos_type
direct_streambuf<T, Tr>::seekoff
(off_type off, BOOST_IOS::seekdir way, BOOST_IOS::openmode which)
{ return seek_impl(off, way, which); }
template<typename T, typename Tr>
inline typename direct_streambuf<T, Tr>::pos_type
direct_streambuf<T, Tr>::seekpos
(pos_type sp, BOOST_IOS::openmode which)
{
return seek_impl(position_to_offset(sp), BOOST_IOS::beg, which);
}
template<typename T, typename Tr>
void direct_streambuf<T, Tr>::close_impl(BOOST_IOS::openmode which)
{
if (which == BOOST_IOS::in && ibeg_ != 0) {
setg(0, 0, 0);
ibeg_ = iend_ = 0;
}
if (which == BOOST_IOS::out && obeg_ != 0) {
sync();
setp(0, 0);
obeg_ = oend_ = 0;
}
boost::iostreams::close(*storage_, which);
}
template<typename T, typename Tr>
typename direct_streambuf<T, Tr>::pos_type direct_streambuf<T, Tr>::seek_impl
(stream_offset off, BOOST_IOS::seekdir way, BOOST_IOS::openmode which)
{
using namespace std;
BOOST_IOS::openmode both = BOOST_IOS::in | BOOST_IOS::out;
if (two_head() && (which & both) == both)
boost::throw_exception(bad_seek());
stream_offset result = -1;
bool one = one_head();
if (one && (pptr() != 0 || gptr()== 0))
init_get_area(); // Switch to input mode, for code reuse.
if (one || ((which & BOOST_IOS::in) != 0 && ibeg_ != 0)) {
if (!gptr()) setg(ibeg_, ibeg_, iend_);
ptrdiff_t next = 0;
switch (way) {
case BOOST_IOS::beg: next = off; break;
case BOOST_IOS::cur: next = (gptr() - ibeg_) + off; break;
case BOOST_IOS::end: next = (iend_ - ibeg_) + off; break;
default: BOOST_ASSERT(0);
}
if (next < 0 || next > (iend_ - ibeg_))
boost::throw_exception(bad_seek());
setg(ibeg_, ibeg_ + next, iend_);
result = next;
}
if (!one && (which & BOOST_IOS::out) != 0 && obeg_ != 0) {
if (!pptr()) setp(obeg_, oend_);
ptrdiff_t next = 0;
switch (way) {
case BOOST_IOS::beg: next = off; break;
case BOOST_IOS::cur: next = (pptr() - obeg_) + off; break;
case BOOST_IOS::end: next = (oend_ - obeg_) + off; break;
default: BOOST_ASSERT(0);
}
if (next < 0 || next > (oend_ - obeg_))
boost::throw_exception(bad_seek());
pbump(static_cast<int>(next - (pptr() - obeg_)));
result = next;
}
return offset_to_position(result);
}
template<typename T, typename Tr>
void direct_streambuf<T, Tr>::init_input(input)
{
std::pair<char_type*, char_type*> p = input_sequence(*storage_);
ibeg_ = p.first;
iend_ = p.second;
}
template<typename T, typename Tr>
void direct_streambuf<T, Tr>::init_output(output)
{
std::pair<char_type*, char_type*> p = output_sequence(*storage_);
obeg_ = p.first;
oend_ = p.second;
}
template<typename T, typename Tr>
void direct_streambuf<T, Tr>::init_get_area()
{
setg(ibeg_, ibeg_, iend_);
if (one_head() && pptr()) {
gbump(static_cast<int>(pptr() - obeg_));
setp(0, 0);
}
}
template<typename T, typename Tr>
void direct_streambuf<T, Tr>::init_put_area()
{
setp(obeg_, oend_);
if (one_head() && gptr()) {
pbump(static_cast<int>(gptr() - ibeg_));
setg(0, 0, 0);
}
}
template<typename T, typename Tr>
inline bool direct_streambuf<T, Tr>::one_head() const
{ return ibeg_ && obeg_ && ibeg_ == obeg_; }
template<typename T, typename Tr>
inline bool direct_streambuf<T, Tr>::two_head() const
{ return ibeg_ && obeg_ && ibeg_ != obeg_; }
//----------------------------------------------------------------------------//
} // End namespace detail.
} } // End namespaces iostreams, boost.
#include <boost/iostreams/detail/config/enable_warnings.hpp> // MSVC
#endif // #ifndef BOOST_IOSTREAMS_DETAIL_DIRECT_STREAMBUF_HPP_INCLUDED
@@ -0,0 +1,447 @@
// (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.
// This material is heavily indebted to the discussion and code samples in
// A. Langer and K. Kreft, "Standard C++ IOStreams and Locales",
// Addison-Wesley, 2000, pp. 228-43.
// User "GMSB" provided an optimization for small seeks.
#ifndef BOOST_IOSTREAMS_DETAIL_INDIRECT_STREAMBUF_HPP_INCLUDED
#define BOOST_IOSTREAMS_DETAIL_INDIRECT_STREAMBUF_HPP_INCLUDED
#include <algorithm> // min, max.
#include <cassert>
#include <exception>
#include <typeinfo>
#include <boost/config.hpp> // Member template friends.
#include <boost/detail/workaround.hpp>
#include <boost/iostreams/constants.hpp>
#include <boost/iostreams/detail/adapter/concept_adapter.hpp>
#include <boost/iostreams/detail/buffer.hpp>
#include <boost/iostreams/detail/config/wide_streams.hpp>
#include <boost/iostreams/detail/double_object.hpp>
#include <boost/iostreams/detail/execute.hpp>
#include <boost/iostreams/detail/functional.hpp>
#include <boost/iostreams/detail/ios.hpp>
#include <boost/iostreams/detail/optional.hpp>
#include <boost/iostreams/detail/push.hpp>
#include <boost/iostreams/detail/streambuf/linked_streambuf.hpp>
#include <boost/iostreams/operations.hpp>
#include <boost/iostreams/positioning.hpp>
#include <boost/iostreams/traits.hpp>
#include <boost/iostreams/operations.hpp>
#include <boost/mpl/if.hpp>
#include <boost/throw_exception.hpp>
#include <boost/type_traits/is_convertible.hpp>
// Must come last.
#include <boost/iostreams/detail/config/disable_warnings.hpp> // MSVC, BCC 5.x
namespace boost { namespace iostreams { namespace detail {
//
// Description: The implementation of basic_streambuf used by chains.
//
template<typename T, typename Tr, typename Alloc, typename Mode>
class indirect_streambuf
: public linked_streambuf<BOOST_DEDUCED_TYPENAME char_type_of<T>::type, Tr>
{
public:
typedef typename char_type_of<T>::type char_type;
BOOST_IOSTREAMS_STREAMBUF_TYPEDEFS(Tr)
private:
typedef typename category_of<T>::type category;
typedef concept_adapter<T> wrapper;
typedef detail::basic_buffer<char_type, Alloc> buffer_type;
typedef indirect_streambuf<T, Tr, Alloc, Mode> my_type;
typedef detail::linked_streambuf<char_type, traits_type> base_type;
typedef linked_streambuf<char_type, Tr> streambuf_type;
public:
indirect_streambuf();
void open(const T& t BOOST_IOSTREAMS_PUSH_PARAMS());
bool is_open() const;
void close();
bool auto_close() const;
void set_auto_close(bool close);
bool strict_sync();
// Declared in linked_streambuf.
T* component() { return &*obj(); }
protected:
BOOST_IOSTREAMS_USING_PROTECTED_STREAMBUF_MEMBERS(base_type)
//----------virtual functions---------------------------------------------//
#ifndef BOOST_IOSTREAMS_NO_LOCALE
void imbue(const std::locale& loc);
#endif
#ifdef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES
public:
#endif
int_type underflow();
int_type pbackfail(int_type c);
int_type overflow(int_type c);
int sync();
pos_type seekoff( off_type off, BOOST_IOS::seekdir way,
BOOST_IOS::openmode which );
pos_type seekpos(pos_type sp, BOOST_IOS::openmode which);
// Declared in linked_streambuf.
void set_next(streambuf_type* next);
void close_impl(BOOST_IOS::openmode m);
const std::type_info& component_type() const { return typeid(T); }
void* component_impl() { return component(); }
private:
//----------Accessor functions--------------------------------------------//
wrapper& obj() { return *storage_; }
streambuf_type* next() const { return next_; }
buffer_type& in() { return buffer_.first(); }
buffer_type& out() { return buffer_.second(); }
bool can_read() const { return is_convertible<Mode, input>::value; }
bool can_write() const { return is_convertible<Mode, output>::value; }
bool output_buffered() const { return (flags_ & f_output_buffered) != 0; }
bool shared_buffer() const { return is_convertible<Mode, seekable>::value || is_convertible<Mode, dual_seekable>::value; }
void set_flags(int f) { flags_ = f; }
//----------State changing functions--------------------------------------//
virtual void init_get_area();
virtual void init_put_area();
//----------Utility function----------------------------------------------//
pos_type seek_impl( stream_offset off, BOOST_IOS::seekdir way,
BOOST_IOS::openmode which );
void sync_impl();
enum flag_type {
f_open = 1,
f_output_buffered = f_open << 1,
f_auto_close = f_output_buffered << 1
};
optional<wrapper> storage_;
streambuf_type* next_;
double_object<
buffer_type,
is_convertible<
Mode,
two_sequence
>
> buffer_;
std::streamsize pback_size_;
int flags_;
};
//--------------Implementation of indirect_streambuf--------------------------//
template<typename T, typename Tr, typename Alloc, typename Mode>
indirect_streambuf<T, Tr, Alloc, Mode>::indirect_streambuf()
: next_(0), pback_size_(0), flags_(f_auto_close) { }
//--------------Implementation of open, is_open and close---------------------//
template<typename T, typename Tr, typename Alloc, typename Mode>
void indirect_streambuf<T, Tr, Alloc, Mode>::open
(const T& t, std::streamsize buffer_size, std::streamsize pback_size)
{
using namespace std;
// Normalize buffer sizes.
buffer_size =
(buffer_size != -1) ?
buffer_size :
iostreams::optimal_buffer_size(t);
pback_size =
(pback_size != -1) ?
pback_size :
default_pback_buffer_size;
// Construct input buffer.
if (can_read()) {
pback_size_ = (std::max)(std::streamsize(2), pback_size); // STLPort needs 2.
std::streamsize size =
pback_size_ +
( buffer_size ? buffer_size: std::streamsize(1) );
in().resize(static_cast<int>(size));
if (!shared_buffer())
init_get_area();
}
// Construct output buffer.
if (can_write() && !shared_buffer()) {
if (buffer_size != std::streamsize(0))
out().resize(static_cast<int>(buffer_size));
init_put_area();
}
storage_.reset(wrapper(t));
flags_ |= f_open;
if (can_write() && buffer_size > 1)
flags_ |= f_output_buffered;
this->set_true_eof(false);
this->set_needs_close();
}
template<typename T, typename Tr, typename Alloc, typename Mode>
inline bool indirect_streambuf<T, Tr, Alloc, Mode>::is_open() const
{ return (flags_ & f_open) != 0; }
template<typename T, typename Tr, typename Alloc, typename Mode>
void indirect_streambuf<T, Tr, Alloc, Mode>::close()
{
using namespace std;
base_type* self = this;
detail::execute_all(
detail::call_member_close(*self, BOOST_IOS::in),
detail::call_member_close(*self, BOOST_IOS::out),
detail::call_reset(storage_),
detail::clear_flags(flags_)
);
}
template<typename T, typename Tr, typename Alloc, typename Mode>
bool indirect_streambuf<T, Tr, Alloc, Mode>::auto_close() const
{ return (flags_ & f_auto_close) != 0; }
template<typename T, typename Tr, typename Alloc, typename Mode>
void indirect_streambuf<T, Tr, Alloc, Mode>::set_auto_close(bool close)
{ flags_ = (flags_ & ~f_auto_close) | (close ? f_auto_close : 0); }
//--------------Implementation virtual functions------------------------------//
#ifndef BOOST_IOSTREAMS_NO_LOCALE
template<typename T, typename Tr, typename Alloc, typename Mode>
void indirect_streambuf<T, Tr, Alloc, Mode>::imbue(const std::locale& loc)
{
if (is_open()) {
obj().imbue(loc);
if (next_)
next_->pubimbue(loc);
}
}
#endif
template<typename T, typename Tr, typename Alloc, typename Mode>
typename indirect_streambuf<T, Tr, Alloc, Mode>::int_type
indirect_streambuf<T, Tr, Alloc, Mode>::underflow()
{
using namespace std;
if (!gptr()) init_get_area();
buffer_type& buf = in();
if (gptr() < egptr()) return traits_type::to_int_type(*gptr());
// Fill putback buffer.
std::streamsize keep =
(std::min)( static_cast<std::streamsize>(gptr() - eback()),
pback_size_ );
if (keep)
traits_type::move( buf.data() + (pback_size_ - keep),
gptr() - keep, keep );
// Set pointers to reasonable values in case read throws.
setg( buf.data() + pback_size_ - keep,
buf.data() + pback_size_,
buf.data() + pback_size_ );
// Read from source.
std::streamsize chars =
obj().read(buf.data() + pback_size_, buf.size() - pback_size_, next_);
if (chars == -1) {
this->set_true_eof(true);
chars = 0;
}
setg(eback(), gptr(), buf.data() + pback_size_ + chars);
return chars != 0 ?
traits_type::to_int_type(*gptr()) :
traits_type::eof();
}
template<typename T, typename Tr, typename Alloc, typename Mode>
typename indirect_streambuf<T, Tr, Alloc, Mode>::int_type
indirect_streambuf<T, Tr, Alloc, Mode>::pbackfail(int_type c)
{
if (gptr() != eback()) {
gbump(-1);
if (!traits_type::eq_int_type(c, traits_type::eof()))
*gptr() = traits_type::to_char_type(c);
return traits_type::not_eof(c);
} else {
boost::throw_exception(bad_putback());
}
}
template<typename T, typename Tr, typename Alloc, typename Mode>
typename indirect_streambuf<T, Tr, Alloc, Mode>::int_type
indirect_streambuf<T, Tr, Alloc, Mode>::overflow(int_type c)
{
if ( (output_buffered() && pptr() == 0) ||
(shared_buffer() && gptr() != 0) )
{
init_put_area();
}
if (!traits_type::eq_int_type(c, traits_type::eof())) {
if (output_buffered()) {
if (pptr() == epptr()) {
sync_impl();
if (pptr() == epptr())
return traits_type::eof();
}
*pptr() = traits_type::to_char_type(c);
pbump(1);
} else {
char_type d = traits_type::to_char_type(c);
if (obj().write(&d, 1, next_) != 1)
return traits_type::eof();
}
}
return traits_type::not_eof(c);
}
template<typename T, typename Tr, typename Alloc, typename Mode>
int indirect_streambuf<T, Tr, Alloc, Mode>::sync()
{
try { // sync() is no-throw.
sync_impl();
obj().flush(next_);
return 0;
} catch (...) { return -1; }
}
template<typename T, typename Tr, typename Alloc, typename Mode>
bool indirect_streambuf<T, Tr, Alloc, Mode>::strict_sync()
{
try { // sync() is no-throw.
sync_impl();
return obj().flush(next_);
} catch (...) { return false; }
}
template<typename T, typename Tr, typename Alloc, typename Mode>
inline typename indirect_streambuf<T, Tr, Alloc, Mode>::pos_type
indirect_streambuf<T, Tr, Alloc, Mode>::seekoff
(off_type off, BOOST_IOS::seekdir way, BOOST_IOS::openmode which)
{ return seek_impl(off, way, which); }
template<typename T, typename Tr, typename Alloc, typename Mode>
inline typename indirect_streambuf<T, Tr, Alloc, Mode>::pos_type
indirect_streambuf<T, Tr, Alloc, Mode>::seekpos
(pos_type sp, BOOST_IOS::openmode which)
{
return seek_impl(position_to_offset(sp), BOOST_IOS::beg, which);
}
template<typename T, typename Tr, typename Alloc, typename Mode>
typename indirect_streambuf<T, Tr, Alloc, Mode>::pos_type
indirect_streambuf<T, Tr, Alloc, Mode>::seek_impl
(stream_offset off, BOOST_IOS::seekdir way, BOOST_IOS::openmode which)
{
if ( gptr() != 0 && way == BOOST_IOS::cur && which == BOOST_IOS::in &&
eback() - gptr() <= off && off <= egptr() - gptr() )
{ // Small seek optimization
gbump(static_cast<int>(off));
return obj().seek(stream_offset(0), BOOST_IOS::cur, BOOST_IOS::in, next_) -
static_cast<off_type>(egptr() - gptr());
}
if (pptr() != 0)
this->BOOST_IOSTREAMS_PUBSYNC(); // sync() confuses VisualAge 6.
if (way == BOOST_IOS::cur && gptr())
off -= static_cast<off_type>(egptr() - gptr());
bool two_head = is_convertible<category, dual_seekable>::value ||
is_convertible<category, bidirectional_seekable>::value;
if (two_head) {
BOOST_IOS::openmode both = BOOST_IOS::in | BOOST_IOS::out;
if ((which & both) == both)
boost::throw_exception(bad_seek());
if (which & BOOST_IOS::in) {
setg(0, 0, 0);
}
if (which & BOOST_IOS::out) {
setp(0, 0);
}
}
else {
setg(0, 0, 0);
setp(0, 0);
}
return obj().seek(off, way, which, next_);
}
template<typename T, typename Tr, typename Alloc, typename Mode>
inline void indirect_streambuf<T, Tr, Alloc, Mode>::set_next
(streambuf_type* next)
{ next_ = next; }
template<typename T, typename Tr, typename Alloc, typename Mode>
inline void indirect_streambuf<T, Tr, Alloc, Mode>::close_impl
(BOOST_IOS::openmode which)
{
if (which == BOOST_IOS::in && is_convertible<Mode, input>::value) {
setg(0, 0, 0);
}
if (which == BOOST_IOS::out && is_convertible<Mode, output>::value) {
sync();
setp(0, 0);
}
if ( !is_convertible<category, dual_use>::value ||
is_convertible<Mode, input>::value == (which == BOOST_IOS::in) )
{
obj().close(which, next_);
}
}
//----------State changing functions------------------------------------------//
template<typename T, typename Tr, typename Alloc, typename Mode>
void indirect_streambuf<T, Tr, Alloc, Mode>::sync_impl()
{
std::streamsize avail, amt;
if ((avail = static_cast<std::streamsize>(pptr() - pbase())) > 0) {
if ((amt = obj().write(pbase(), avail, next())) == avail)
setp(out().begin(), out().end());
else {
const char_type* ptr = pptr();
setp(out().begin() + amt, out().end());
pbump(static_cast<int>(ptr - pptr()));
}
}
}
template<typename T, typename Tr, typename Alloc, typename Mode>
void indirect_streambuf<T, Tr, Alloc, Mode>::init_get_area()
{
if (shared_buffer() && pptr() != 0) {
sync_impl();
setp(0, 0);
}
setg(in().begin(), in().begin(), in().begin());
}
template<typename T, typename Tr, typename Alloc, typename Mode>
void indirect_streambuf<T, Tr, Alloc, Mode>::init_put_area()
{
using namespace std;
if (shared_buffer() && gptr() != 0) {
obj().seek(static_cast<off_type>(gptr() - egptr()), BOOST_IOS::cur, BOOST_IOS::in, next_);
setg(0, 0, 0);
}
if (output_buffered())
setp(out().begin(), out().end());
else
setp(0, 0);
}
//----------------------------------------------------------------------------//
} } } // End namespaces detail, iostreams, boost.
#include <boost/iostreams/detail/config/enable_warnings.hpp> // MSVC, BCC 5.x
#endif // #ifndef BOOST_IOSTREAMS_DETAIL_INDIRECT_STREAMBUF_HPP_INCLUDED
@@ -0,0 +1,114 @@
// (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_LINKED_STREAMBUF_HPP_INCLUDED
#define BOOST_IOSTREAMS_DETAIL_LINKED_STREAMBUF_HPP_INCLUDED
#if defined(_MSC_VER)
# pragma once
#endif
#include <typeinfo>
#include <boost/config.hpp> // member template friends.
#include <boost/iostreams/detail/char_traits.hpp>
#include <boost/iostreams/detail/ios.hpp> // openmode.
#include <boost/iostreams/detail/streambuf.hpp>
// Must come last.
#include <boost/iostreams/detail/config/disable_warnings.hpp> // MSVC.
namespace boost { namespace iostreams { namespace detail {
template<typename Self, typename Ch, typename Tr, typename Alloc, typename Mode>
class chain_base;
template<typename Chain, typename Access, typename Mode> class chainbuf;
#define BOOST_IOSTREAMS_USING_PROTECTED_STREAMBUF_MEMBERS(base) \
using base::eback; using base::gptr; using base::egptr; \
using base::setg; using base::gbump; using base::pbase; \
using base::pptr; using base::epptr; using base::setp; \
using base::pbump; using base::underflow; using base::pbackfail; \
using base::xsgetn; using base::overflow; using base::xsputn; \
using base::sync; using base::seekoff; using base::seekpos; \
/**/
template<typename Ch, typename Tr = BOOST_IOSTREAMS_CHAR_TRAITS(Ch) >
class linked_streambuf : public BOOST_IOSTREAMS_BASIC_STREAMBUF(Ch, Tr) {
protected:
linked_streambuf() : flags_(0) { }
void set_true_eof(bool eof)
{
flags_ = (flags_ & ~f_true_eof) | (eof ? f_true_eof : 0);
}
public:
// Should be called only after receiving an ordinary EOF indication,
// to confirm that it represents EOF rather than WOULD_BLOCK.
bool true_eof() const { return (flags_ & f_true_eof) != 0; }
protected:
//----------grant friendship to chain_base and chainbuf-------------------//
#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
template< typename Self, typename ChT, typename TrT,
typename Alloc, typename Mode >
friend class chain_base;
template<typename Chain, typename Mode, typename Access>
friend class chainbuf;
template<typename U>
friend class member_close_operation;
#else
public:
typedef BOOST_IOSTREAMS_BASIC_STREAMBUF(Ch, Tr) base;
BOOST_IOSTREAMS_USING_PROTECTED_STREAMBUF_MEMBERS(base)
#endif
void close(BOOST_IOS::openmode which)
{
if ( which == BOOST_IOS::in &&
(flags_ & f_input_closed) == 0 )
{
flags_ |= f_input_closed;
close_impl(which);
}
if ( which == BOOST_IOS::out &&
(flags_ & f_output_closed) == 0 )
{
flags_ |= f_output_closed;
close_impl(which);
}
}
void set_needs_close()
{
flags_ &= ~(f_input_closed | f_output_closed);
}
virtual void set_next(linked_streambuf<Ch, Tr>* /* next */) { }
virtual void close_impl(BOOST_IOS::openmode) = 0;
virtual bool auto_close() const = 0;
virtual void set_auto_close(bool) = 0;
virtual bool strict_sync() = 0;
virtual const std::type_info& component_type() const = 0;
virtual void* component_impl() = 0;
#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
private:
#else
public:
#endif
private:
enum flag_type {
f_true_eof = 1,
f_input_closed = f_true_eof << 1,
f_output_closed = f_input_closed << 1
};
int flags_;
};
} } } // End namespaces detail, iostreams, boost.
#include <boost/iostreams/detail/config/enable_warnings.hpp> // MSVC.
#endif // #ifndef BOOST_IOSTREAMS_DETAIL_LINKED_STREAMBUF_HPP_INCLUDED