URI of form ev4:nt/NTType:1.0 ; narrow, narrow_unsafe, is_compatible => wrap, wrapUnsafe, isCompatible

This commit is contained in:
Marty Kraimer
2014-10-01 08:34:34 -04:00
parent 08eb138d02
commit 4ee19f4dd1
19 changed files with 230 additions and 241 deletions

View File

@@ -103,7 +103,7 @@ StructureConstPtr NTMultiChannelBuilder::createStructure()
if(valueType) {
fields[ind++] = fieldCreate->createUnionArray(valueType);
} else {
fields[ind++] = fieldCreate->createVariantUnion();
fields[ind++] = fieldCreate->createVariantUnionArray();
}
names[ind] = "channelName";
fields[ind++] = fieldCreate->createScalarArray(pvString);
@@ -195,17 +195,15 @@ NTMultiChannelBuilder::shared_pointer NTMultiChannelBuilder::add(string const &
}
const std::string NTMultiChannel::URI("uri:ev4:nt/2014/pwd:NTMultiChannel");
const std::string NTMultiChannel::URI("ev4:nt/NTMultiChannel:1.0");
NTMultiChannel::shared_pointer NTMultiChannel::narrow(PVStructurePtr const & structure)
NTMultiChannel::shared_pointer NTMultiChannel::wrap(PVStructurePtr const & structure)
{
if (!structure || !is_a(structure->getStructure()))
return shared_pointer();
return narrow_unsafe(structure);
if(!isCompatible(structure)) return shared_pointer();
return wrapUnsafe(structure);
}
NTMultiChannel::shared_pointer NTMultiChannel::narrow_unsafe(PVStructurePtr const & structure)
NTMultiChannel::shared_pointer NTMultiChannel::wrapUnsafe(PVStructurePtr const & structure)
{
return shared_pointer(new NTMultiChannel(structure));
}
@@ -215,8 +213,9 @@ bool NTMultiChannel::is_a(StructureConstPtr const &structure)
return structure->getID() == URI;
}
bool NTMultiChannel::is_compatible(PVStructurePtr const &pvStructure)
bool NTMultiChannel::isCompatible(PVStructurePtr const &pvStructure)
{
if(!pvStructure) return false;
PVUnionArrayPtr pvValue = pvStructure->getSubField<PVUnionArray>("value");
if(!pvValue) return false;
PVFieldPtr pvField = pvStructure->getSubField("descriptor");

View File

@@ -148,20 +148,20 @@ public:
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.
* Wrap (aka dynamic cast, or wrap) the structure to NTMultiChannel.
* First isCompatible is called.
* This method will nullptr if the structure is is not compatible.
* @param structure The structure to wrap-ed (dynamic cast, wrapped) to NTMultiChannel.
* @return NTMultiChannel instance on success, nullptr otherwise.
*/
static shared_pointer narrow(epics::pvData::PVStructurePtr const & structure);
static shared_pointer wrap(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.
* Wrap (aka dynamic cast, or wrap) the structure to NTMultiChannel without checking for isCompatible
* @param structure The structure to wrap-ed (dynamic cast, wrapped) to NTMultiChannel.
* @return NTMultiChannel instance.
*/
static shared_pointer narrow_unsafe(epics::pvData::PVStructurePtr const & structure);
static shared_pointer wrapUnsafe(epics::pvData::PVStructurePtr const & structure);
/**
* Is the Structure an NTMultiChannel.
* This method structure->getID() and checks if it is the same as the URI.
@@ -176,7 +176,7 @@ public:
* @param pvStructure The pvStructure to test.
* @return (false,true) if (is not, is) an NTMultiChannel.
*/
static bool is_compatible(
static bool isCompatible(
epics::pvData::PVStructurePtr const &pvStructure);
/**
* Create a NTMultiChannelBuilder instance

View File

@@ -108,17 +108,15 @@ NTNameValueBuilder::shared_pointer NTNameValueBuilder::add(string const & name,
}
const std::string NTNameValue::URI("uri:ev4:nt/2014/pwd:NTNameValue");
const std::string NTNameValue::URI("ev4:nt/NTNameValue:1.0");
NTNameValue::shared_pointer NTNameValue::narrow(PVStructurePtr const & structure)
NTNameValue::shared_pointer NTNameValue::wrap(PVStructurePtr const & structure)
{
if (!structure || !is_a(structure->getStructure()))
return shared_pointer();
return narrow_unsafe(structure);
if(!isCompatible(structure)) return shared_pointer();
return wrapUnsafe(structure);
}
NTNameValue::shared_pointer NTNameValue::narrow_unsafe(PVStructurePtr const & structure)
NTNameValue::shared_pointer NTNameValue::wrapUnsafe(PVStructurePtr const & structure)
{
return shared_pointer(new NTNameValue(structure));
}
@@ -128,8 +126,9 @@ bool NTNameValue::is_a(StructureConstPtr const & structure)
return structure->getID() == URI;
}
bool NTNameValue::is_compatible(PVStructurePtr const & pvStructure)
bool NTNameValue::isCompatible(PVStructurePtr const & pvStructure)
{
if(!pvStructure) return false;
PVStringArrayPtr pvName = pvStructure->getSubField<PVStringArray>("name");
if(!pvName) return false;
PVFieldPtr pvValue = pvStructure->getSubField("value");

View File

@@ -119,20 +119,21 @@ 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.
* Wrap (aka dynamic cast, or wrap) the structure to NTNameValue.
* First isCompatible is called.
* This method will nullptr if the structure is is not compatible.
* This method will nullptr if the structure is nullptr.
* @param structure The structure to narrow-ed (dynamic cast, wrapped) to NTNameValue.
* @param structure The structure to wrap-ed (dynamic cast, wrapped) to NTNameValue.
* @return NTNameValue instance on success, nullptr otherwise.
*/
static shared_pointer narrow(epics::pvData::PVStructurePtr const & structure);
static shared_pointer wrap(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.
* Wrap (aka dynamic cast, or wrap) the structure to NTMultiChannel without checking for isCompatible
* @param structure The structure to wrap-ed (dynamic cast, wrapped) to NTNameValue.
* @return NTNameValue instance.
*/
static shared_pointer narrow_unsafe(epics::pvData::PVStructurePtr const & structure);
static shared_pointer wrapUnsafe(epics::pvData::PVStructurePtr const & structure);
/**
* Is the structure an NTNameValue.
@@ -146,7 +147,7 @@ public:
* @param pvStructure The pvStructure to test.
* @return (false,true) if (is not, is) an NTMultiChannel.
*/
static bool is_compatible(
static bool isCompatible(
epics::pvData::PVStructurePtr const &pvStructure);
/**
* Create a NTNameValue builder instance.

View File

@@ -18,7 +18,7 @@ static NTFieldPtr ntField = NTField::get();
namespace detail {
const std::string ntAttrStr("uri:ev4:nt/2014/pwd:NTAttribute");
const std::string ntAttrStr("ev4:nt/NTAttribute:1.0");
static FieldCreatePtr fieldCreate = getFieldCreate();
static PVDataCreatePtr pvDataCreate = getPVDataCreate();
@@ -198,21 +198,19 @@ NTNDArrayBuilder::shared_pointer NTNDArrayBuilder::add(string const & name, Fiel
}
const std::string NTNDArray::URI("uri:ev4:nt/2014/pwd:NTNDArray");
const std::string ntAttrStr("uri:ev4:nt/2014/pwd:NTAttribute");
const std::string NTNDArray::URI("ev4:nt/NTNDArray:1.0");
const std::string ntAttrStr("ev4:nt/NTAttribute:1.0");
static FieldCreatePtr fieldCreate = getFieldCreate();
static PVDataCreatePtr pvDataCreate = getPVDataCreate();
NTNDArray::shared_pointer NTNDArray::narrow(PVStructurePtr const & structure)
NTNDArray::shared_pointer NTNDArray::wrap(PVStructurePtr const & structure)
{
if (!structure || !is_a(structure->getStructure()))
return shared_pointer();
return narrow_unsafe(structure);
if(!isCompatible(structure)) return shared_pointer();
return wrapUnsafe(structure);
}
NTNDArray::shared_pointer NTNDArray::narrow_unsafe(PVStructurePtr const & structure)
NTNDArray::shared_pointer NTNDArray::wrapUnsafe(PVStructurePtr const & structure)
{
return shared_pointer(new NTNDArray(structure));
}
@@ -222,8 +220,9 @@ bool NTNDArray::is_a(StructureConstPtr const & structure)
return structure->getID() == URI;
}
bool NTNDArray::is_compatible(PVStructurePtr const & pvStructure)
bool NTNDArray::isCompatible(PVStructurePtr const & pvStructure)
{
if(!pvStructure) return false;
PVUnionPtr pvValue = pvStructure->getSubField<PVUnion>("value");
if(!pvValue) return false;
PVFieldPtr pvField = pvStructure->getSubField("descriptor");

View File

@@ -116,20 +116,21 @@ 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.
* Wrap (aka dynamic cast, or wrap) the structure to NTNDArray.
* First isCompatible is called.
* This method will nullptr if the structure is is not compatible.
* This method will nullptr if the structure is nullptr.
* @param structure The structure to narrow-ed (dynamic cast, wrapped) to NTNDArray.
* @param structure The structure to wrap-ed (dynamic cast, wrapped) to NTNDArray.
* @return NTNDArray instance on success, nullptr otherwise.
*/
static shared_pointer narrow(epics::pvData::PVStructurePtr const & structure);
static shared_pointer wrap(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.
* Wrap (aka dynamic cast, or wrap) the structure to NTMultiChannel without checking for isCompatible
* @param structure The structure to wrap-ed (dynamic cast, wrapped) to NTNDArray.
* @return NTNDArray instance.
*/
static shared_pointer narrow_unsafe(epics::pvData::PVStructurePtr const & structure);
static shared_pointer wrapUnsafe(epics::pvData::PVStructurePtr const & structure);
/**
* Is the structure an NTNDArray.
@@ -144,7 +145,7 @@ public:
* @param pvStructure The pvStructure to test.
* @return (false,true) if (is not, is) an NTMultiChannel.
*/
static bool is_compatible(
static bool isCompatible(
epics::pvData::PVStructurePtr const &pvStructure);
/**
* Create a NTNDArrayBuilder instance

View File

@@ -128,17 +128,15 @@ NTScalarBuilder::shared_pointer NTScalarBuilder::add(string const & name, FieldC
}
const std::string NTScalar::URI("uri:ev4:nt/2014/pwd:NTScalar");
const std::string NTScalar::URI("ev4:nt/NTScalar:1.0");
NTScalar::shared_pointer NTScalar::narrow(PVStructurePtr const & structure)
NTScalar::shared_pointer NTScalar::wrap(PVStructurePtr const & structure)
{
if (!structure || !is_a(structure->getStructure()))
return shared_pointer();
return narrow_unsafe(structure);
if(!isCompatible(structure)) return shared_pointer();
return wrapUnsafe(structure);
}
NTScalar::shared_pointer NTScalar::narrow_unsafe(PVStructurePtr const & structure)
NTScalar::shared_pointer NTScalar::wrapUnsafe(PVStructurePtr const & structure)
{
return shared_pointer(new NTScalar(structure));
}
@@ -148,8 +146,9 @@ bool NTScalar::is_a(StructureConstPtr const & structure)
return structure->getID() == URI;
}
bool NTScalar::is_compatible(PVStructurePtr const & pvStructure)
bool NTScalar::isCompatible(PVStructurePtr const & pvStructure)
{
if(!pvStructure) return false;
PVScalarPtr pvValue = pvStructure->getSubField<PVScalar>("value");
if(!pvValue) return false;
PVFieldPtr pvField = pvStructure->getSubField("descriptor");

View File

@@ -134,20 +134,21 @@ 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.
* Wrap (aka dynamic cast, or wrap) the structure to NTScalar.
* First isCompatible is called.
* This method will nullptr if the structure is is not compatible.
* This method will nullptr if the structure is nullptr.
* @param structure The structure to narrow-ed (dynamic cast, wrapped) to NTScalar.
* @param structure The structure to wrap-ed (dynamic cast, wrapped) to NTScalar.
* @return NTScalar instance on success, nullptr otherwise.
*/
static shared_pointer narrow(epics::pvData::PVStructurePtr const & structure);
static shared_pointer wrap(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.
* Wrap (aka dynamic cast, or wrap) the structure to NTMultiChannel without checking for isCompatible
* @param structure The structure to wrap-ed (dynamic cast, wrapped) to NTScalar.
* @return NTScalar instance.
*/
static shared_pointer narrow_unsafe(epics::pvData::PVStructurePtr const & structure);
static shared_pointer wrapUnsafe(epics::pvData::PVStructurePtr const & structure);
/**
* Is the structure an NTScalar.
@@ -161,7 +162,7 @@ public:
* @param pvStructure The pvStructure to test.
* @return (false,true) if (is not, is) an NTMultiChannel.
*/
static bool is_compatible(
static bool isCompatible(
epics::pvData::PVStructurePtr const &pvStructure);
/**
* Create a NTScalar builder instance.

View File

@@ -125,17 +125,15 @@ NTScalarArrayBuilder::shared_pointer NTScalarArrayBuilder::add(string const & na
}
const std::string NTScalarArray::URI("uri:ev4:nt/2014/pwd:NTScalarArray");
const std::string NTScalarArray::URI("ev4:nt/NTScalarArray:1.0");
NTScalarArray::shared_pointer NTScalarArray::narrow(PVStructurePtr const & structure)
NTScalarArray::shared_pointer NTScalarArray::wrap(PVStructurePtr const & structure)
{
if (!structure || !is_a(structure->getStructure()))
return shared_pointer();
return narrow_unsafe(structure);
if(!isCompatible(structure)) return shared_pointer();
return wrapUnsafe(structure);
}
NTScalarArray::shared_pointer NTScalarArray::narrow_unsafe(PVStructurePtr const & structure)
NTScalarArray::shared_pointer NTScalarArray::wrapUnsafe(PVStructurePtr const & structure)
{
return shared_pointer(new NTScalarArray(structure));
}
@@ -145,8 +143,9 @@ bool NTScalarArray::is_a(StructureConstPtr const & structure)
return structure->getID() == URI;
}
bool NTScalarArray::is_compatible(PVStructurePtr const & pvStructure)
bool NTScalarArray::isCompatible(PVStructurePtr const & pvStructure)
{
if(!pvStructure) return false;
PVScalarArrayPtr pvValue = pvStructure->getSubField<PVScalarArray>("value");
if(!pvValue) return false;
PVFieldPtr pvField = pvStructure->getSubField("descriptor");

View File

@@ -134,20 +134,21 @@ 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.
* Wrap (aka dynamic cast, or wrap) the structure to NTScalarArray.
* First isCompatible is called.
* This method will nullptr if the structure is is not compatible.
* This method will nullptr if the structure is nullptr.
* @param structure The structure to narrow-ed (dynamic cast, wrapped) to NTScalarArray.
* @param structure The structure to wrap-ed (dynamic cast, wrapped) to NTScalarArray.
* @return NTScalarArray instance on success, nullptr otherwise.
*/
static shared_pointer narrow(epics::pvData::PVStructurePtr const & structure);
static shared_pointer wrap(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.
* Wrap (aka dynamic cast, or wrap) the structure to NTMultiChannel without checking for isCompatible
* @param structure The structure to wrap-ed (dynamic cast, wrapped) to NTScalarArray.
* @return NTScalarArray instance.
*/
static shared_pointer narrow_unsafe(epics::pvData::PVStructurePtr const & structure);
static shared_pointer wrapUnsafe(epics::pvData::PVStructurePtr const & structure);
/**
@@ -162,7 +163,7 @@ public:
* @param pvStructure The pvStructure to test.
* @return (false,true) if (is not, is) an NTMultiChannel.
*/
static bool is_compatible(
static bool isCompatible(
epics::pvData::PVStructurePtr const &pvStructure);
/**

View File

@@ -123,17 +123,15 @@ NTTableBuilder::shared_pointer NTTableBuilder::add(string const & name, FieldCon
}
const std::string NTTable::URI("uri:ev4:nt/2014/pwd:NTTable");
const std::string NTTable::URI("ev4:nt/NTTable:1.0");
NTTable::shared_pointer NTTable::narrow(PVStructurePtr const & structure)
NTTable::shared_pointer NTTable::wrap(PVStructurePtr const & structure)
{
if (!structure || !is_a(structure->getStructure()))
return shared_pointer();
return narrow_unsafe(structure);
if(!isCompatible(structure)) return shared_pointer();
return wrapUnsafe(structure);
}
NTTable::shared_pointer NTTable::narrow_unsafe(PVStructurePtr const & structure)
NTTable::shared_pointer NTTable::wrapUnsafe(PVStructurePtr const & structure)
{
return shared_pointer(new NTTable(structure));
}
@@ -143,19 +141,15 @@ bool NTTable::is_a(StructureConstPtr const & structure)
return structure->getID() == URI;
}
bool NTTable::is_compatible(PVStructurePtr const & pvStructure)
bool NTTable::isCompatible(PVStructurePtr const & pvStructure)
{
if(!pvStructure) return false;
PVFieldPtr pvField = pvStructure->getSubField("alarm");
if(pvField && !ntField->isAlarm(pvField->getField())) return false;
pvField = pvStructure->getSubField("timeStamp");
if(pvField && !ntField->isTimeStamp(pvField->getField())) return false;
PVStringArrayPtr pvLabel = pvStructure->getSubField<PVStringArray>("labels");
const shared_vector<const string> column(pvLabel->view());
size_t len = column.size();
for(size_t i=0; i<len; ++i) {
string value = "value." + column[i];
if(!pvStructure->getSubField<PVScalarArray>(value)) return false;
}
if(!pvLabel) return false;
return true;
}

View File

@@ -122,20 +122,21 @@ 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.
* Wrap (aka dynamic cast, or wrap) the structure to NTTable.
* First isCompatible is called.
* This method will nullptr if the structure is is not compatible.
* This method will nullptr if the structure is nullptr.
* @param structure The structure to narrow-ed (dynamic cast, wrapped) to NTTable.
* @param structure The structure to wrap-ed (dynamic cast, wrapped) to NTTable.
* @return NTTable instance on success, nullptr otherwise.
*/
static shared_pointer narrow(epics::pvData::PVStructurePtr const & structure);
static shared_pointer wrap(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.
* Wrap (aka dynamic cast, or wrap) the structure to NTMultiChannel without checking for isCompatible
* @param structure The structure to wrap-ed (dynamic cast, wrapped) to NTTable.
* @return NTTable instance.
*/
static shared_pointer narrow_unsafe(epics::pvData::PVStructurePtr const & structure);
static shared_pointer wrapUnsafe(epics::pvData::PVStructurePtr const & structure);
/**
* Is the structure an NTTable.
@@ -149,7 +150,7 @@ public:
* @param pvStructure The pvStructure to test.
* @return (false,true) if (is not, is) an NTMultiChannel.
*/
static bool is_compatible(
static bool isCompatible(
epics::pvData::PVStructurePtr const &pvStructure);
/**
* Create a NTTable builder instance.