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

@ -37,7 +37,7 @@
<h1>EPICS ntCPP</h1>
<!-- Maturity: Working Draft or Request for Comments, or Recommendation, and date. -->
<h2 class="nocount">EPICS v4 Working Group, Working Draft, 22-Sept-2014</h2>
<h2 class="nocount">EPICS v4 Working Group, Working Draft, 01-Oct-2014</h2>
<dl>
<dt>Latest version:</dt>
@ -80,7 +80,7 @@ V4 control system programming environment:<br />
<h2 class="nocount">Status of this Document</h2>
<p>This is the 22-Sept-2014 version of the C++ implementation of pvData.
<p>This is the 01-Oct-2014 version of the C++ implementation of pvData.
</p>
@ -417,7 +417,7 @@ This has methods to do the following:</p>
<h2>Normative Type NTScalar</h2>
<p>This has the following fields:</p>
<pre>
uri:ev4:nt/2014/pwd:NTScalar
ev4:nt/NTScalar:1.0
double value // mandatory and can be any numeric type
string descriptor // optional
alarm_t alarm // optional
@ -532,10 +532,10 @@ class NTScalar
public:
POINTER_DEFINITIONS(NTScalar);
~NTScalar() {}
static shared_pointer narrow(PVStructurePtr const &amp; structure);
static shared_pointer narrow_unsafe(PVStructurePtr const &amp; structure);
static shared_pointer wrap(PVStructurePtr const &amp; structure);
static shared_pointer wrapUnsafe(PVStructurePtr const &amp; structure);
static bool is_a(StructureConstPtr const &amp; structure);
static bool is_compatible(PVStructurePtr const &amp;pvStructure);
static bool isComparible(PVStructurePtr const &amp;pvStructure);
static NTScalarBuilderPtr createBuilder();
bool attachTimeStamp(PVTimeStamp &amp;pvTimeStamp) const;
@ -555,20 +555,19 @@ private:
</pre>
where
<dl>
<dt>narrow</dt>
<dt>wrap</dt>
<dd>Given a pvStructure this creates an NTScalar that warps it.
It calls <b>is_a</b> on the introspection interface of the
pvStructure and returns a null PVScalar if <b>is_a</b> returns false.
It calls <b>isCompatible</b> returns a null PVScalar if <b>isCompatible</b> returns false.
<br \>
The primary use of narrow is by pvAccess client code.
The primary use of wrap is by pvAccess client code.
The server creates a pvStructure that is valid for an NTScalar
and passes it to the client.
The client can call narrow to create an NTScalar for it;s own use.
The client can call wrap to create an NTScalar for it;s own use.
An example is:
<pre>
void myCallback(PVStructurePtr const &amp; pvStructure)
{
NTScalarPtr ntscalar = NTScalar::narrow(pvStructure);
NTScalarPtr ntscalar = NTScalar::wrap(pvStructure);
if(!ntscalar) {
// not a valid NTScalar
}
@ -576,14 +575,14 @@ void myCallback(PVStructurePtr const &amp; pvStructure)
}
</pre>
<dd>
<dt>narrow_unsafe</dt>
<dt>wrapUnsafe</dt>
<dd>Given a pvStructure this creates an NTScalar that warps it.
It does not check that the introspection interface is compatible.
This method is dangerous.</dd>
<dt>is_a</dt>
<dd>This method checks to see if the structure has an ID that is
correct for NTScalar.</dd>
<dt>is_compatible</dt>
<dt>isComparible</dt>
<dd>This method checks to see if the pvStructure has appropriate
fields to be an NTScalar.
</dd>
@ -661,7 +660,7 @@ string message = alarm.getMessage();
field is a scalar array field instead of just a scalar.</p>
<p>This has the following fields:</p>
<pre>
uri:ev4:nt/2014/pwd:NTScalarArray
ev4:nt/NTScalarArray:1.0
double[] value // mandatory and can be any numeric type
string descriptor // optional
alarm_t alarm // optional
@ -746,10 +745,10 @@ class NTScalarArray
public:
POINTER_DEFINITIONS(NTScalarArray);
~NTScalarArray() {}
static shared_pointer narrow(PVStructurePtr const &amp; structure);
static shared_pointer narrow_unsafe(PVStructurePtr const &amp; structure);
static shared_pointer wrap(PVStructurePtr const &amp; structure);
static shared_pointer wrapUnsafe(PVStructurePtr const &amp; structure);
static bool is_a(StructureConstPtr const &amp; structure);
static bool is_compatible(PVStructurePtr const &amp;pvStructure);
static bool isComparible(PVStructurePtr const &amp;pvStructure);
static NTScalarArrayBuilderPtr createBuilder();
bool attachTimeStamp(PVTimeStamp &amp;pvTimeStamp) const;
@ -769,19 +768,18 @@ private:
</pre>
where
<dl>
<dt>narrow</dt>
<dt>wrap</dt>
<dd>Given a pvStructure this creates an NTScalarArray that warps it.
It calls <b>is_a</b> on the introspection interface of the
pvStructure and returns a null PVScalarArrayPtr if <b>is_a</b> returns false.
It calls <b>isCompatible</b> returns a null PVScalarArray if <b>isCompatible</b> returns false.
<dd>
<dt>narrow_unsafe</dt>
<dt>wrapUnsafe</dt>
<dd>Given a pvStructure this creates an NTScalarArray that warps it.
It does not check that the introspection interface is compatible.
This method is dangerous.</dd>
<dt>is_a</dt>
<dd>This method checks to see if the structure has an ID that is
correct for NTScalarArray.</dd>
<dt>is_compatible</dt>
<dt>isComparible</dt>
<dd>This method checks to see if the pvStructure has appropriate
fields to be an NTScalarArray.
</dd>
@ -834,7 +832,7 @@ where
<h2>Normative Type NTNameValue</h2>
<pre>
uri:ev4:nt/2014/pwd:NTNameValue
ev4:nt/NTNameValue:1.0
string[] names // mandatory
double[] values // madatory, can be any type, must be same length as names
string descriptor // optional
@ -905,10 +903,10 @@ class NTNameValue
public:
POINTER_DEFINITIONS(NTNameValue);
~NTNameValue() {}
static shared_pointer narrow(PVStructurePtr const &amp; structure);
static shared_pointer narrow_unsafe(PVStructurePtr const &amp; structure);
static shared_pointer wrap(PVStructurePtr const &amp; structure);
static shared_pointer wrapUnsafe(PVStructurePtr const &amp; structure);
static bool is_a(StructureConstPtr const &amp; structure);
static bool is_compatible(PVStructurePtr const &amp;pvStructure);
static bool isComparible(PVStructurePtr const &amp;pvStructure);
static NTNameValueBuilderPtr createBuilder();
bool attachTimeStamp(PVTimeStamp &amp;pvTimeStamp) const;
@ -925,19 +923,18 @@ private:
</pre>
where
<dl>
<dt>narrow</dt>
<dt>wrap</dt>
<dd>Given a pvStructure this creates an NTNameValue that warps it.
It calls <b>is_a</b> on the introspection interface of the
pvStructure and returns a null NTNameValuePtr if <b>is_a</b> returns false.
It calls <b>isCompatible</b> returns a null NTNameValue if <b>isCompatible</b> returns false.
<dd>
<dt>narrow_unsafe</dt>
<dt>wrapUnsafe</dt>
<dd>Given a pvStructure this creates an NTNameValue that warps it.
It does not check that the introspection interface is compatible.
This method is dangerous.</dd>
<dt>is_a</dt>
<dd>This method checks to see if the structure has an ID that is
correct for NTNameValue.</dd>
<dt>is_compatible</dt>
<dt>isComparible</dt>
<dd>This method checks to see if the pvStructure has appropriate
fields to be an NTNameValue.
</dd>
@ -974,7 +971,7 @@ where
<h2>Normative Type NTTable</h2>
<pre>
uri:ev4:nt/2014/pwd:NTTable
ev4:nt/NTTable:1.0
string[] labels [column0,column1,column2] // mandatory
structure value // mandatory;
double[] column0 [] // name=labels[0]; can be any scalar type
@ -1045,10 +1042,10 @@ class NTTable
public:
POINTER_DEFINITIONS(NTTable);
~NTTable() {}
static shared_pointer narrow(PVStructurePtr const &amp; structure);
static shared_pointer narrow_unsafe(PVStructurePtr const &amp; structure);
static shared_pointer wrap(PVStructurePtr const &amp; structure);
static shared_pointer wrapUnsafe(PVStructurePtr const &amp; structure);
static bool is_a(StructureConstPtr const &amp; structure);
static bool is_compatible(PVStructurePtr const &amp;pvStructure);
static bool isComparible(PVStructurePtr const &amp;pvStructure);
static NTTableBuilderPtr createBuilder();
bool attachTimeStamp(PVTimeStamp &amp;pvTimeStamp) const;
@ -1066,19 +1063,18 @@ private:
</pre>
where
<dl>
<dt>narrow</dt>
<dt>wrap</dt>
<dd>Given a pvStructure this creates an NTTable that warps it.
It calls <b>is_a</b> on the introspection interface of the
pvStructure and returns a null NTTablePtr if <b>is_a</b> returns false.
It calls <b>isCompatible</b> returns a null NTTable if <b>isCompatible</b> returns false.
<dd>
<dt>narrow_unsafe</dt>
<dt>wrapUnsafe</dt>
<dd>Given a pvStructure this creates an NTTable that warps it.
It does not check that the introspection interface is compatible.
This method is dangerous.</dd>
<dt>is_a</dt>
<dd>This method checks to see if the structure has an ID that is
correct for NTTable.</dd>
<dt>is_compatible</dt>
<dt>isComparible</dt>
<dd>This method checks to see if the pvStructure has appropriate
fields to be an NTTable.
</dd>
@ -1200,10 +1196,10 @@ class NTMultiChannel
public:
POINTER_DEFINITIONS(NTMultiChannel);
~NTMultiChannel() {}
static shared_pointer narrow(PVStructurePtr const &amp; structure);
static shared_pointer narrow_unsafe(PVStructurePtr const &amp; structure);
static shared_pointer wrap(PVStructurePtr const &amp; structure);
static shared_pointer wrapUnsafe(PVStructurePtr const &amp; structure);
static bool is_a(StructureConstPtr const &amp; structure);
static bool is_compatible(PVStructurePtr const &amp;pvStructure);
static bool isComparible(PVStructurePtr const &amp;pvStructure);
static NTMultiChannelBuilderPtr createBuilder();
bool attachTimeStamp(PVTimeStamp &amp;pvTimeStamp) const;
@ -1228,19 +1224,18 @@ private:
</pre>
where
<dl>
<dt>narrow</dt>
<dt>wrap</dt>
<dd>Given a pvStructure this creates an NTMultiChannel that warps it.
It calls <b>is_a</b> on the introspection interface of the
pvStructure and returns a null NTMultiChannelPtr if <b>is_a</b> returns false.
It calls <b>isCompatible</b> returns a null NTMultiChannel if <b>isCompatible</b> returns false.
<dd>
<dt>narrow_unsafe</dt>
<dt>wrapUnsafe</dt>
<dd>Given a pvStructure this creates an NTMultiChannel that warps it.
It does not check that the introspection interface is compatible.
This method is dangerous.</dd>
<dt>is_a</dt>
<dd>This method checks to see if the structure has an ID that is
correct for NTMultiChannel.</dd>
<dt>is_compatible</dt>
<dt>isComparible</dt>
<dd>This method checks to see if the pvStructure has appropriate
fields to be an NTMultiChannel.
</dd>
@ -1291,7 +1286,7 @@ where
<h2>Normative Type NTNDArray</h2>
<pre>
uri:ev4:nt/2014/pwd:NTNDArray
ev4:nt/NTNDArray:1.0
union value //mandatory
long compressedSize //mandatory
long uncompressedSize //mandatory
@ -1311,9 +1306,9 @@ uri:ev4:nt/2014/pwd:NTNDArray
long secondsPastEpoch
int nanoseconds
int userTag
uri:ev4:nt/2014/pwd:NTAttribute[] attribute //mandatory
uri:ev4:nt/2014/pwd:NTAttribute[]
uri:ev4:nt/2014/pwd:NTAttribute
ev4:nt/NTAttribute:1.0[] attribute //mandatory
ev4:nt/NTAttribute:1.0[]
ev4:nt/NTAttribute:1.0
string name
any value
string description
@ -1389,10 +1384,10 @@ class NTNDArray
public:
POINTER_DEFINITIONS(NTNDArray);
~NTNDArray() {}
static shared_pointer narrow(PVStructurePtr const &amp; structure);
static shared_pointer narrow_unsafe(PVStructurePtr const &amp; structure);
static shared_pointer wrap(PVStructurePtr const &amp; structure);
static shared_pointer wrapUnsafe(PVStructurePtr const &amp; structure);
static bool is_a(StructureConstPtr const &amp; structure);
static bool is_compatible(PVStructurePtr const &amp;pvStructure);
static bool isComparible(PVStructurePtr const &amp;pvStructure);
static NTNDArrayBuilderPtr createBuilder();
bool attachTimeStamp(PVTimeStamp &amp;pvTimeStamp) const;
@ -1416,19 +1411,18 @@ private:
</pre>
where
<dl>
<dt>narrow</dt>
<dt>wrap</dt>
<dd>Given a pvStructure this creates an NTNDArray that warps it.
It calls <b>is_a</b> on the introspection interface of the
pvStructure and returns a null NTNDArrayPtr if <b>is_a</b> returns false.
It calls <b>isCompatible</b> returns a null NTNDArray if <b>isCompatible</b> returns false.
<dd>
<dt>narrow_unsafe</dt>
<dt>wrapUnsafe</dt>
<dd>Given a pvStructure this creates an NTNDArray that warps it.
It does not check that the introspection interface is compatible.
This method is dangerous.</dd>
<dt>is_a</dt>
<dd>This method checks to see if the structure has an ID that is
correct for NTNDArray.</dd>
<dt>is_compatible</dt>
<dt>isComparible</dt>
<dd>This method checks to see if the pvStructure has appropriate
fields to be an NTNDArray.
</dd>

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.

