diff --git a/src/factory/printer.cpp b/src/factory/printer.cpp index f1cb18a..c52d6fa 100644 --- a/src/factory/printer.cpp +++ b/src/factory/printer.cpp @@ -149,24 +149,32 @@ void printTimeT(std::ostream& strm, const PVStructure& top) printTimeTx(strm, *sub); } -bool printEnumT(std::ostream& strm, const PVStructure& top) +bool printEnumT(std::ostream& strm, const PVStructure& top, bool fromtop) { - PVScalar::const_shared_pointer idx(top.getSubField("value.index")); - PVStringArray::const_shared_pointer choices(top.getSubFieldT("value.choices")); + PVStructure::const_shared_pointer value; + if(fromtop) { + value = top.getSubField("value"); + } else { + value = std::tr1::static_pointer_cast(top.shared_from_this()); + } + PVScalar::const_shared_pointer idx(value->getSubField("index")); + PVStringArray::const_shared_pointer choices(value->getSubField("choices")); if(!idx || !choices) return false; - strm<view()); uint32 I = idx->getAs(); + strm<<'('<=ch.size()) { - strm<<'('<"; } else { - strm<<'"'< bar MINOR DEVICE FOO \n", print(input->stream())); } +static const pvd::StructureConstPtr ntenum(pvd::getFieldCreate()->createFieldBuilder() + ->setId("epics:nt/NTEnum:1.0") + ->addNestedStructure("value") + ->setId("enum_t") + ->add("index", pvd::pvInt) + ->addArray("choices", pvd::pvString) + ->endNested() + ->add("alarm", pvd::getStandardField()->alarm()) + ->add("timeStamp", pvd::getStandardField()->timeStamp()) + ->createStructure()); + +void showNTEnum() +{ + testDiag("%s", CURRENT_FUNCTION); + pvd::PVStructurePtr input(pvd::getPVDataCreate()->createPVStructure(ntenum)); + testDiff(" (0) \n", print(input->stream()), "empty"); + + pvd::PVStringArray::svector sarr; + sarr.push_back("one"); + sarr.push_back("a two"); + input->getSubFieldT("value.choices")->replace(pvd::freeze(sarr)); + + input->getSubFieldT("value.index")->put(0); + + testDiff(" (0) one\n", print(input->stream()), "one"); + + input->getSubFieldT("value.index")->put(1); + + testDiff(" (1) a two\n", print(input->stream()), "two"); + + testDiff("epics:nt/NTEnum:1.0 \n" + " enum_t value (1) a two\n" + " int index 1\n" + " string[] choices [\"one\", \"a two\"]\n" + " alarm_t alarm \n" + " int severity 0\n" + " int status 0\n" + " string message \n" + " time_t timeStamp \n" + " long secondsPastEpoch 0\n" + " int nanoseconds 0\n" + " int userTag 0\n", + print(input->stream().format(pvd::PVStructure::Formatter::Raw)), "two raw"); +} + static const pvd::StructureConstPtr table(pvd::getFieldCreate()->createFieldBuilder() ->setId("epics:nt/NTTable:1.0") ->addArray("labels", pvd::pvString) @@ -315,6 +360,7 @@ MAIN(testprinter) testPlan(16); showNTScalarNumeric(); showNTScalarString(); + showNTEnum(); showNTTable(); testRaw(); testEscape();