|
|
@ -15,18 +15,18 @@ template<unsigned short STACK_SIZE>
|
|
|
|
class stack_buf
|
|
|
|
class stack_buf
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
using bufpair_t = std::pair<const char*, std::size_t>;
|
|
|
|
using bufpair_t = std::pair<const char*, std::size_t>;
|
|
|
|
using iterator = char const*;
|
|
|
|
using iterator = char const*;
|
|
|
|
static constexpr unsigned short stack_size = STACK_SIZE;
|
|
|
|
static constexpr unsigned short stack_size = STACK_SIZE;
|
|
|
|
stack_buf() :_v(), _stack_size(0) {}
|
|
|
|
stack_buf() :_v(), _stack_size(0) {}
|
|
|
|
~stack_buf() = default;
|
|
|
|
~stack_buf() = default;
|
|
|
|
|
|
|
|
|
|
|
|
stack_buf& operator=(const stack_buf& other) = delete;
|
|
|
|
stack_buf& operator=(const stack_buf& other) = delete;
|
|
|
|
|
|
|
|
|
|
|
|
stack_buf(const stack_buf& other):stack_buf(other, delegate_copy_move{})
|
|
|
|
stack_buf(const stack_buf& other):stack_buf(other, delegate_copy_move {})
|
|
|
|
{}
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
stack_buf(stack_buf&& other):stack_buf(other, delegate_copy_move{})
|
|
|
|
stack_buf(stack_buf&& other):stack_buf(other, delegate_copy_move {})
|
|
|
|
{
|
|
|
|
{
|
|
|
|
other.clear();
|
|
|
|
other.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -50,7 +50,7 @@ public:
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_v.reserve(_stack_size + buf_size);
|
|
|
|
_v.reserve(_stack_size + buf_size);
|
|
|
|
_v.insert(_v.end(), _stack_array.begin(), _stack_array.begin() + _stack_size);
|
|
|
|
_v.insert(_v.end(), _stack_array.begin(), _stack_array.begin() + _stack_size);
|
|
|
|
_v.insert(_v.end(), buf, buf + buf_size);
|
|
|
|
_v.insert(_v.end(), buf, buf + buf_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -71,38 +71,38 @@ public:
|
|
|
|
return bufpair_t(_stack_array.data(), _stack_size);
|
|
|
|
return bufpair_t(_stack_array.data(), _stack_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
iterator begin() const
|
|
|
|
iterator begin() const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return get().first;
|
|
|
|
return get().first;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
iterator end() const
|
|
|
|
iterator end() const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bufpair_t bpair = get();
|
|
|
|
bufpair_t bpair = get();
|
|
|
|
return bpair.first + bpair.second;
|
|
|
|
return bpair.first + bpair.second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::size_t size() const
|
|
|
|
std::size_t size() const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return get().second;
|
|
|
|
return get().second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
private:
|
|
|
|
struct delegate_copy_move {};
|
|
|
|
struct delegate_copy_move {};
|
|
|
|
template<class T1>
|
|
|
|
template<class T1>
|
|
|
|
stack_buf(T1&& other, delegate_copy_move)
|
|
|
|
stack_buf(T1&& other, delegate_copy_move)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_stack_size = other._stack_size;
|
|
|
|
_stack_size = other._stack_size;
|
|
|
|
if (other.vector_used())
|
|
|
|
if (other.vector_used())
|
|
|
|
_v = std::forward<T1>(other)._v;
|
|
|
|
_v = std::forward<T1>(other)._v;
|
|
|
|
else
|
|
|
|
else
|
|
|
|
std::copy_n(other._stack_array.begin(), other._stack_size, _stack_array.begin());
|
|
|
|
std::copy_n(other._stack_array.begin(), other._stack_size, _stack_array.begin());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline bool vector_used() const
|
|
|
|
inline bool vector_used() const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return !(_v.empty());
|
|
|
|
return !(_v.empty());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<char> _v;
|
|
|
|
std::vector<char> _v;
|
|
|
|
std::array<char, STACK_SIZE> _stack_array;
|
|
|
|
std::array<char, STACK_SIZE> _stack_array;
|
|
|
|