[ox/buffer] Add copy constructor to NodeBuffer

This commit is contained in:
Gary Talent 2018-05-02 21:11:49 -05:00
parent 6236214be6
commit a13b369792

View File

@ -75,6 +75,8 @@ class __attribute__((packed)) NodeBuffer {
public: public:
NodeBuffer() = default; NodeBuffer() = default;
NodeBuffer(const NodeBuffer &other);
explicit NodeBuffer(size_t size); explicit NodeBuffer(size_t size);
const Iterator iterator() const; const Iterator iterator() const;
@ -120,9 +122,11 @@ class __attribute__((packed)) NodeBuffer {
*/ */
size_t spaceNeeded(size_t size); size_t spaceNeeded(size_t size);
private: void compact(void (*cb)(ItemPtr itemMoved) = nullptr);
void compact(void (*cb)(ItemPtr itemMoved));
void truncate();
private:
uint8_t *data(); uint8_t *data();
}; };
@ -132,6 +136,11 @@ NodeBuffer<size_t, Item>::NodeBuffer(size_t size) {
m_header.size = size; m_header.size = size;
} }
template<typename size_t, typename Item>
NodeBuffer<size_t, Item>::NodeBuffer(const NodeBuffer &other) {
ox_memcpy(this, &other, other.size());
}
template<typename size_t, typename Item> template<typename size_t, typename Item>
const typename NodeBuffer<size_t, Item>::Iterator NodeBuffer<size_t, Item>::iterator() const { const typename NodeBuffer<size_t, Item>::Iterator NodeBuffer<size_t, Item>::iterator() const {
return Iterator(this, firstItem()); return Iterator(this, firstItem());
@ -314,6 +323,11 @@ void NodeBuffer<size_t, Item>::compact(void (*cb)(ItemPtr)) {
} }
} }
template<typename size_t, typename Item>
void NodeBuffer<size_t, Item>::truncate() {
m_header.size = m_header.bytesUsed;
}
template<typename size_t, typename Item> template<typename size_t, typename Item>
uint8_t *NodeBuffer<size_t, Item>::data() { uint8_t *NodeBuffer<size_t, Item>::data() {
return reinterpret_cast<uint8_t*>(ptr(sizeof(*this)).get()); return reinterpret_cast<uint8_t*>(ptr(sizeof(*this)).get());