Merge changes from topic 'hidl_vec'
* changes:
hidl_vec: relinquish internal buffer ownership
hidl_vec: add data() method
hidl_vec: implement move semantics
diff --git a/include/hidl/HidlSupport.h b/include/hidl/HidlSupport.h
index f9f7f14..b1bb6ed 100644
--- a/include/hidl/HidlSupport.h
+++ b/include/hidl/HidlSupport.h
@@ -82,6 +82,10 @@
*this = other;
}
+ hidl_vec(hidl_vec<T> &&other) {
+ *this = static_cast<hidl_vec &&>(other);
+ }
+
~hidl_vec() {
if (mOwnsBuffer) {
delete[] mBuffer;
@@ -101,6 +105,30 @@
mOwnsBuffer = false;
}
+ T *data() {
+ return mBuffer;
+ }
+
+ const T *data() const {
+ return mBuffer;
+ }
+
+ T *releaseData() {
+ if (!mOwnsBuffer && mSize > 0) {
+ resize(mSize);
+ }
+ mOwnsBuffer = false;
+ return mBuffer;
+ }
+
+ hidl_vec &operator=(hidl_vec &&other) {
+ mBuffer = other.mBuffer;
+ mSize = other.mSize;
+ mOwnsBuffer = other.mOwnsBuffer;
+ other.mOwnsBuffer = false;
+ return *this;
+ }
+
hidl_vec &operator=(const hidl_vec &other) {
if (this != &other) {
if (mOwnsBuffer) {