File indexing completed on 2025-01-18 10:13:16
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef UPB_MEM_ARENA_HPP_
0009 #define UPB_MEM_ARENA_HPP_
0010
0011 #ifdef __cplusplus
0012
0013 #include <memory>
0014
0015 #include "upb/mem/arena.h"
0016
0017 namespace upb {
0018
0019 class Arena {
0020 public:
0021
0022 Arena() : ptr_(upb_Arena_New(), upb_Arena_Free) {}
0023 Arena(char* initial_block, size_t size)
0024 : ptr_(upb_Arena_Init(initial_block, size, &upb_alloc_global),
0025 upb_Arena_Free) {}
0026
0027 upb_Arena* ptr() const { return ptr_.get(); }
0028
0029
0030
0031
0032
0033 bool Fuse(Arena& other) { return upb_Arena_Fuse(ptr(), other.ptr()); }
0034
0035 protected:
0036 std::unique_ptr<upb_Arena, decltype(&upb_Arena_Free)> ptr_;
0037 };
0038
0039
0040
0041 template <int N>
0042 class InlinedArena : public Arena {
0043 public:
0044 InlinedArena() : Arena(initial_block_, N) {}
0045 ~InlinedArena() {
0046
0047
0048 ptr_.reset();
0049 }
0050
0051 private:
0052 InlinedArena(const InlinedArena&) = delete;
0053 InlinedArena& operator=(const InlinedArena&) = delete;
0054
0055 char initial_block_[N];
0056 };
0057
0058 }
0059
0060 #endif
0061
0062 #endif