ZeroBuf  0.5.0
Zero-copy, zero-serialize, zero-hassle protocol buffers
ConstAllocator.h
1 
2 /* Copyright (c) 2015-2016, Human Brain Project
3  * Daniel.Nachbaur@epfl.ch
4  */
5 
6 #ifndef ZEROBUF_CONSTALLOCATOR_H
7 #define ZEROBUF_CONSTALLOCATOR_H
8 
9 #include <zerobuf/Allocator.h> // base class
10 #include <zerobuf/api.h>
11 
12 namespace zerobuf
13 {
15 class ConstAllocator : public Allocator
16 {
17 public:
18  ZEROBUF_API ConstAllocator(const uint8_t* data, size_t size);
19 
20  ZEROBUF_API ~ConstAllocator();
21 
22  const uint8_t* getData() const final { return _data; }
23  size_t getSize() const final { return _size; }
24  bool isMutable() const final { return false; }
25 private:
26  ConstAllocator(const ConstAllocator&) = delete;
27  ConstAllocator& operator=(const ConstAllocator&) = delete;
28 
29  uint8_t* getData() final
30  {
31  throw std::runtime_error("No mutable getData() for ConstAllocator");
32  }
33  void copyBuffer(const void*, size_t) final
34  {
35  throw std::runtime_error("No copyBuffer for ConstAllocator");
36  }
37  uint8_t* updateAllocation(size_t, bool, size_t) final
38  {
39  throw std::runtime_error("No updateAllocation for ConstAllocator");
40  }
41  void compact(float) final
42  {
43  throw std::runtime_error("No compact for ConstAllocator");
44  }
45 
46  const uint8_t* _data;
47  const size_t _size;
48 };
49 }
50 
51 #endif
Defines export visibility macros for library ZeroBuf.
Zero-copy, zero-serialize, zero-hassle protocol buffers.
Definition: Allocator.h:12
Allocator base class and interface.
Definition: Allocator.h:20
A zerobuf root allocator which gives read-only access to its data.