ntnameValue: extra fields can be added now
This commit is contained in:
@ -46,6 +46,10 @@ StructureConstPtr NTNameValueBuilder::createStructure()
|
||||
if (timeStamp)
|
||||
builder->add("timeStamp", ntField->createTimeStamp());
|
||||
|
||||
size_t extraCount = extraFieldNames.size();
|
||||
for (size_t i = 0; i< extraCount; i++)
|
||||
builder->add(extraFieldNames[i], extraFields[i]);
|
||||
|
||||
StructureConstPtr s = builder->createStructure();
|
||||
|
||||
reset();
|
||||
@ -91,8 +95,17 @@ void NTNameValueBuilder::reset()
|
||||
descriptor = false;
|
||||
alarm = false;
|
||||
timeStamp = false;
|
||||
extraFieldNames.clear();
|
||||
extraFields.clear();
|
||||
}
|
||||
|
||||
NTNameValueBuilder::shared_pointer NTNameValueBuilder::add(string const & name, FieldConstPtr const & field)
|
||||
{
|
||||
extraFields.push_back(field); extraFieldNames.push_back(name);
|
||||
return shared_from_this();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
const std::string NTNameValue::URI("uri:ev4:nt/2012/pwd:NTNameValue");
|
||||
|
@ -74,6 +74,14 @@ namespace detail {
|
||||
*/
|
||||
NTNameValuePtr create();
|
||||
|
||||
/**
|
||||
* Add extra {@code Field} to the type.
|
||||
* @param name name of the field.
|
||||
* @param field a field to add.
|
||||
* @return this instance of a {@code NTNameValueBuilder}.
|
||||
*/
|
||||
shared_pointer add(std::string const & name, epics::pvData::FieldConstPtr const & field);
|
||||
|
||||
private:
|
||||
NTNameValueBuilder();
|
||||
|
||||
@ -86,6 +94,10 @@ namespace detail {
|
||||
bool alarm;
|
||||
bool timeStamp;
|
||||
|
||||
// NOTE: this preserves order, however it does not handle duplicates
|
||||
epics::pvData::StringArray extraFieldNames;
|
||||
epics::pvData::FieldConstPtrArray extraFields;
|
||||
|
||||
friend class ::epics::nt::NTNameValue;
|
||||
};
|
||||
|
||||
|
@ -204,11 +204,43 @@ void test_narrow()
|
||||
testOk(ptr.get() != 0, "narrow_unsafe OK");
|
||||
}
|
||||
|
||||
void test_extra()
|
||||
{
|
||||
testDiag("test_extra");
|
||||
|
||||
NTNameValueBuilderPtr builder = NTNameValue::createBuilder();
|
||||
testOk(builder.get() != 0, "Got builder");
|
||||
|
||||
StructureConstPtr structure = builder->
|
||||
value(pvDouble)->
|
||||
addTimeStamp()->
|
||||
add("function", getFieldCreate()->createScalar(pvString))->
|
||||
createStructure();
|
||||
testOk1(structure.get() != 0);
|
||||
if (!structure)
|
||||
return;
|
||||
|
||||
testOk1(NTNameValue::is_a(structure));
|
||||
testOk1(structure->getID() == NTNameValue::URI);
|
||||
testOk1(structure->getNumberFields() == 4);
|
||||
testOk1(structure->getField("names").get() != 0);
|
||||
testOk1(structure->getField("values").get() != 0);
|
||||
testOk1(structure->getField("timeStamp").get() != 0);
|
||||
testOk1(structure->getField("function").get() != 0);
|
||||
|
||||
testOk(dynamic_pointer_cast<const Scalar>(structure->getField("function")).get() != 0 &&
|
||||
dynamic_pointer_cast<const Scalar>(structure->getField("function"))->getScalarType() == pvString, "function type");
|
||||
|
||||
std::cout << *structure << std::endl;
|
||||
}
|
||||
|
||||
|
||||
MAIN(testNTNameValue) {
|
||||
testPlan(37);
|
||||
testPlan(47);
|
||||
test_builder();
|
||||
test_ntnameValue();
|
||||
test_narrow();
|
||||
test_extra();
|
||||
return testDone();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user