From 39d9f88b13c6dd5e4d332d332741fb9779ad1714 Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Fri, 26 Oct 2018 15:34:01 -0700 Subject: hidl_enum_range: support const/reverse iteration This also moves the implementation to auto-generated code. Only the values themselves are generated in auto-generated code. Bug: 118395041 Test: hidl_test Change-Id: I4ae3cf992a64012e431c0ade3fc4ac3645f96756 --- base/include/hidl/HidlSupport.h | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/base/include/hidl/HidlSupport.h b/base/include/hidl/HidlSupport.h index 2d0dc25..43e84c0 100644 --- a/base/include/hidl/HidlSupport.h +++ b/base/include/hidl/HidlSupport.h @@ -997,12 +997,31 @@ std::string toString(const hidl_array &a) { + details::toString(details::const_accessor(a.data())); } +namespace details { +// Never instantiated. Used as a placeholder for template variables. +template +struct hidl_invalid_type; + +// HIDL generates specializations of this for enums. See hidl_enum_range. +template ::value>> +constexpr hidl_invalid_type hidl_enum_values; +} // namespace details + /** - * Every HIDL generated enum generates an implementation of this function. + * Every HIDL generated enum supports this function. * E.x.: for(const auto v : hidl_enum_range) { ... } */ template ::value>> -struct hidl_enum_range; +struct hidl_enum_range { + constexpr auto begin() const { return std::begin(details::hidl_enum_values); } + constexpr auto cbegin() const { return begin(); } + constexpr auto rbegin() const { return std::rbegin(details::hidl_enum_values); } + constexpr auto crbegin() const { return rbegin(); } + constexpr auto end() const { return std::end(details::hidl_enum_values); } + constexpr auto cend() const { return end(); } + constexpr auto rend() const { return std::rend(details::hidl_enum_values); } + constexpr auto crend() const { return rend(); } +}; template ::value>> struct hidl_enum_iterator { -- cgit v1.2.3