diff --git a/src/pvxs/data.h b/src/pvxs/data.h index 83a692d..16e41c9 100644 --- a/src/pvxs/data.h +++ b/src/pvxs/data.h @@ -97,10 +97,16 @@ template<> struct StorageMap { typedef unselect_t store_t; static constexpr StoreType code{StoreType::Null}; }; +// drill through enum{} to handle as underlying integer type +template +struct StorageMap::value>::type> + :StorageMap::type> +{}; + template using StoreAs = StorageMap::type>; -template +template struct StoreTransform { // pass through by default static inline const T& in (const T& v) { return v; } @@ -118,6 +124,14 @@ struct StoreTransform> { return v.template convertTo(); } }; +template +struct StoreTransform::value>::type> { + typedef typename std::underlying_type::type itype_t; + static inline + itype_t in(const T& v) { return v; } + static inline + T out(const itype_t& v) { return static_cast(v); } +}; } // namespace impl @@ -583,6 +597,7 @@ public: * - std::string * - Value * - shared_array + * - An enum where the underlying type is one of the preceding (since UNRELEASED). * * @throws NoField !this->valid() * @throws NoConvert if the field value can not be coerced to type T @@ -639,6 +654,7 @@ public: * - std::string * - Value * - shared_array + * - An enum where the underlying type is one of the preceding (since UNRELEASED). */ template void from(const T& val) { diff --git a/test/testdata.cpp b/test/testdata.cpp index 345b8d9..d45e159 100644 --- a/test/testdata.cpp +++ b/test/testdata.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -64,6 +65,9 @@ void testAssign() testOk1(!val["alarm.status"].isMarked(true, true)); testOk1(!!val["alarm"].isMarked(true, true)); testOk1(!val["alarm"].isMarked(true, false)); + + val["alarm.severity"] = INVALID_ALARM; + testEq(val["alarm.severity"].as(), INVALID_ALARM); } void testAssignUnion() @@ -342,7 +346,7 @@ void testExtract() MAIN(testdata) { - testPlan(115); + testPlan(116); testSetup(); testTraverse(); testAssign();