From c4f6132aca65bce357e802a4010c005fdc8952c8 Mon Sep 17 00:00:00 2001 From: Matej Sekoranja Date: Fri, 8 Feb 2013 22:45:04 +0100 Subject: [PATCH] added simple operators 'test', added <<= >>= operators to PVScalar --- pvDataApp/pv/pvData.h | 14 ++++++ testApp/pv/Makefile | 4 ++ testApp/pv/testOperators.cpp | 85 ++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 testApp/pv/testOperators.cpp diff --git a/pvDataApp/pv/pvData.h b/pvDataApp/pv/pvData.h index 364ee32..4f15742 100644 --- a/pvDataApp/pv/pvData.h +++ b/pvDataApp/pv/pvData.h @@ -423,6 +423,20 @@ public: return o << get(); } + // get operator + // double value; doubleField >>= value; + void operator>>=(T& value) const + { + value = get(); + } + + // put operator + // double value = 12.8; doubleField <<= value; + void operator<<=(T value) + { + put(value); + } + protected: PVScalarValue(ScalarConstPtr const & scalar) : PVScalar(scalar) {} diff --git a/testApp/pv/Makefile b/testApp/pv/Makefile index 7893a3e..558e4c0 100644 --- a/testApp/pv/Makefile +++ b/testApp/pv/Makefile @@ -42,6 +42,10 @@ PROD_HOST += testPVStructureArray testPVStructureArray_SRCS += testPVStructureArray.cpp testPVStructureArray_LIBS += pvData Com +PROD_HOST += testOperators +testOperators_SRCS += testOperators.cpp +testOperators_LIBS += pvData Com + include $(TOP)/configure/RULES #---------------------------------------- # ADD RULES AFTER THIS LINE diff --git a/testApp/pv/testOperators.cpp b/testApp/pv/testOperators.cpp new file mode 100644 index 0000000..07e4a8c --- /dev/null +++ b/testApp/pv/testOperators.cpp @@ -0,0 +1,85 @@ +/* testOperators.cpp */ +/** + * Copyright - See the COPYRIGHT that is included with this distribution. + * EPICS pvData is distributed subject to a Software License Agreement found + * in file LICENSE that is included with this distribution. + */ +/* Author: Matej Sekoranja Date: 2013.02 */ + +#include + +#include +#include +#include + +#include + +using namespace epics::pvData; + +static PVDataCreatePtr pvDataCreate = getPVDataCreate(); +static StandardFieldPtr standardField = getStandardField(); +static StandardPVFieldPtr standardPVField = getStandardPVField(); + +int main(int, char*) +{ + PVStructurePtr pvStructure = standardPVField->scalar(pvDouble, + "alarm,timeStamp,display,control,valueAlarm"); + + const double testDV = 12.8; + + PVDoublePtr pvValue = pvStructure->getDoubleField("value"); + *pvValue <<= testDV; + + double dv; + *pvValue >>= dv; + assert(testDV == dv); + + + const std::string testSV = "test message"; + + PVStringPtr pvMessage = pvStructure->getStringField("alarm.message"); + *pvMessage <<= testSV; + + std::string sv; + *pvMessage >>= sv; + assert(testSV == sv); + + // + // to stream tests + // + + std::cout << *pvValue << std::endl; + std::cout << *pvMessage << std::endl; + std::cout << *pvStructure << std::endl; + + + StringArray choices; + choices.reserve(3); + choices.push_back("one"); + choices.push_back("two"); + choices.push_back("three"); + pvStructure = standardPVField->enumerated(choices, "alarm,timeStamp,valueAlarm"); + std::cout << *pvStructure << std::endl; + + + + pvStructure = standardPVField->scalarArray(pvBoolean,"alarm,timeStamp"); + std::cout << *pvStructure << std::endl; + + + StructureConstPtr structure = standardField->scalar(pvDouble, "alarm,timeStamp"); + pvStructure = standardPVField->structureArray(structure,"alarm,timeStamp"); + size_t num = 2; + PVStructurePtrArray pvStructures; + pvStructures.reserve(num); + for(size_t i=0; icreatePVStructure(structure)); + } + PVStructureArrayPtr pvStructureArray = pvStructure->getStructureArrayField("value"); + pvStructureArray->put(0, num, pvStructures, 0); + std::cout << *pvStructure << std::endl; + + return 0; +} +