narrow and narrow_unsafe methods added
This commit is contained in:
@ -184,6 +184,19 @@ void NTMultiChannelBuilder::reset()
|
||||
|
||||
const std::string NTMultiChannel::URI("uri:ev4:nt/2012/pwd:NTMultiChannel");
|
||||
|
||||
NTMultiChannel::shared_pointer NTMultiChannel::narrow(PVStructurePtr const & structure)
|
||||
{
|
||||
if (!structure || !is_a(structure->getStructure()))
|
||||
return shared_pointer();
|
||||
|
||||
return narrow_unsafe(structure);
|
||||
}
|
||||
|
||||
NTMultiChannel::shared_pointer NTMultiChannel::narrow_unsafe(PVStructurePtr const & structure)
|
||||
{
|
||||
return shared_pointer(new NTMultiChannel(structure));
|
||||
}
|
||||
|
||||
bool NTMultiChannel::is_a(StructureConstPtr const &structure)
|
||||
{
|
||||
return structure->getID() == URI;
|
||||
|
@ -135,6 +135,23 @@ public:
|
||||
POINTER_DEFINITIONS(NTMultiChannel);
|
||||
|
||||
static const std::string URI;
|
||||
|
||||
/**
|
||||
* Narrow (aka dynamic cast, or wrap) the structure to NTMultiChannel.
|
||||
* First the structure ID is checked against NTMultiChannel::URI.
|
||||
* This method will nullptr if the structure is nullptr.
|
||||
* @param structure The structure to narrow-ed (dynamic cast, wrapped) to NTMultiChannel.
|
||||
* @return NTMultiChannel instance on success, nullptr otherwise.
|
||||
*/
|
||||
static shared_pointer narrow(epics::pvData::PVStructurePtr const & structure);
|
||||
|
||||
/**
|
||||
* Narrow (aka dynamic cast, or wrap) the structure to NTMultiChannel without checking for null-ness or its ID.
|
||||
* @param structure The structure to narrow-ed (dynamic cast, wrapped) to NTMultiChannel.
|
||||
* @return NTMultiChannel instance.
|
||||
*/
|
||||
static shared_pointer narrow_unsafe(epics::pvData::PVStructurePtr const & structure);
|
||||
|
||||
/**
|
||||
* Is the pvStructure an NTMultiChannel.
|
||||
* @param structure The structure to test.
|
||||
|
@ -97,6 +97,19 @@ void NTNameValueBuilder::reset()
|
||||
|
||||
const std::string NTNameValue::URI("uri:ev4:nt/2012/pwd:NTNameValue");
|
||||
|
||||
NTNameValue::shared_pointer NTNameValue::narrow(PVStructurePtr const & structure)
|
||||
{
|
||||
if (!structure || !is_a(structure->getStructure()))
|
||||
return shared_pointer();
|
||||
|
||||
return narrow_unsafe(structure);
|
||||
}
|
||||
|
||||
NTNameValue::shared_pointer NTNameValue::narrow_unsafe(PVStructurePtr const & structure)
|
||||
{
|
||||
return shared_pointer(new NTNameValue(structure));
|
||||
}
|
||||
|
||||
bool NTNameValue::is_a(StructureConstPtr const & structure)
|
||||
{
|
||||
return structure->getID() == URI;
|
||||
|
@ -106,6 +106,22 @@ public:
|
||||
|
||||
static const std::string URI;
|
||||
|
||||
/**
|
||||
* Narrow (aka dynamic cast, or wrap) the structure to NTNameValue.
|
||||
* First the structure ID is checked against NTNameValue::URI.
|
||||
* This method will nullptr if the structure is nullptr.
|
||||
* @param structure The structure to narrow-ed (dynamic cast, wrapped) to NTNameValue.
|
||||
* @return NTNameValue instance on success, nullptr otherwise.
|
||||
*/
|
||||
static shared_pointer narrow(epics::pvData::PVStructurePtr const & structure);
|
||||
|
||||
/**
|
||||
* Narrow (aka dynamic cast, or wrap) the structure to NTNameValue without checking for null-ness or its ID.
|
||||
* @param structure The structure to narrow-ed (dynamic cast, wrapped) to NTNameValue.
|
||||
* @return NTNameValue instance.
|
||||
*/
|
||||
static shared_pointer narrow_unsafe(epics::pvData::PVStructurePtr const & structure);
|
||||
|
||||
/**
|
||||
* Is the structure an NTNameValue.
|
||||
* @param structure The structure to test.
|
||||
|
@ -177,6 +177,19 @@ const std::string ntAttrStr("uri:ev4:nt/2012/pwd:NTAttribute");
|
||||
static FieldCreatePtr fieldCreate = getFieldCreate();
|
||||
static PVDataCreatePtr pvDataCreate = getPVDataCreate();
|
||||
|
||||
NTNDArray::shared_pointer NTNDArray::narrow(PVStructurePtr const & structure)
|
||||
{
|
||||
if (!structure || !is_a(structure->getStructure()))
|
||||
return shared_pointer();
|
||||
|
||||
return narrow_unsafe(structure);
|
||||
}
|
||||
|
||||
NTNDArray::shared_pointer NTNDArray::narrow_unsafe(PVStructurePtr const & structure)
|
||||
{
|
||||
return shared_pointer(new NTNDArray(structure));
|
||||
}
|
||||
|
||||
bool NTNDArray::is_a(StructureConstPtr const & structure)
|
||||
{
|
||||
return structure->getID() == URI;
|
||||
|
@ -104,6 +104,22 @@ public:
|
||||
|
||||
static const std::string URI;
|
||||
|
||||
/**
|
||||
* Narrow (aka dynamic cast, or wrap) the structure to NTNDArray.
|
||||
* First the structure ID is checked against NTNDArray::URI.
|
||||
* This method will nullptr if the structure is nullptr.
|
||||
* @param structure The structure to narrow-ed (dynamic cast, wrapped) to NTNDArray.
|
||||
* @return NTNDArray instance on success, nullptr otherwise.
|
||||
*/
|
||||
static shared_pointer narrow(epics::pvData::PVStructurePtr const & structure);
|
||||
|
||||
/**
|
||||
* Narrow (aka dynamic cast, or wrap) the structure to NTNDArray without checking for null-ness or its ID.
|
||||
* @param structure The structure to narrow-ed (dynamic cast, wrapped) to NTNDArray.
|
||||
* @return NTNDArray instance.
|
||||
*/
|
||||
static shared_pointer narrow_unsafe(epics::pvData::PVStructurePtr const & structure);
|
||||
|
||||
/**
|
||||
* Is the structure an NTNDArray.
|
||||
* @param structure The structure to test.
|
||||
|
@ -116,6 +116,19 @@ void NTScalarBuilder::reset()
|
||||
|
||||
const std::string NTScalar::URI("uri:ev4:nt/2012/pwd:NTScalar");
|
||||
|
||||
NTScalar::shared_pointer NTScalar::narrow(PVStructurePtr const & structure)
|
||||
{
|
||||
if (!structure || !is_a(structure->getStructure()))
|
||||
return shared_pointer();
|
||||
|
||||
return narrow_unsafe(structure);
|
||||
}
|
||||
|
||||
NTScalar::shared_pointer NTScalar::narrow_unsafe(PVStructurePtr const & structure)
|
||||
{
|
||||
return shared_pointer(new NTScalar(structure));
|
||||
}
|
||||
|
||||
bool NTScalar::is_a(StructureConstPtr const & structure)
|
||||
{
|
||||
return structure->getID() == URI;
|
||||
|
@ -122,6 +122,22 @@ public:
|
||||
|
||||
static const std::string URI;
|
||||
|
||||
/**
|
||||
* Narrow (aka dynamic cast, or wrap) the structure to NTScalar.
|
||||
* First the structure ID is checked against NTScalar::URI.
|
||||
* This method will nullptr if the structure is nullptr.
|
||||
* @param structure The structure to narrow-ed (dynamic cast, wrapped) to NTScalar.
|
||||
* @return NTScalar instance on success, nullptr otherwise.
|
||||
*/
|
||||
static shared_pointer narrow(epics::pvData::PVStructurePtr const & structure);
|
||||
|
||||
/**
|
||||
* Narrow (aka dynamic cast, or wrap) the structure to NTScalar without checking for null-ness or its ID.
|
||||
* @param structure The structure to narrow-ed (dynamic cast, wrapped) to NTScalar.
|
||||
* @return NTScalar instance.
|
||||
*/
|
||||
static shared_pointer narrow_unsafe(epics::pvData::PVStructurePtr const & structure);
|
||||
|
||||
/**
|
||||
* Is the structure an NTScalar.
|
||||
* @param structure The structure to test.
|
||||
|
@ -116,6 +116,19 @@ void NTScalarArrayBuilder::reset()
|
||||
|
||||
const std::string NTScalarArray::URI("uri:ev4:nt/2012/pwd:NTScalarArray");
|
||||
|
||||
NTScalarArray::shared_pointer NTScalarArray::narrow(PVStructurePtr const & structure)
|
||||
{
|
||||
if (!structure || !is_a(structure->getStructure()))
|
||||
return shared_pointer();
|
||||
|
||||
return narrow_unsafe(structure);
|
||||
}
|
||||
|
||||
NTScalarArray::shared_pointer NTScalarArray::narrow_unsafe(PVStructurePtr const & structure)
|
||||
{
|
||||
return shared_pointer(new NTScalarArray(structure));
|
||||
}
|
||||
|
||||
bool NTScalarArray::is_a(StructureConstPtr const & structure)
|
||||
{
|
||||
return structure->getID() == URI;
|
||||
|
@ -122,6 +122,23 @@ public:
|
||||
|
||||
static const std::string URI;
|
||||
|
||||
/**
|
||||
* Narrow (aka dynamic cast, or wrap) the structure to NTScalarArray.
|
||||
* First the structure ID is checked against NTScalarArray::URI.
|
||||
* This method will nullptr if the structure is nullptr.
|
||||
* @param structure The structure to narrow-ed (dynamic cast, wrapped) to NTScalarArray.
|
||||
* @return NTScalarArray instance on success, nullptr otherwise.
|
||||
*/
|
||||
static shared_pointer narrow(epics::pvData::PVStructurePtr const & structure);
|
||||
|
||||
/**
|
||||
* Narrow (aka dynamic cast, or wrap) the structure to NTScalarArray without checking for null-ness or its ID.
|
||||
* @param structure The structure to narrow-ed (dynamic cast, wrapped) to NTScalarArray.
|
||||
* @return NTScalarArray instance.
|
||||
*/
|
||||
static shared_pointer narrow_unsafe(epics::pvData::PVStructurePtr const & structure);
|
||||
|
||||
|
||||
/**
|
||||
* Is the structure an NTScalarArray.
|
||||
* @param structure The structure to test.
|
||||
|
@ -115,6 +115,19 @@ void NTTableBuilder::reset()
|
||||
|
||||
const std::string NTTable::URI("uri:ev4:nt/2012/pwd:NTTable");
|
||||
|
||||
NTTable::shared_pointer NTTable::narrow(PVStructurePtr const & structure)
|
||||
{
|
||||
if (!structure || !is_a(structure->getStructure()))
|
||||
return shared_pointer();
|
||||
|
||||
return narrow_unsafe(structure);
|
||||
}
|
||||
|
||||
NTTable::shared_pointer NTTable::narrow_unsafe(PVStructurePtr const & structure)
|
||||
{
|
||||
return shared_pointer(new NTTable(structure));
|
||||
}
|
||||
|
||||
bool NTTable::is_a(StructureConstPtr const & structure)
|
||||
{
|
||||
return structure->getID() == URI;
|
||||
|
@ -110,6 +110,22 @@ public:
|
||||
|
||||
static const std::string URI;
|
||||
|
||||
/**
|
||||
* Narrow (aka dynamic cast, or wrap) the structure to NTTable.
|
||||
* First the structure ID is checked against NTTable::URI.
|
||||
* This method will nullptr if the structure is nullptr.
|
||||
* @param structure The structure to narrow-ed (dynamic cast, wrapped) to NTTable.
|
||||
* @return NTTable instance on success, nullptr otherwise.
|
||||
*/
|
||||
static shared_pointer narrow(epics::pvData::PVStructurePtr const & structure);
|
||||
|
||||
/**
|
||||
* Narrow (aka dynamic cast, or wrap) the structure to NTTable without checking for null-ness or its ID.
|
||||
* @param structure The structure to narrow-ed (dynamic cast, wrapped) to NTTable.
|
||||
* @return NTTable instance.
|
||||
*/
|
||||
static shared_pointer narrow_unsafe(epics::pvData::PVStructurePtr const & structure);
|
||||
|
||||
/**
|
||||
* Is the structure an NTTable.
|
||||
* @param structure The structure to test.
|
||||
|
@ -147,10 +147,42 @@ static void test()
|
||||
}
|
||||
|
||||
|
||||
void test_narrow()
|
||||
{
|
||||
testDiag("test_narrow");
|
||||
|
||||
NTMultiChannelPtr nullPtr = NTMultiChannel::narrow(PVStructurePtr());
|
||||
testOk(nullPtr.get() == 0, "nullptr narrow");
|
||||
|
||||
nullPtr = NTMultiChannel::narrow(
|
||||
getPVDataCreate()->createPVStructure(
|
||||
NTField::get()->createTimeStamp()
|
||||
)
|
||||
);
|
||||
testOk(nullPtr.get() == 0, "wrong type narrow");
|
||||
|
||||
|
||||
NTMultiChannelBuilderPtr builder = NTMultiChannel::createBuilder();
|
||||
testOk(builder.get() != 0, "Got builder");
|
||||
|
||||
PVStructurePtr pvStructure = builder->
|
||||
createPVStructure();
|
||||
testOk1(pvStructure.get() != 0);
|
||||
if (!pvStructure)
|
||||
return;
|
||||
|
||||
NTMultiChannelPtr ptr = NTMultiChannel::narrow(pvStructure);
|
||||
testOk(ptr.get() != 0, "narrow OK");
|
||||
|
||||
ptr = NTMultiChannel::narrow_unsafe(pvStructure);
|
||||
testOk(ptr.get() != 0, "narrow_unsafe OK");
|
||||
}
|
||||
|
||||
MAIN(testCreateRequest)
|
||||
{
|
||||
testPlan(18);
|
||||
testPlan(24);
|
||||
test();
|
||||
test_narrow();
|
||||
return testDone();
|
||||
}
|
||||
|
||||
|
@ -171,10 +171,44 @@ void test_ntnameValue()
|
||||
|
||||
}
|
||||
|
||||
|
||||
void test_narrow()
|
||||
{
|
||||
testDiag("test_narrow");
|
||||
|
||||
NTNameValuePtr nullPtr = NTNameValue::narrow(PVStructurePtr());
|
||||
testOk(nullPtr.get() == 0, "nullptr narrow");
|
||||
|
||||
nullPtr = NTNameValue::narrow(
|
||||
getPVDataCreate()->createPVStructure(
|
||||
NTField::get()->createTimeStamp()
|
||||
)
|
||||
);
|
||||
testOk(nullPtr.get() == 0, "wrong type narrow");
|
||||
|
||||
|
||||
NTNameValueBuilderPtr builder = NTNameValue::createBuilder();
|
||||
testOk(builder.get() != 0, "Got builder");
|
||||
|
||||
PVStructurePtr pvStructure = builder->
|
||||
value(pvString)->
|
||||
createPVStructure();
|
||||
testOk1(pvStructure.get() != 0);
|
||||
if (!pvStructure)
|
||||
return;
|
||||
|
||||
NTNameValuePtr ptr = NTNameValue::narrow(pvStructure);
|
||||
testOk(ptr.get() != 0, "narrow OK");
|
||||
|
||||
ptr = NTNameValue::narrow_unsafe(pvStructure);
|
||||
testOk(ptr.get() != 0, "narrow_unsafe OK");
|
||||
}
|
||||
|
||||
MAIN(testNTNameValue) {
|
||||
testPlan(31);
|
||||
testPlan(37);
|
||||
test_builder();
|
||||
test_ntnameValue();
|
||||
test_narrow();
|
||||
return testDone();
|
||||
}
|
||||
|
||||
|
@ -48,9 +48,42 @@ void test_builder()
|
||||
|
||||
}
|
||||
|
||||
|
||||
void test_narrow()
|
||||
{
|
||||
testDiag("test_narrow");
|
||||
|
||||
NTNDArrayPtr nullPtr = NTNDArray::narrow(PVStructurePtr());
|
||||
testOk(nullPtr.get() == 0, "nullptr narrow");
|
||||
|
||||
nullPtr = NTNDArray::narrow(
|
||||
getPVDataCreate()->createPVStructure(
|
||||
NTField::get()->createTimeStamp()
|
||||
)
|
||||
);
|
||||
testOk(nullPtr.get() == 0, "wrong type narrow");
|
||||
|
||||
|
||||
NTNDArrayBuilderPtr builder = NTNDArray::createBuilder();
|
||||
testOk(builder.get() != 0, "Got builder");
|
||||
|
||||
PVStructurePtr pvStructure = builder->
|
||||
createPVStructure();
|
||||
testOk1(pvStructure.get() != 0);
|
||||
if (!pvStructure)
|
||||
return;
|
||||
|
||||
NTNDArrayPtr ptr = NTNDArray::narrow(pvStructure);
|
||||
testOk(ptr.get() != 0, "narrow OK");
|
||||
|
||||
ptr = NTNDArray::narrow_unsafe(pvStructure);
|
||||
testOk(ptr.get() != 0, "narrow_unsafe OK");
|
||||
}
|
||||
|
||||
MAIN(testNTNDArray) {
|
||||
testPlan(16);
|
||||
testPlan(22);
|
||||
test_builder();
|
||||
test_narrow();
|
||||
return testDone();
|
||||
}
|
||||
|
||||
|
@ -196,10 +196,44 @@ void test_ntscalarArray()
|
||||
|
||||
}
|
||||
|
||||
|
||||
void test_narrow()
|
||||
{
|
||||
testDiag("test_narrow");
|
||||
|
||||
NTScalarArrayPtr nullPtr = NTScalarArray::narrow(PVStructurePtr());
|
||||
testOk(nullPtr.get() == 0, "nullptr narrow");
|
||||
|
||||
nullPtr = NTScalarArray::narrow(
|
||||
getPVDataCreate()->createPVStructure(
|
||||
NTField::get()->createTimeStamp()
|
||||
)
|
||||
);
|
||||
testOk(nullPtr.get() == 0, "wrong type narrow");
|
||||
|
||||
|
||||
NTScalarArrayBuilderPtr builder = NTScalarArray::createBuilder();
|
||||
testOk(builder.get() != 0, "Got builder");
|
||||
|
||||
PVStructurePtr pvStructure = builder->
|
||||
arrayValue(pvDouble)->
|
||||
createPVStructure();
|
||||
testOk1(pvStructure.get() != 0);
|
||||
if (!pvStructure)
|
||||
return;
|
||||
|
||||
NTScalarArrayPtr ptr = NTScalarArray::narrow(pvStructure);
|
||||
testOk(ptr.get() != 0, "narrow OK");
|
||||
|
||||
ptr = NTScalarArray::narrow_unsafe(pvStructure);
|
||||
testOk(ptr.get() != 0, "narrow_unsafe OK");
|
||||
}
|
||||
|
||||
MAIN(testNTScalarArray) {
|
||||
testPlan(31);
|
||||
testPlan(37);
|
||||
test_builder();
|
||||
test_ntscalarArray();
|
||||
test_narrow();
|
||||
return testDone();
|
||||
}
|
||||
|
||||
|
@ -186,10 +186,43 @@ void test_ntscalar()
|
||||
|
||||
}
|
||||
|
||||
void test_narrow()
|
||||
{
|
||||
testDiag("test_narrow");
|
||||
|
||||
NTScalarPtr nullPtr = NTScalar::narrow(PVStructurePtr());
|
||||
testOk(nullPtr.get() == 0, "nullptr narrow");
|
||||
|
||||
nullPtr = NTScalar::narrow(
|
||||
getPVDataCreate()->createPVStructure(
|
||||
NTField::get()->createTimeStamp()
|
||||
)
|
||||
);
|
||||
testOk(nullPtr.get() == 0, "wrong type narrow");
|
||||
|
||||
|
||||
NTScalarBuilderPtr builder = NTScalar::createBuilder();
|
||||
testOk(builder.get() != 0, "Got builder");
|
||||
|
||||
PVStructurePtr pvStructure = builder->
|
||||
value(pvDouble)->
|
||||
createPVStructure();
|
||||
testOk1(pvStructure.get() != 0);
|
||||
if (!pvStructure)
|
||||
return;
|
||||
|
||||
NTScalarPtr ptr = NTScalar::narrow(pvStructure);
|
||||
testOk(ptr.get() != 0, "narrow OK");
|
||||
|
||||
ptr = NTScalar::narrow_unsafe(pvStructure);
|
||||
testOk(ptr.get() != 0, "narrow_unsafe OK");
|
||||
}
|
||||
|
||||
MAIN(testNTScalar) {
|
||||
testPlan(28);
|
||||
testPlan(34);
|
||||
test_builder();
|
||||
test_ntscalar();
|
||||
test_narrow();
|
||||
return testDone();
|
||||
}
|
||||
|
||||
|
@ -195,11 +195,46 @@ void test_nttable()
|
||||
|
||||
}
|
||||
|
||||
void test_narrow()
|
||||
{
|
||||
testDiag("test_narrow");
|
||||
|
||||
NTTablePtr nullPtr = NTTable::narrow(PVStructurePtr());
|
||||
testOk(nullPtr.get() == 0, "nullptr narrow");
|
||||
|
||||
nullPtr = NTTable::narrow(
|
||||
getPVDataCreate()->createPVStructure(
|
||||
NTField::get()->createTimeStamp()
|
||||
)
|
||||
);
|
||||
testOk(nullPtr.get() == 0, "wrong type narrow");
|
||||
|
||||
|
||||
NTTableBuilderPtr builder = NTTable::createBuilder();
|
||||
testOk(builder.get() != 0, "Got builder");
|
||||
|
||||
PVStructurePtr pvStructure = builder->
|
||||
add("column0", pvDouble)->
|
||||
add("column1", pvString)->
|
||||
add("column2", pvInt)->
|
||||
createPVStructure();
|
||||
testOk1(pvStructure.get() != 0);
|
||||
if (!pvStructure)
|
||||
return;
|
||||
|
||||
NTTablePtr ptr = NTTable::narrow(pvStructure);
|
||||
testOk(ptr.get() != 0, "narrow OK");
|
||||
|
||||
ptr = NTTable::narrow_unsafe(pvStructure);
|
||||
testOk(ptr.get() != 0, "narrow_unsafe OK");
|
||||
}
|
||||
|
||||
MAIN(testNTTable) {
|
||||
testPlan(39);
|
||||
testPlan(45);
|
||||
test_builder();
|
||||
test_labels();
|
||||
test_nttable();
|
||||
test_narrow();
|
||||
return testDone();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user