mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
6d5547a Set version to 1.0.0-b34 6fab138 Fix and tidy up CMake build scripts: ccefa54 Set version to 1.0.0-b33 32afe41 Set internal state correctly when writing frames: fe3e20b Add write_frames unit test 578dcd0 Add decorator unit test aaa3733 Use fwrite return value in file_body df66165 Require Visual Studio 2015 Update 3 or later b8e5a21 Set version to 1.0.0-b32 ffb1758 Update CMake scripts for finding packages: b893749 Remove http Writer suspend and resume feature (API Change): 27864fb Add io_service completion invariants tests eba05a7 Set version to 1.0.0-b31 484bcef Fix badge markdown in README.md 5663bea Add missing dynabuf_readstream member 0d7a551 Tidy up build settings 0fd4030 Move the handler, don't copy it git-subtree-dir: src/beast git-subtree-split: 6d5547a32c50ec95832c4779311502555ab0ee1f
308 lines
5.9 KiB
C++
308 lines
5.9 KiB
C++
//
|
|
// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail 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)
|
|
//
|
|
|
|
#ifndef BEAST_IMPL_STATIC_STREAMBUF_IPP
|
|
#define BEAST_IMPL_STATIC_STREAMBUF_IPP
|
|
|
|
#include <beast/core/detail/type_traits.hpp>
|
|
#include <boost/asio/buffer.hpp>
|
|
#include <algorithm>
|
|
#include <cstring>
|
|
#include <iterator>
|
|
#include <stdexcept>
|
|
|
|
namespace beast {
|
|
|
|
class static_streambuf::const_buffers_type
|
|
{
|
|
std::size_t n_;
|
|
std::uint8_t const* p_;
|
|
|
|
public:
|
|
using value_type = boost::asio::const_buffer;
|
|
|
|
class const_iterator;
|
|
|
|
const_buffers_type() = delete;
|
|
const_buffers_type(
|
|
const_buffers_type const&) = default;
|
|
const_buffers_type& operator=(
|
|
const_buffers_type const&) = default;
|
|
|
|
const_iterator
|
|
begin() const;
|
|
|
|
const_iterator
|
|
end() const;
|
|
|
|
private:
|
|
friend class static_streambuf;
|
|
|
|
const_buffers_type(
|
|
std::uint8_t const* p, std::size_t n)
|
|
: n_(n)
|
|
, p_(p)
|
|
{
|
|
}
|
|
};
|
|
|
|
class static_streambuf::const_buffers_type::const_iterator
|
|
{
|
|
std::size_t n_ = 0;
|
|
std::uint8_t const* p_ = nullptr;
|
|
|
|
public:
|
|
using value_type = boost::asio::const_buffer;
|
|
using pointer = value_type const*;
|
|
using reference = value_type;
|
|
using difference_type = std::ptrdiff_t;
|
|
using iterator_category =
|
|
std::bidirectional_iterator_tag;
|
|
|
|
const_iterator() = default;
|
|
const_iterator(const_iterator&& other) = default;
|
|
const_iterator(const_iterator const& other) = default;
|
|
const_iterator& operator=(const_iterator&& other) = default;
|
|
const_iterator& operator=(const_iterator const& other) = default;
|
|
|
|
bool
|
|
operator==(const_iterator const& other) const
|
|
{
|
|
return p_ == other.p_;
|
|
}
|
|
|
|
bool
|
|
operator!=(const_iterator const& other) const
|
|
{
|
|
return !(*this == other);
|
|
}
|
|
|
|
reference
|
|
operator*() const
|
|
{
|
|
return value_type{p_, n_};
|
|
}
|
|
|
|
pointer
|
|
operator->() const = delete;
|
|
|
|
const_iterator&
|
|
operator++()
|
|
{
|
|
p_ += n_;
|
|
return *this;
|
|
}
|
|
|
|
const_iterator
|
|
operator++(int)
|
|
{
|
|
auto temp = *this;
|
|
++(*this);
|
|
return temp;
|
|
}
|
|
|
|
const_iterator&
|
|
operator--()
|
|
{
|
|
p_ -= n_;
|
|
return *this;
|
|
}
|
|
|
|
const_iterator
|
|
operator--(int)
|
|
{
|
|
auto temp = *this;
|
|
--(*this);
|
|
return temp;
|
|
}
|
|
|
|
private:
|
|
friend class const_buffers_type;
|
|
|
|
const_iterator(
|
|
std::uint8_t const* p, std::size_t n)
|
|
: n_(n)
|
|
, p_(p)
|
|
{
|
|
}
|
|
};
|
|
|
|
inline
|
|
auto
|
|
static_streambuf::const_buffers_type::begin() const ->
|
|
const_iterator
|
|
{
|
|
return const_iterator{p_, n_};
|
|
}
|
|
|
|
inline
|
|
auto
|
|
static_streambuf::const_buffers_type::end() const ->
|
|
const_iterator
|
|
{
|
|
return const_iterator{p_ + n_, n_};
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
class static_streambuf::mutable_buffers_type
|
|
{
|
|
std::size_t n_;
|
|
std::uint8_t* p_;
|
|
|
|
public:
|
|
using value_type = boost::asio::mutable_buffer;
|
|
|
|
class const_iterator;
|
|
|
|
mutable_buffers_type() = delete;
|
|
mutable_buffers_type(
|
|
mutable_buffers_type const&) = default;
|
|
mutable_buffers_type& operator=(
|
|
mutable_buffers_type const&) = default;
|
|
|
|
const_iterator
|
|
begin() const;
|
|
|
|
const_iterator
|
|
end() const;
|
|
|
|
private:
|
|
friend class static_streambuf;
|
|
|
|
mutable_buffers_type(
|
|
std::uint8_t* p, std::size_t n)
|
|
: n_(n)
|
|
, p_(p)
|
|
{
|
|
}
|
|
};
|
|
|
|
class static_streambuf::mutable_buffers_type::const_iterator
|
|
{
|
|
std::size_t n_ = 0;
|
|
std::uint8_t* p_ = nullptr;
|
|
|
|
public:
|
|
using value_type = boost::asio::mutable_buffer;
|
|
using pointer = value_type const*;
|
|
using reference = value_type;
|
|
using difference_type = std::ptrdiff_t;
|
|
using iterator_category =
|
|
std::bidirectional_iterator_tag;
|
|
|
|
const_iterator() = default;
|
|
const_iterator(const_iterator&& other) = default;
|
|
const_iterator(const_iterator const& other) = default;
|
|
const_iterator& operator=(const_iterator&& other) = default;
|
|
const_iterator& operator=(const_iterator const& other) = default;
|
|
|
|
bool
|
|
operator==(const_iterator const& other) const
|
|
{
|
|
return p_ == other.p_;
|
|
}
|
|
|
|
bool
|
|
operator!=(const_iterator const& other) const
|
|
{
|
|
return !(*this == other);
|
|
}
|
|
|
|
reference
|
|
operator*() const
|
|
{
|
|
return value_type{p_, n_};
|
|
}
|
|
|
|
pointer
|
|
operator->() const = delete;
|
|
|
|
const_iterator&
|
|
operator++()
|
|
{
|
|
p_ += n_;
|
|
return *this;
|
|
}
|
|
|
|
const_iterator
|
|
operator++(int)
|
|
{
|
|
auto temp = *this;
|
|
++(*this);
|
|
return temp;
|
|
}
|
|
|
|
const_iterator&
|
|
operator--()
|
|
{
|
|
p_ -= n_;
|
|
return *this;
|
|
}
|
|
|
|
const_iterator
|
|
operator--(int)
|
|
{
|
|
auto temp = *this;
|
|
--(*this);
|
|
return temp;
|
|
}
|
|
|
|
private:
|
|
friend class mutable_buffers_type;
|
|
|
|
const_iterator(std::uint8_t* p, std::size_t n)
|
|
: n_(n)
|
|
, p_(p)
|
|
{
|
|
}
|
|
};
|
|
|
|
inline
|
|
auto
|
|
static_streambuf::mutable_buffers_type::begin() const ->
|
|
const_iterator
|
|
{
|
|
return const_iterator{p_, n_};
|
|
}
|
|
|
|
inline
|
|
auto
|
|
static_streambuf::mutable_buffers_type::end() const ->
|
|
const_iterator
|
|
{
|
|
return const_iterator{p_ + n_, n_};
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
inline
|
|
auto
|
|
static_streambuf::data() const ->
|
|
const_buffers_type
|
|
{
|
|
return const_buffers_type{in_,
|
|
static_cast<std::size_t>(out_ - in_)};
|
|
}
|
|
|
|
inline
|
|
auto
|
|
static_streambuf::prepare(std::size_t n) ->
|
|
mutable_buffers_type
|
|
{
|
|
if(n > static_cast<std::size_t>(end_ - out_))
|
|
throw detail::make_exception<std::length_error>(
|
|
"no space in streambuf", __FILE__, __LINE__);
|
|
last_ = out_ + n;
|
|
return mutable_buffers_type{out_, n};
|
|
}
|
|
|
|
} // beast
|
|
|
|
#endif
|