/usr/include/boost/iostreams/detail/streambuf/direct_streambuf.hpp is in libboost1.55-dev 1.55.0+dfsg-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | // (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) && (_MSC_VER >= 1020)
# 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:
#if !BOOST_WORKAROUND(__GNUC__, == 2)
BOOST_IOSTREAMS_USING_PROTECTED_STREAMBUF_MEMBERS(base_type)
#endif
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
|