format NTEnum
This commit is contained in:
@@ -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<PVScalar>("value.index"));
|
||||
PVStringArray::const_shared_pointer choices(top.getSubFieldT<PVStringArray>("value.choices"));
|
||||
PVStructure::const_shared_pointer value;
|
||||
if(fromtop) {
|
||||
value = top.getSubField<PVStructure>("value");
|
||||
} else {
|
||||
value = std::tr1::static_pointer_cast<const PVStructure>(top.shared_from_this());
|
||||
}
|
||||
PVScalar::const_shared_pointer idx(value->getSubField<PVScalar>("index"));
|
||||
PVStringArray::const_shared_pointer choices(value->getSubField<PVStringArray>("choices"));
|
||||
if(!idx || !choices) return false;
|
||||
|
||||
strm<<format::indent();
|
||||
printTimeT(strm, top);
|
||||
printAlarmT(strm, top);
|
||||
if(fromtop) {
|
||||
strm<<format::indent();
|
||||
printTimeT(strm, top);
|
||||
printAlarmT(strm, top);
|
||||
}
|
||||
|
||||
PVStringArray::const_svector ch(choices->view());
|
||||
uint32 I = idx->getAs<uint32>();
|
||||
strm<<'('<<I<<')';
|
||||
if(I>=ch.size()) {
|
||||
strm<<'('<<I<<')';
|
||||
strm<<" <undefined>";
|
||||
} else {
|
||||
strm<<'"'<<ch[I]<<"\" ("<<I<<")";
|
||||
strm<<' '<<escape(ch[I]);
|
||||
}
|
||||
strm<<'\n';
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -366,6 +374,9 @@ void printRaw(std::ostream& strm, const PVStructure::Formatter& format, const PV
|
||||
} else if(id=="time_t") {
|
||||
strm.put(' ');
|
||||
printTimeTx(strm, *str);
|
||||
} else if(id=="enum_t") {
|
||||
strm.put(' ');
|
||||
printEnumT(strm, *str, false);
|
||||
}
|
||||
strm.put('\n');
|
||||
}
|
||||
@@ -433,8 +444,10 @@ std::ostream& operator<<(std::ostream& strm, const PVStructure::Formatter& forma
|
||||
return strm;
|
||||
|
||||
case structure:
|
||||
if(printEnumT(strm, format.xtop))
|
||||
if(printEnumT(strm, format.xtop, true)) {
|
||||
strm<<'\n';
|
||||
return strm;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -173,6 +173,51 @@ void showNTScalarString()
|
||||
testDiff("<undefined> 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("<undefined> (0) <undefined>\n", print(input->stream()), "empty");
|
||||
|
||||
pvd::PVStringArray::svector sarr;
|
||||
sarr.push_back("one");
|
||||
sarr.push_back("a two");
|
||||
input->getSubFieldT<pvd::PVStringArray>("value.choices")->replace(pvd::freeze(sarr));
|
||||
|
||||
input->getSubFieldT<pvd::PVInt>("value.index")->put(0);
|
||||
|
||||
testDiff("<undefined> (0) one\n", print(input->stream()), "one");
|
||||
|
||||
input->getSubFieldT<pvd::PVInt>("value.index")->put(1);
|
||||
|
||||
testDiff("<undefined> (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 <undefined> \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();
|
||||
|
||||
Reference in New Issue
Block a user