NTUtils added, is_a for new URI scheme
This commit is contained in:
@ -6,6 +6,7 @@ SRC = $(TOP)/src/
|
||||
SRC_DIRS += $(SRC)/nt
|
||||
|
||||
INC += nt.h
|
||||
INC += ntutils.h
|
||||
INC += ntfield.h
|
||||
INC += ntscalar.h
|
||||
INC += ntscalarArray.h
|
||||
@ -14,6 +15,7 @@ INC += nttable.h
|
||||
INC += ntmultiChannel.h
|
||||
INC += ntndarray.h
|
||||
|
||||
LIBSRCS += ntutils.cpp
|
||||
LIBSRCS += ntfield.cpp
|
||||
LIBSRCS += ntscalar.cpp
|
||||
LIBSRCS += ntscalarArray.cpp
|
||||
|
@ -7,6 +7,9 @@
|
||||
#ifndef NT_H
|
||||
#define NT_H
|
||||
|
||||
/*
|
||||
* Include all the normative types here.
|
||||
*/
|
||||
#include <pv/ntfield.h>
|
||||
#include <pv/ntscalar.h>
|
||||
#include <pv/ntscalarArray.h>
|
||||
|
@ -8,9 +8,10 @@
|
||||
#include <pv/lock.h>
|
||||
#include <pv/ntfield.h>
|
||||
|
||||
using namespace epics::pvData;
|
||||
using std::tr1::static_pointer_cast;
|
||||
|
||||
namespace epics { namespace pvData {
|
||||
namespace epics { namespace nt {
|
||||
|
||||
NTFieldPtr NTField::get()
|
||||
{
|
||||
|
@ -17,7 +17,7 @@
|
||||
#include <pv/pvTimeStamp.h>
|
||||
#include <pv/sharedVector.h>
|
||||
|
||||
namespace epics { namespace pvData {
|
||||
namespace epics { namespace nt {
|
||||
/**
|
||||
* Convenience Class for introspection fields of a Normative Type
|
||||
* @author mrk
|
||||
@ -47,83 +47,83 @@ public:
|
||||
* @param field The field to test.
|
||||
* @return (false,true) if field (is not,is) an enumerated structure.
|
||||
*/
|
||||
bool isEnumerated(FieldConstPtr const & field);
|
||||
bool isEnumerated(epics::pvData::FieldConstPtr const & field);
|
||||
/**
|
||||
* Is field a timeStamp structure.
|
||||
* @param field The field to test.
|
||||
* @return (false,true) if field (is not,is) a timeStamp structure.
|
||||
*/
|
||||
bool isTimeStamp(FieldConstPtr const & field);
|
||||
bool isTimeStamp(epics::pvData::FieldConstPtr const & field);
|
||||
/**
|
||||
* Is field an alarm structure.
|
||||
* @param field The field to test.
|
||||
* @return (false,true) if field (is not,is) an alarm structure.
|
||||
*/
|
||||
bool isAlarm(FieldConstPtr const & field);
|
||||
bool isAlarm(epics::pvData::FieldConstPtr const & field);
|
||||
/**
|
||||
* Is field a display structure.
|
||||
* @param field The field to test.
|
||||
* @return (false,true) if field (is not,is) a display structure.
|
||||
*/
|
||||
bool isDisplay(FieldConstPtr const & field);
|
||||
bool isDisplay(epics::pvData::FieldConstPtr const & field);
|
||||
/**
|
||||
* Is field an alarmLimit structure.
|
||||
* @param field The field to test.
|
||||
* @return (false,true) if field (is not,is) an alarmLimit structure.
|
||||
*/
|
||||
bool isAlarmLimit(FieldConstPtr const & field);
|
||||
bool isAlarmLimit(epics::pvData::FieldConstPtr const & field);
|
||||
/**
|
||||
* Is field a control structure.
|
||||
* @param field The field to test.
|
||||
* @return (false,true) if field (is not,is) a control structure.
|
||||
*/
|
||||
bool isControl(FieldConstPtr const & field);
|
||||
bool isControl(epics::pvData::FieldConstPtr const & field);
|
||||
|
||||
/**
|
||||
* Create an enumerated structure.
|
||||
* @return an enumerated structure.
|
||||
*/
|
||||
StructureConstPtr createEnumerated();
|
||||
epics::pvData::StructureConstPtr createEnumerated();
|
||||
/**
|
||||
* Create a timeStamp structure.
|
||||
* @return a timeStamp structure.
|
||||
*/
|
||||
StructureConstPtr createTimeStamp();
|
||||
epics::pvData::StructureConstPtr createTimeStamp();
|
||||
/**
|
||||
* Create an alarm structure.
|
||||
* @return an alarm structure.
|
||||
*/
|
||||
StructureConstPtr createAlarm();
|
||||
epics::pvData::StructureConstPtr createAlarm();
|
||||
/**
|
||||
* Create a display structure.
|
||||
* @return a displayalarm structure.
|
||||
*/
|
||||
StructureConstPtr createDisplay();
|
||||
epics::pvData::StructureConstPtr createDisplay();
|
||||
/**
|
||||
* Create a control structure.
|
||||
* @return a control structure.
|
||||
*/
|
||||
StructureConstPtr createControl();
|
||||
epics::pvData::StructureConstPtr createControl();
|
||||
|
||||
/**
|
||||
* Create an array of enumerated structures.
|
||||
* @return an array of enumerated structures.
|
||||
*/
|
||||
StructureArrayConstPtr createEnumeratedArray();
|
||||
epics::pvData::StructureArrayConstPtr createEnumeratedArray();
|
||||
/**
|
||||
* Create an array of timeStamp structures.
|
||||
* @return an array of timeStamp structures.
|
||||
*/
|
||||
StructureArrayConstPtr createTimeStampArray();
|
||||
epics::pvData::StructureArrayConstPtr createTimeStampArray();
|
||||
/**
|
||||
* Create an array of alarm structures.
|
||||
* @return an array of alarm structures.
|
||||
*/
|
||||
StructureArrayConstPtr createAlarmArray();
|
||||
epics::pvData::StructureArrayConstPtr createAlarmArray();
|
||||
private:
|
||||
NTField();
|
||||
FieldCreatePtr fieldCreate;
|
||||
StandardFieldPtr standardField;
|
||||
epics::pvData::FieldCreatePtr fieldCreate;
|
||||
epics::pvData::StandardFieldPtr standardField;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -148,54 +148,54 @@ public:
|
||||
* @param choices The array of choices.
|
||||
* @return an enumerated PVStructure..
|
||||
*/
|
||||
PVStructurePtr createEnumerated(
|
||||
StringArray const & choices);
|
||||
epics::pvData::PVStructurePtr createEnumerated(
|
||||
epics::pvData::StringArray const & choices);
|
||||
/**
|
||||
* Create a timeStamp PVStructure.
|
||||
* @return a timeStamp PVStructure..
|
||||
*/
|
||||
PVStructurePtr createTimeStamp();
|
||||
epics::pvData::PVStructurePtr createTimeStamp();
|
||||
/**
|
||||
* Create an alarm PVStructure.
|
||||
* @return an alarm PVStructure..
|
||||
*/
|
||||
PVStructurePtr createAlarm();
|
||||
epics::pvData::PVStructurePtr createAlarm();
|
||||
/**
|
||||
* Create a display PVStructure.
|
||||
* @return a display PVStructure..
|
||||
*/
|
||||
PVStructurePtr createDisplay();
|
||||
epics::pvData::PVStructurePtr createDisplay();
|
||||
/**
|
||||
* Create an alarmLimit PVStructure.
|
||||
* @return an alarmLimit PVStructure..
|
||||
*/
|
||||
PVStructurePtr createAlarmLimit();
|
||||
epics::pvData::PVStructurePtr createAlarmLimit();
|
||||
/**
|
||||
* Create a control PVStructure.
|
||||
* @return a control PVStructure..
|
||||
*/
|
||||
PVStructurePtr createControl();
|
||||
epics::pvData::PVStructurePtr createControl();
|
||||
|
||||
/**
|
||||
* Create an enumerated PVStructureArray.
|
||||
* @return an enumerated PVStructureArray..
|
||||
*/
|
||||
PVStructureArrayPtr createEnumeratedArray();
|
||||
epics::pvData::PVStructureArrayPtr createEnumeratedArray();
|
||||
/**
|
||||
* Create a timeStamp PVStructureArray.
|
||||
* @return a timeStamp PVStructureArray
|
||||
*/
|
||||
PVStructureArrayPtr createTimeStampArray();
|
||||
epics::pvData::PVStructureArrayPtr createTimeStampArray();
|
||||
/**
|
||||
* Create an alarm PVStructureArray.
|
||||
* @return an alarm PVStructureArray..
|
||||
*/
|
||||
PVStructureArrayPtr createAlarmArray();
|
||||
epics::pvData::PVStructureArrayPtr createAlarmArray();
|
||||
private:
|
||||
PVNTField();
|
||||
PVDataCreatePtr pvDataCreate;
|
||||
StandardFieldPtr standardField;
|
||||
StandardPVFieldPtr standardPVField;
|
||||
epics::pvData::PVDataCreatePtr pvDataCreate;
|
||||
epics::pvData::StandardFieldPtr standardField;
|
||||
epics::pvData::StandardPVFieldPtr standardPVField;
|
||||
NTFieldPtr ntstructureField;
|
||||
};
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include <pv/ntmultiChannel.h>
|
||||
#include <pv/ntutils.h>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
@ -210,7 +211,7 @@ NTMultiChannel::shared_pointer NTMultiChannel::wrapUnsafe(PVStructurePtr const &
|
||||
|
||||
bool NTMultiChannel::is_a(StructureConstPtr const &structure)
|
||||
{
|
||||
return structure->getID() == URI;
|
||||
return NTUtils::is_a(structure->getID(), URI);
|
||||
}
|
||||
|
||||
bool NTMultiChannel::isCompatible(PVStructurePtr const &pvStructure)
|
||||
|
@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include <pv/ntnameValue.h>
|
||||
#include <pv/ntutils.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace epics::pvData;
|
||||
@ -123,7 +124,7 @@ NTNameValue::shared_pointer NTNameValue::wrapUnsafe(PVStructurePtr const & struc
|
||||
|
||||
bool NTNameValue::is_a(StructureConstPtr const & structure)
|
||||
{
|
||||
return structure->getID() == URI;
|
||||
return NTUtils::is_a(structure->getID(), URI);
|
||||
}
|
||||
|
||||
bool NTNameValue::isCompatible(PVStructurePtr const & pvStructure)
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include <pv/ntndarray.h>
|
||||
#include <pv/ntutils.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace epics::pvData;
|
||||
@ -217,7 +218,7 @@ NTNDArray::shared_pointer NTNDArray::wrapUnsafe(PVStructurePtr const & structure
|
||||
|
||||
bool NTNDArray::is_a(StructureConstPtr const & structure)
|
||||
{
|
||||
return structure->getID() == URI;
|
||||
return NTUtils::is_a(structure->getID(), URI);
|
||||
}
|
||||
|
||||
bool NTNDArray::isCompatible(PVStructurePtr const & pvStructure)
|
||||
|
@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include <pv/ntscalar.h>
|
||||
#include <pv/ntutils.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace epics::pvData;
|
||||
@ -143,7 +144,7 @@ NTScalar::shared_pointer NTScalar::wrapUnsafe(PVStructurePtr const & structure)
|
||||
|
||||
bool NTScalar::is_a(StructureConstPtr const & structure)
|
||||
{
|
||||
return structure->getID() == URI;
|
||||
return NTUtils::is_a(structure->getID(), URI);
|
||||
}
|
||||
|
||||
bool NTScalar::isCompatible(PVStructurePtr const & pvStructure)
|
||||
|
@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include <pv/ntscalarArray.h>
|
||||
#include <pv/ntutils.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace epics::pvData;
|
||||
@ -140,7 +141,7 @@ NTScalarArray::shared_pointer NTScalarArray::wrapUnsafe(PVStructurePtr const & s
|
||||
|
||||
bool NTScalarArray::is_a(StructureConstPtr const & structure)
|
||||
{
|
||||
return structure->getID() == URI;
|
||||
return NTUtils::is_a(structure->getID(), URI);
|
||||
}
|
||||
|
||||
bool NTScalarArray::isCompatible(PVStructurePtr const & pvStructure)
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include <pv/nttable.h>
|
||||
#include <pv/ntutils.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace epics::pvData;
|
||||
@ -138,7 +139,7 @@ NTTable::shared_pointer NTTable::wrapUnsafe(PVStructurePtr const & structure)
|
||||
|
||||
bool NTTable::is_a(StructureConstPtr const & structure)
|
||||
{
|
||||
return structure->getID() == URI;
|
||||
return NTUtils::is_a(structure->getID(), URI);
|
||||
}
|
||||
|
||||
bool NTTable::isCompatible(PVStructurePtr const & pvStructure)
|
||||
|
24
src/nt/ntutils.cpp
Normal file
24
src/nt/ntutils.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
/* ntutils.cpp */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
|
||||
#include <pv/ntutils.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace epics { namespace nt {
|
||||
|
||||
bool NTUtils::is_a(const std::string &u1, const std::string &u2)
|
||||
{
|
||||
// remove minor for the u2
|
||||
size_t pos = u2.find_last_of('.');
|
||||
std::string su2 = (pos == string::npos) ? u2 : u2.substr(0, pos);
|
||||
|
||||
// "starts with comparison"
|
||||
return su2.size() <= u1.size() && u1.compare(0, su2.size(), su2) == 0;
|
||||
}
|
||||
|
||||
}}
|
38
src/nt/ntutils.h
Normal file
38
src/nt/ntutils.h
Normal file
@ -0,0 +1,38 @@
|
||||
/* ntutils.h */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
#ifndef NTUTILS_H
|
||||
#define NTUTILS_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace epics { namespace nt {
|
||||
|
||||
/**
|
||||
* Utility methods for NT types.
|
||||
* @author mse
|
||||
*/
|
||||
class NTUtils {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Checks whether NT types are compatible by checking their IDs,
|
||||
* i.e. their names and major version must match.
|
||||
* @param u1 the first uri.
|
||||
* @param u2 the second uri.
|
||||
* @return true of URIs are compatible, false otherwise.
|
||||
*/
|
||||
static bool is_a(const std::string &u1, const std::string &u2);
|
||||
|
||||
private:
|
||||
// disable object creation
|
||||
NTUtils() {}
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif /* NTUTILS_H */
|
||||
|
@ -32,6 +32,10 @@ TESTPROD_HOST += ntndarrayTest
|
||||
ntndarrayTest_SRCS = ntndarrayTest.cpp
|
||||
TESTS += ntndarrayTest
|
||||
|
||||
TESTPROD_HOST += ntutilsTest
|
||||
ntndarrayTest_SRCS = ntutilsTest.cpp
|
||||
TESTS += ntutilsTest
|
||||
|
||||
TESTSCRIPTS_HOST += $(TESTS:%=%.t)
|
||||
|
||||
include $(TOP)/configure/RULES
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
#include <pv/nt.h>
|
||||
|
||||
using namespace epics::nt;
|
||||
using namespace epics::pvData;
|
||||
using std::string;
|
||||
using std::cout;
|
||||
|
36
test/nt/ntutilsTest.cpp
Normal file
36
test/nt/ntutilsTest.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
|
||||
#include <epicsUnitTest.h>
|
||||
#include <testMain.h>
|
||||
|
||||
#include <pv/ntutils.h>
|
||||
|
||||
|
||||
using namespace epics::nt;
|
||||
|
||||
void test_is_a()
|
||||
{
|
||||
testDiag("test_is_a");
|
||||
|
||||
testOk1(NTUtils::is_a("epics:nt/NTTable:1.0", "epics:nt/NTTable:1.0"));
|
||||
testOk1(NTUtils::is_a("epics:nt/NTTable:2.0", "epics:nt/NTTable:2.0"));
|
||||
testOk1(NTUtils::is_a("epics:nt/NTTable:1.0", "epics:nt/NTTable:1.1"));
|
||||
testOk1(NTUtils::is_a("epics:nt/NTTable:1.1", "epics:nt/NTTable:1.0"));
|
||||
|
||||
testOk1(!NTUtils::is_a("epics:nt/NTTable:1.0", "epics:nt/NTTable:2.0"));
|
||||
testOk1(!NTUtils::is_a("epics:nt/NTTable:2.0", "epics:nt/NTTable:1.0"));
|
||||
testOk1(!NTUtils::is_a("epics:nt/NTTable:1.3", "epics:nt/NTTable:2.3"));
|
||||
testOk1(!NTUtils::is_a("epics:nt/NTTable:1.0", "epics:nt/NTMatrix:1.0"));
|
||||
}
|
||||
|
||||
MAIN(testNTUtils) {
|
||||
testPlan(8);
|
||||
test_is_a();
|
||||
return testDone();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user