diff --git a/src/nt.cpp b/src/nt.cpp index 5f65b21..994e8c7 100644 --- a/src/nt.cpp +++ b/src/nt.cpp @@ -104,6 +104,22 @@ TypeDef NTScalar::build() const return def; } +TypeDef NTEnum::build() const +{ + using namespace pvxs::members; + + TypeDef def(TypeCode::Struct, "epics:nt/NTEnum:1.0", { + Struct("value", "enum_t", { + Int32("index"), + StringA("choices"), + }), + Alarm{}.build().as("alarm"), + TimeStamp{}.build().as("timeStamp"), + }); + + return def; +} + TypeDef NTNDArray::build() const { using namespace pvxs::members; diff --git a/src/pvxs/nt.h b/src/pvxs/nt.h index ded9bad..f438b5c 100644 --- a/src/pvxs/nt.h +++ b/src/pvxs/nt.h @@ -85,6 +85,20 @@ struct NTScalar { } }; +/** An enumerated value (choice from a list of strings) + * + * @since UNRELEASED + */ +struct NTEnum { + //! A TypeDef which can be appended + PVXS_API + TypeDef build() const; + //! Instantiate + inline Value create() const { + return build().create(); + } +}; + /** The areaDetector inspired N-dimension array/image container. * * @code diff --git a/test/testnt.cpp b/test/testnt.cpp index 7393243..13ff91e 100644 --- a/test/testnt.cpp +++ b/test/testnt.cpp @@ -73,12 +73,22 @@ void testNTURI() testEq(top["query.arg2"].as(), "hello"); } +void testNTEnum() +{ + testDiag("In %s", __func__); + + auto top = nt::NTEnum{}.create(); + + testTrue(top.idStartsWith("epics:nt/NTEnum:"))<<"\n"<