1#ifndef PROTOZERO_BUFFER_FIXED_HPP 
    2#define PROTOZERO_BUFFER_FIXED_HPP 
   37    std::size_t m_capacity;
 
   38    std::size_t m_size = 0;
 
   44    using size_type = std::size_t;
 
   46    using value_type = char;
 
   47    using reference = value_type&;
 
   48    using const_reference = 
const value_type&;
 
   49    using pointer = value_type*;
 
   50    using const_pointer = 
const value_type*;
 
   52    using iterator = pointer;
 
   53    using const_iterator = const_pointer;
 
   76        m_data(container.
data()),
 
   77        m_capacity(container.
size()) {
 
 
   81    const char* 
data() const noexcept {
 
 
   96    std::size_t 
size() const noexcept {
 
 
  106    const char* 
begin() const noexcept {
 
 
  117        return m_data + m_size;
 
 
  121    const char* 
end() const noexcept {
 
  122        return m_data + m_size;
 
 
  126    const char* 
cend() const noexcept {
 
  127        return m_data + m_size;
 
 
  134    void append(
const char* 
data, std::size_t count) {
 
  135        if (m_size + count > m_capacity) {
 
  136            throw std::length_error{
"fixed size data store exhausted"};
 
  138        std::copy_n(
data, count, m_data + m_size);
 
  142    void append_zeros(std::size_t count) {
 
  143        if (m_size + count > m_capacity) {
 
  144            throw std::length_error{
"fixed size data store exhausted"};
 
  146        std::fill_n(m_data + m_size, count, 
'\0');
 
  150    void resize(std::size_t 
size) {
 
  151        protozero_assert(
size < m_size);
 
  152        if (
size > m_capacity) {
 
  153            throw std::length_error{
"fixed size data store exhausted"};
 
  158    void erase_range(std::size_t from, std::size_t to) {
 
  159        protozero_assert(from <= m_size);
 
  160        protozero_assert(to <= m_size);
 
  161        protozero_assert(from < to);
 
  162        std::copy(m_data + to, m_data + m_size, m_data + from);
 
  163        m_size -= (to - from);
 
  166    char* at_pos(std::size_t pos) {
 
  167        protozero_assert(pos <= m_size);
 
  171    void push_back(
char ch) {
 
  172        if (m_size >= m_capacity) {
 
  173            throw std::length_error{
"fixed size data store exhausted"};
 
  175        m_data[m_size++] = ch;
 
 
  185    static std::size_t size(
const fixed_size_buffer_adaptor* buffer) 
noexcept {
 
  186        return buffer->size();
 
  189    static void append(fixed_size_buffer_adaptor* buffer, 
const char* data, std::size_t count) {
 
  190        buffer->append(data, count);
 
  193    static void append_zeros(fixed_size_buffer_adaptor* buffer, std::size_t count) {
 
  194        buffer->append_zeros(count);
 
  197    static void resize(fixed_size_buffer_adaptor* buffer, std::size_t size) {
 
  198        buffer->resize(size);
 
  201    static void reserve_additional(fixed_size_buffer_adaptor* , std::size_t ) {
 
  205    static void erase_range(fixed_size_buffer_adaptor* buffer, std::size_t from, std::size_t to) {
 
  206        buffer->erase_range(from, to);
 
  209    static char* at_pos(fixed_size_buffer_adaptor* buffer, std::size_t pos) {
 
  210        return buffer->at_pos(pos);
 
  213    static void push_back(fixed_size_buffer_adaptor* buffer, 
char ch) {
 
  214        buffer->push_back(ch);
 
Contains the customization points for buffer implementations.
Definition buffer_fixed.hpp:34
fixed_size_buffer_adaptor(T &container)
Definition buffer_fixed.hpp:75
std::size_t size() const noexcept
The number of bytes used in the buffer. Always <= capacity().
Definition buffer_fixed.hpp:96
const char * end() const noexcept
Return iterator to end of data.
Definition buffer_fixed.hpp:121
const char * cbegin() const noexcept
Return iterator to beginning of data.
Definition buffer_fixed.hpp:111
fixed_size_buffer_adaptor(char *data, std::size_t capacity) noexcept
Definition buffer_fixed.hpp:63
char * end() noexcept
Return iterator to end of data.
Definition buffer_fixed.hpp:116
std::size_t capacity() const noexcept
The capacity this buffer was created with.
Definition buffer_fixed.hpp:91
const char * begin() const noexcept
Return iterator to beginning of data.
Definition buffer_fixed.hpp:106
char * data() noexcept
Returns a pointer to the data in the buffer.
Definition buffer_fixed.hpp:86
char * begin() noexcept
Return iterator to beginning of data.
Definition buffer_fixed.hpp:101
const char * data() const noexcept
Returns a pointer to the data in the buffer.
Definition buffer_fixed.hpp:81
const char * cend() const noexcept
Return iterator to end of data.
Definition buffer_fixed.hpp:126
Contains macro checks for different configurations.
All parts of the protozero header-only library are in this namespace.
Definition basic_pbf_builder.hpp:24