ZeroBuf  0.4.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/api.h>
10 #include <zerobuf/Allocator.h> // base class
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 
26 private:
27  ConstAllocator( const ConstAllocator& ) = delete;
28  ConstAllocator& operator = ( const ConstAllocator& ) = delete;
29 
30  uint8_t* getData() final
31  { throw std::runtime_error( "No mutable getData() for ConstAllocator" ); }
32  void copyBuffer( const void*, size_t ) final
33  { throw std::runtime_error( "No copyBuffer for ConstAllocator" ); }
34  uint8_t* updateAllocation( size_t, bool, size_t ) final
35  { throw std::runtime_error( "No updateAllocation for ConstAllocator" ); }
36  void compact( float ) final
37  { throw std::runtime_error( "No compact for ConstAllocator" ); }
38 
39  const uint8_t* _data;
40  const size_t _size;
41 };
42 }
43 
44 #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.