aboutsummaryrefslogtreecommitdiff
path: root/include/odhtdb/OwnedMemory.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/odhtdb/OwnedMemory.hpp')
-rw-r--r--include/odhtdb/OwnedMemory.hpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/include/odhtdb/OwnedMemory.hpp b/include/odhtdb/OwnedMemory.hpp
index 67afe06..4c6df1c 100644
--- a/include/odhtdb/OwnedMemory.hpp
+++ b/include/odhtdb/OwnedMemory.hpp
@@ -22,4 +22,32 @@ namespace odhtdb
void *data;
usize size;
};
+
+ class OwnedByteArray
+ {
+ public:
+ OwnedByteArray() : data(nullptr), size(0) {}
+ OwnedByteArray(u8 *_data, usize _size) : data(_data), size(_size) {}
+ OwnedByteArray(OwnedByteArray &&other)
+ {
+ data = other.data;
+ size = other.size;
+
+ other.data = nullptr;
+ other.size = 0;
+ }
+ ~OwnedByteArray()
+ {
+ delete[] data;
+ }
+
+ // Do not allow copy of this struct, forcing move when returning a OwnedByteArray in a function
+ OwnedByteArray(OwnedByteArray&) = delete;
+ OwnedByteArray& operator = (OwnedByteArray&) = delete;
+
+ const DataView getView() const { return DataView(data, size); }
+
+ u8 *data;
+ usize size;
+ };
}