File indexing completed on 2026-09-20 09:29:08
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef UPB_MEM_ARENA_HPP_
0009 #define UPB_MEM_ARENA_HPP_
0010
0011 #include "upb/mem/alloc.h"
0012 #ifdef __cplusplus
0013
0014 #include <cstddef>
0015 #include <memory>
0016
0017 #include "upb/mem/arena.h"
0018
0019 namespace upb {
0020
0021 class Arena {
0022 public:
0023
0024 Arena() : ptr_(upb_Arena_New(), upb_Arena_Free) {}
0025 Arena(char* initial_block, size_t size)
0026 : ptr_(upb_Arena_Init(initial_block, size, &upb_alloc_global),
0027 upb_Arena_Free) {}
0028 explicit Arena(size_t size)
0029 : ptr_(upb_Arena_NewSized(size), upb_Arena_Free) {}
0030
0031 upb_Arena* ptr() const { return ptr_.get(); }
0032
0033
0034
0035
0036
0037 bool Fuse(Arena& other) { return upb_Arena_Fuse(ptr(), other.ptr()); }
0038
0039 bool IsFused(Arena& other) const {
0040 return upb_Arena_IsFused(ptr(), other.ptr());
0041 }
0042
0043 protected:
0044 std::unique_ptr<upb_Arena, decltype(&upb_Arena_Free)> ptr_;
0045 };
0046 }
0047
0048 #endif
0049
0050 #endif