protozero  1.7.1
Minimalistic protocol buffer decoder and encoder in C++.
buffer_fixed.hpp
Go to the documentation of this file.
1 #ifndef PROTOZERO_BUFFER_FIXED_HPP
2 #define PROTOZERO_BUFFER_FIXED_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 
19 #include "buffer_tmpl.hpp"
20 #include "config.hpp"
21 
22 #include <algorithm>
23 #include <cstddef>
24 #include <iterator>
25 #include <stdexcept>
26 
27 namespace protozero {
28 
35 
36  char* m_data;
37  std::size_t m_capacity;
38  std::size_t m_size = 0;
39 
40 public:
41 
43 
44  using size_type = std::size_t;
45 
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*;
51 
52  using iterator = pointer;
53  using const_iterator = const_pointer;
54 
56 
63  fixed_size_buffer_adaptor(char* data, std::size_t capacity) noexcept :
64  m_data(data),
65  m_capacity(capacity) {
66  }
67 
74  template <typename T>
75  explicit fixed_size_buffer_adaptor(T& container) :
76  m_data(container.data()),
77  m_capacity(container.size()) {
78  }
79 
81  const char* data() const noexcept {
82  return m_data;
83  }
84 
86  char* data() noexcept {
87  return m_data;
88  }
89 
91  std::size_t capacity() const noexcept {
92  return m_capacity;
93  }
94 
96  std::size_t size() const noexcept {
97  return m_size;
98  }
99 
101  char* begin() noexcept {
102  return m_data;
103  }
104 
106  const char* begin() const noexcept {
107  return m_data;
108  }
109 
111  const char* cbegin() const noexcept {
112  return m_data;
113  }
114