protozero  1.7.0
Minimalistic protocol buffer decoder and encoder in C++.
buffer_string.hpp
Go to the documentation of this file.
1 #ifndef PROTOZERO_BUFFER_STRING_HPP
2 #define PROTOZERO_BUFFER_STRING_HPP
3 
4 /*****************************************************************************
5 
6 protozero - Minimalistic protocol buffer decoder and encoder in C++.
7 
8 This file is from https://github.com/mapbox/protozero where you can find more
9 documentation.
10 
11 *****************************************************************************/
12 
20 #include "buffer_tmpl.hpp"
21 
22 #include <cstddef>
23 #include <iterator>
24 #include <string>
25 
26 namespace protozero {
27 
28 // Implementation of buffer customizations points for std::string
29 
31 template <>
32 struct buffer_customization<std::string> {
33 
34  static std::size_t size(const std::string* buffer) noexcept {
35  return buffer->size();
36  }
37 
38  static void append(std::string* buffer, const char* data, std::size_t count) {
39  buffer->append(data, count);
40  }
41 
42  static void append_zeros(std::string* buffer, std::size_t count) {
43  buffer->append(count, '\0');
44  }
45 
46  static void resize(std::string* buffer, std::size_t size) {
47  protozero_assert(size < buffer->size());
48  buffer->resize(size);
49  }
50 
51  static void reserve_additional(std::string* buffer, std::size_t size) {
52  buffer->reserve(buffer->size() + size);
53  }
54 
55  static void erase_range(std::string* buffer, std::size_t from, std::size_t to) {
56  protozero_assert(from <= buffer->size());
57  protozero_assert(to <= buffer->size());
58  protozero_assert(from <= to);
59  buffer->erase(std::next(buffer->begin(), from), std::next(buffer->begin(), to));
60  }
61 
62  static char* at_pos(std::string* buffer, std::size_t pos) {
63  protozero_assert(pos <= buffer->size());
64  return (&*buffer->begin()) + pos;
65  }
66 
67  static void push_back(std::string* buffer, char ch) {
68  buffer->push_back(ch);
69  }
70 
71 };
73 
74 } // namespace protozero
75 
76 #endif // PROTOZERO_BUFFER_STRING_HPP
Contains the customization points for buffer implementations.
All parts of the protozero header-only library are in this namespace.
Definition: basic_pbf_builder.hpp:24