Adds hidl_array<T, SIZE1, SIZE...>::size() API
One-dimensional arrays "hidl_array<T, SIZE>" now have an accessor
static size_t hidl_array<T, SIZE>::size();
that returns the size (number of elements) of the array,
multi-dimensional arrays "hidl_array<T, SIZE1, SIZE...> gain an accessor
static tuple<size_t, ...> size()
that returns a tuple containing the sizes of each dimension.
Bug: 31805709
Test: hidl_test, hidl_test_java
Change-Id: I80e6cd4f8e506ed2dcffdbfba560983f6239a190
diff --git a/include/hidl/HidlSupport.h b/include/hidl/HidlSupport.h
index e2495e3..e4409e4 100644
--- a/include/hidl/HidlSupport.h
+++ b/include/hidl/HidlSupport.h
@@ -21,6 +21,7 @@
#include <dirent.h>
#include <dlfcn.h>
#include <hwbinder/Parcel.h>
+#include <tuple>
#include <utils/Errors.h>
#include <utils/RefBase.h>
#include <utils/StrongPointer.h>
@@ -258,6 +259,12 @@
&mBuffer[index * details::product<SIZES...>::value]);
}
+ using size_tuple_type = std::tuple<decltype(SIZE1), decltype(SIZES)...>;
+
+ static constexpr size_tuple_type size() {
+ return std::make_tuple(SIZE1, SIZES...);
+ }
+
private:
T mBuffer[details::product<SIZE1, SIZES...>::value];
};
@@ -277,6 +284,8 @@
return mBuffer[index];
}
+ static constexpr size_t size() { return SIZE1; }
+
private:
T mBuffer[SIZE1];
};