View File

@ -32,7 +32,7 @@ using std::cout;
using std::endl;
using std::vector;
static bool debug = true;
static bool debug = false;
static FieldCreatePtr fieldCreate = getFieldCreate();
static PVDataCreatePtr pvDataCreate = getPVDataCreate();
@ -122,7 +122,7 @@ static void test()
testOk1(multiChannel.get() != 0);
pvStructure = multiChannel->getPVStructure();
if(debug) {cout << *pvStructure << endl;}
testOk1(NTMultiChannel::is_compatible(pvStructure)==true);
testOk1(NTMultiChannel::isCompatible(pvStructure)==true);
PVStructurePtr pvTimeStamp = multiChannel->getTimeStamp();
testOk1(pvTimeStamp.get() !=0);
PVStructurePtr pvAlarm = multiChannel->getAlarm();
@ -150,19 +150,19 @@ static void test()
}
void test_narrow()
void test_wrap()
{
testDiag("test_narrow");
testDiag("test_wrap");
NTMultiChannelPtr nullPtr = NTMultiChannel::narrow(PVStructurePtr());
testOk(nullPtr.get() == 0, "nullptr narrow");
NTMultiChannelPtr nullPtr = NTMultiChannel::wrap(PVStructurePtr());
testOk(nullPtr.get() == 0, "nullptr wrap");
nullPtr = NTMultiChannel::narrow(
nullPtr = NTMultiChannel::wrap(
getPVDataCreate()->createPVStructure(
NTField::get()->createTimeStamp()
)
);
testOk(nullPtr.get() == 0, "wrong type narrow");
testOk(nullPtr.get() == 0, "wrong type wrap");
NTMultiChannelBuilderPtr builder = NTMultiChannel::createBuilder();
@ -174,18 +174,19 @@ void test_narrow()
if (!pvStructure)
return;
NTMultiChannelPtr ptr = NTMultiChannel::narrow(pvStructure);
testOk(ptr.get() != 0, "narrow OK");
NTMultiChannelPtr ptr = NTMultiChannel::wrap(pvStructure);
testOk(ptr.get() != 0, "wrap OK");
ptr = NTMultiChannel::narrow_unsafe(pvStructure);
testOk(ptr.get() != 0, "narrow_unsafe OK");
builder = NTMultiChannel::createBuilder();
ptr = NTMultiChannel::wrapUnsafe(pvStructure);
testOk(ptr.get() != 0, "wrapUnsafe OK");
}
MAIN(testCreateRequest)
{
testPlan(25);
test();
test_narrow();
test_wrap();
return testDone();
}

View File

@ -180,19 +180,19 @@ void test_ntnameValue()
}
void test_narrow()
void test_wrap()
{
testDiag("test_narrow");
testDiag("test_wrap");
NTNameValuePtr nullPtr = NTNameValue::narrow(PVStructurePtr());
testOk(nullPtr.get() == 0, "nullptr narrow");
NTNameValuePtr nullPtr = NTNameValue::wrap(PVStructurePtr());
testOk(nullPtr.get() == 0, "nullptr wrap");
nullPtr = NTNameValue::narrow(
nullPtr = NTNameValue::wrap(
getPVDataCreate()->createPVStructure(
NTField::get()->createTimeStamp()
)
);
testOk(nullPtr.get() == 0, "wrong type narrow");
testOk(nullPtr.get() == 0, "wrong type wrap");
NTNameValueBuilderPtr builder = NTNameValue::createBuilder();
@ -205,12 +205,12 @@ void test_narrow()
if (!pvStructure)
return;
testOk1(NTNameValue::is_compatible(pvStructure)==true);
NTNameValuePtr ptr = NTNameValue::narrow(pvStructure);
testOk(ptr.get() != 0, "narrow OK");
testOk1(NTNameValue::isCompatible(pvStructure)==true);
NTNameValuePtr ptr = NTNameValue::wrap(pvStructure);
testOk(ptr.get() != 0, "wrap OK");
ptr = NTNameValue::narrow_unsafe(pvStructure);
testOk(ptr.get() != 0, "narrow_unsafe OK");
ptr = NTNameValue::wrapUnsafe(pvStructure);
testOk(ptr.get() != 0, "wrapUnsafe OK");
}
void test_extra()
@ -248,7 +248,7 @@ MAIN(testNTNameValue) {
testPlan(48);
test_builder();
test_ntnameValue();
test_narrow();
test_wrap();
test_extra();
return testDone();
}

View File

@ -76,23 +76,23 @@ void test_all()
add("extra2",fieldCreate->createScalarArray(pvString)) ->
createPVStructure();
std::cout << *pvStructure << std::endl;
testOk1(NTNDArray::is_compatible(pvStructure)==true);
testOk1(NTNDArray::isCompatible(pvStructure)==true);
}
void test_narrow()
void test_wrap()
{
testDiag("test_narrow");
testDiag("test_wrap");
NTNDArrayPtr nullPtr = NTNDArray::narrow(PVStructurePtr());
testOk(nullPtr.get() == 0, "nullptr narrow");
NTNDArrayPtr nullPtr = NTNDArray::wrap(PVStructurePtr());
testOk(nullPtr.get() == 0, "nullptr wrap");
nullPtr = NTNDArray::narrow(
nullPtr = NTNDArray::wrap(
getPVDataCreate()->createPVStructure(
NTField::get()->createTimeStamp()
)
);
testOk(nullPtr.get() == 0, "wrong type narrow");
testOk(nullPtr.get() == 0, "wrong type wrap");
NTNDArrayBuilderPtr builder = NTNDArray::createBuilder();
@ -103,13 +103,13 @@ void test_narrow()
testOk1(pvStructure.get() != 0);
if (!pvStructure)
return;
testOk1(NTNDArray::is_compatible(pvStructure)==true);
testOk1(NTNDArray::isCompatible(pvStructure)==true);
NTNDArrayPtr ptr = NTNDArray::narrow(pvStructure);
testOk(ptr.get() != 0, "narrow OK");
NTNDArrayPtr ptr = NTNDArray::wrap(pvStructure);
testOk(ptr.get() != 0, "wrap OK");
ptr = NTNDArray::narrow_unsafe(pvStructure);
testOk(ptr.get() != 0, "narrow_unsafe OK");
ptr = NTNDArray::wrapUnsafe(pvStructure);
testOk(ptr.get() != 0, "wrapUnsafe OK");
}
MAIN(testNTNDArray) {
@ -118,7 +118,7 @@ MAIN(testNTNDArray) {
test_builder(false);
test_builder(false); // called twice to test caching
test_all();
test_narrow();
test_wrap();
return testDone();
}

View File

@ -201,19 +201,19 @@ void test_ntscalarArray()
}
void test_narrow()
void test_wrap()
{
testDiag("test_narrow");
testDiag("test_wrap");
NTScalarArrayPtr nullPtr = NTScalarArray::narrow(PVStructurePtr());
testOk(nullPtr.get() == 0, "nullptr narrow");
NTScalarArrayPtr nullPtr = NTScalarArray::wrap(PVStructurePtr());
testOk(nullPtr.get() == 0, "nullptr wrap");
nullPtr = NTScalarArray::narrow(
nullPtr = NTScalarArray::wrap(
getPVDataCreate()->createPVStructure(
NTField::get()->createTimeStamp()
)
);
testOk(nullPtr.get() == 0, "wrong type narrow");
testOk(nullPtr.get() == 0, "wrong type wrap");
NTScalarArrayBuilderPtr builder = NTScalarArray::createBuilder();
@ -226,19 +226,19 @@ void test_narrow()
if (!pvStructure)
return;
testOk1(NTScalarArray::is_compatible(pvStructure)==true);
NTScalarArrayPtr ptr = NTScalarArray::narrow(pvStructure);
testOk(ptr.get() != 0, "narrow OK");
testOk1(NTScalarArray::isCompatible(pvStructure)==true);
NTScalarArrayPtr ptr = NTScalarArray::wrap(pvStructure);
testOk(ptr.get() != 0, "wrap OK");
ptr = NTScalarArray::narrow_unsafe(pvStructure);
testOk(ptr.get() != 0, "narrow_unsafe OK");
ptr = NTScalarArray::wrapUnsafe(pvStructure);
testOk(ptr.get() != 0, "wrapUnsafe OK");
}
MAIN(testNTScalarArray) {
testPlan(38);
test_builder();
test_ntscalarArray();
test_narrow();
test_wrap();
return testDone();
}

View File

@ -192,19 +192,19 @@ void test_ntscalar()
}
void test_narrow()
void test_wrap()
{
testDiag("test_narrow");
testDiag("test_wrap");
NTScalarPtr nullPtr = NTScalar::narrow(PVStructurePtr());
testOk(nullPtr.get() == 0, "nullptr narrow");
NTScalarPtr nullPtr = NTScalar::wrap(PVStructurePtr());
testOk(nullPtr.get() == 0, "nullptr wrap");
nullPtr = NTScalar::narrow(
nullPtr = NTScalar::wrap(
getPVDataCreate()->createPVStructure(
NTField::get()->createTimeStamp()
)
);
testOk(nullPtr.get() == 0, "wrong type narrow");
testOk(nullPtr.get() == 0, "wrong type wrap");
NTScalarBuilderPtr builder = NTScalar::createBuilder();
@ -217,19 +217,19 @@ void test_narrow()
if (!pvStructure)
return;
testOk1(NTScalar::is_compatible(pvStructure)==true);
NTScalarPtr ptr = NTScalar::narrow(pvStructure);
testOk(ptr.get() != 0, "narrow OK");
testOk1(NTScalar::isCompatible(pvStructure)==true);
NTScalarPtr ptr = NTScalar::wrap(pvStructure);
testOk(ptr.get() != 0, "wrap OK");
ptr = NTScalar::narrow_unsafe(pvStructure);
testOk(ptr.get() != 0, "narrow_unsafe OK");
ptr = NTScalar::wrapUnsafe(pvStructure);
testOk(ptr.get() != 0, "wrapUnsafe OK");
}
MAIN(testNTScalar) {
testPlan(35);
test_builder();
test_ntscalar();
test_narrow();
test_wrap();
return testDone();
}

View File

@ -87,7 +87,7 @@ void test_labels()
if (!pvStructure)
return;
testOk1(NTTable::is_compatible(pvStructure)==true);
testOk1(NTTable::isCompatible(pvStructure)==true);
std::cout << *pvStructure << std::endl;
PVStringArrayPtr labels = pvStructure->getSubField<PVStringArray>("labels");
@ -199,19 +199,19 @@ void test_nttable()
}
void test_narrow()
void test_wrap()
{
testDiag("test_narrow");
testDiag("test_wrap");
NTTablePtr nullPtr = NTTable::narrow(PVStructurePtr());
testOk(nullPtr.get() == 0, "nullptr narrow");
NTTablePtr nullPtr = NTTable::wrap(PVStructurePtr());
testOk(nullPtr.get() == 0, "nullptr wrap");
nullPtr = NTTable::narrow(
nullPtr = NTTable::wrap(
getPVDataCreate()->createPVStructure(
NTField::get()->createTimeStamp()
)
);
testOk(nullPtr.get() == 0, "wrong type narrow");
testOk(nullPtr.get() == 0, "wrong type wrap");
NTTableBuilderPtr builder = NTTable::createBuilder();
@ -226,11 +226,11 @@ void test_narrow()
if (!pvStructure)
return;
NTTablePtr ptr = NTTable::narrow(pvStructure);
testOk(ptr.get() != 0, "narrow OK");
NTTablePtr ptr = NTTable::wrap(pvStructure);
testOk(ptr.get() != 0, "wrap OK");
ptr = NTTable::narrow_unsafe(pvStructure);
testOk(ptr.get() != 0, "narrow_unsafe OK");
ptr = NTTable::wrapUnsafe(pvStructure);
testOk(ptr.get() != 0, "wrapUnsafe OK");
}
MAIN(testNTTable) {
@ -238,7 +238,7 @@ MAIN(testNTTable) {
test_builder();
test_labels();
test_nttable();
test_narrow();
test_wrap();
return testDone();
}