DetachedBuffer is a finished flatbuffer memory region, detached from its builder. The original memory region and allocator are also stored so that the DetachedBuffer can manage the memory lifetime.
| 745 | // builder. The original memory region and allocator are also stored so that |
| 746 | // the DetachedBuffer can manage the memory lifetime. |
| 747 | class DetachedBuffer { |
| 748 | public: |
| 749 | DetachedBuffer() |
| 750 | : allocator_(nullptr), |
| 751 | own_allocator_(false), |
| 752 | buf_(nullptr), |
| 753 | reserved_(0), |
| 754 | cur_(nullptr), |
| 755 | size_(0) {} |
| 756 | |
| 757 | DetachedBuffer(Allocator *allocator, bool own_allocator, uint8_t *buf, |
| 758 | size_t reserved, uint8_t *cur, size_t sz) |
| 759 | : allocator_(allocator), |
| 760 | own_allocator_(own_allocator), |
| 761 | buf_(buf), |
| 762 | reserved_(reserved), |
| 763 | cur_(cur), |
| 764 | size_(sz) {} |
| 765 | |
| 766 | // clang-format off |
| 767 | #if !defined(FLATBUFFERS_CPP98_STL) |
| 768 | // clang-format on |
| 769 | DetachedBuffer(DetachedBuffer &&other) |
| 770 | : allocator_(other.allocator_), |
| 771 | own_allocator_(other.own_allocator_), |
| 772 | buf_(other.buf_), |
| 773 | reserved_(other.reserved_), |
| 774 | cur_(other.cur_), |
| 775 | size_(other.size_) { |
| 776 | other.reset(); |
| 777 | } |
| 778 | // clang-format off |
| 779 | #endif // !defined(FLATBUFFERS_CPP98_STL) |
| 780 | // clang-format on |
| 781 | |
| 782 | // clang-format off |
| 783 | #if !defined(FLATBUFFERS_CPP98_STL) |
| 784 | // clang-format on |
| 785 | DetachedBuffer &operator=(DetachedBuffer &&other) { |
| 786 | if (this == &other) return *this; |
| 787 | |
| 788 | destroy(); |
| 789 | |
| 790 | allocator_ = other.allocator_; |
| 791 | own_allocator_ = other.own_allocator_; |
| 792 | buf_ = other.buf_; |
| 793 | reserved_ = other.reserved_; |
| 794 | cur_ = other.cur_; |
| 795 | size_ = other.size_; |
| 796 | |
| 797 | other.reset(); |
| 798 | |
| 799 | return *this; |
| 800 | } |
| 801 | // clang-format off |
| 802 | #endif // !defined(FLATBUFFERS_CPP98_STL) |
| 803 | // clang-format on |
| 804 |
no test coverage detected