From 3dae9f87286a95e9cf2107cb27dd1e9850296c76 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Tue, 8 Feb 2011 13:28:03 -0500 Subject: [PATCH] factory: templates for BasePV* implementations --- pvDataApp/factory/DefaultPVBoolean.cpp | 67 --------------- pvDataApp/factory/DefaultPVByte.cpp | 66 -------------- pvDataApp/factory/DefaultPVDouble.cpp | 66 -------------- pvDataApp/factory/DefaultPVFloat.cpp | 66 -------------- pvDataApp/factory/DefaultPVInt.cpp | 66 -------------- pvDataApp/factory/DefaultPVLong.cpp | 66 -------------- pvDataApp/factory/DefaultPVShort.cpp | 66 -------------- pvDataApp/factory/DefaultPVString.cpp | 65 -------------- pvDataApp/factory/PVDataCreateFactory.cpp | 100 ++++++++++++++++++++-- 9 files changed, 93 insertions(+), 535 deletions(-) delete mode 100644 pvDataApp/factory/DefaultPVBoolean.cpp delete mode 100644 pvDataApp/factory/DefaultPVByte.cpp delete mode 100644 pvDataApp/factory/DefaultPVDouble.cpp delete mode 100644 pvDataApp/factory/DefaultPVFloat.cpp delete mode 100644 pvDataApp/factory/DefaultPVInt.cpp delete mode 100644 pvDataApp/factory/DefaultPVLong.cpp delete mode 100644 pvDataApp/factory/DefaultPVShort.cpp delete mode 100644 pvDataApp/factory/DefaultPVString.cpp diff --git a/pvDataApp/factory/DefaultPVBoolean.cpp b/pvDataApp/factory/DefaultPVBoolean.cpp deleted file mode 100644 index 81fb00c..0000000 --- a/pvDataApp/factory/DefaultPVBoolean.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/*PVBoolean.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 -#include -#include -#include -#include "pvData.h" -#include "convert.h" -#include "factory.h" -#include "byteBuffer.h" - -namespace epics { namespace pvData { - - class BasePVBoolean : public PVBoolean { - public: - BasePVBoolean(PVStructure *parent,ScalarConstPtr scalar); - virtual ~BasePVBoolean(); - virtual bool get(); - virtual void put(bool val); - virtual void serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher); - virtual void deserialize(ByteBuffer *pbuffer, - DeserializableControl *pflusher); - virtual bool operator==(PVField& pv) ; - virtual bool operator!=(PVField& pv) ; - private: - bool value; - }; - - BasePVBoolean::BasePVBoolean(PVStructure *parent,ScalarConstPtr scalar) - : PVBoolean(parent,scalar),value(false) - {} - - BasePVBoolean::~BasePVBoolean() {} - - bool BasePVBoolean::get() { return value;} - - void BasePVBoolean::put(bool val){value = val;} - - void BasePVBoolean::serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher) { - pflusher->ensureBuffer(1); - pbuffer->putBoolean(value); - } - - void BasePVBoolean::deserialize(ByteBuffer *pbuffer, - DeserializableControl *pflusher) - { - pflusher->ensureData(1); - value = pbuffer->getBoolean(); - } - - bool BasePVBoolean::operator==(PVField& pvField) - { - return getConvert()->equals(this, &pvField); - } - - bool BasePVBoolean::operator!=(PVField& pvField) - { - return !(getConvert()->equals(this, &pvField)); - } - -}} diff --git a/pvDataApp/factory/DefaultPVByte.cpp b/pvDataApp/factory/DefaultPVByte.cpp deleted file mode 100644 index 0e54942..0000000 --- a/pvDataApp/factory/DefaultPVByte.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/*PVByte.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 -#include -#include -#include -#include "pvData.h" -#include "convert.h" -#include "factory.h" -#include "byteBuffer.h" - -namespace epics { namespace pvData { - - class BasePVByte : public PVByte { - public: - BasePVByte(PVStructure *parent,ScalarConstPtr scalar); - virtual ~BasePVByte(); - virtual int8 get(); - virtual void put(int8 val); - virtual void serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher) ; - virtual void deserialize(ByteBuffer *pbuffer, - DeserializableControl *pflusher); - virtual bool operator==(PVField& pv) ; - virtual bool operator!=(PVField& pv) ; - private: - int8 value; - }; - - BasePVByte::BasePVByte(PVStructure *parent,ScalarConstPtr scalar) - : PVByte(parent,scalar),value(0) - {} - - BasePVByte::~BasePVByte() {} - - int8 BasePVByte::get() { return value;} - - void BasePVByte::put(int8 val){value = val;} - - void BasePVByte::serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher) { - pflusher->ensureBuffer(1); - pbuffer->putByte(value); - } - - void BasePVByte::deserialize(ByteBuffer *pbuffer, - DeserializableControl *pflusher) { - pflusher->ensureData(1); - value = pbuffer->getByte(); - } - - bool BasePVByte::operator==(PVField& pvField) - { - return getConvert()->equals(this, &pvField); - } - - bool BasePVByte::operator!=(PVField& pvField) - { - return !(getConvert()->equals(this, &pvField)); - } - -}} diff --git a/pvDataApp/factory/DefaultPVDouble.cpp b/pvDataApp/factory/DefaultPVDouble.cpp deleted file mode 100644 index 153c573..0000000 --- a/pvDataApp/factory/DefaultPVDouble.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/*BasePVDouble.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. - */ -#include -#include -#include -#include -#include "pvData.h" -#include "convert.h" -#include "factory.h" -#include "byteBuffer.h" - -namespace epics { namespace pvData { - - class BasePVDouble : public PVDouble { - public: - BasePVDouble(PVStructure *parent,ScalarConstPtr scalar); - virtual ~BasePVDouble(); - virtual double get(); - virtual void put(double val); - virtual void serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher) ; - virtual void deserialize(ByteBuffer *pbuffer, - DeserializableControl *pflusher); - virtual bool operator==(PVField& pv) ; - virtual bool operator!=(PVField& pv) ; - private: - double value; - }; - - BasePVDouble::BasePVDouble(PVStructure *parent,ScalarConstPtr scalar) - : PVDouble(parent,scalar),value(0.0) - {} - - BasePVDouble::~BasePVDouble() {} - - double BasePVDouble::get() { return value;} - - void BasePVDouble::put(double val){value = val;} - - void BasePVDouble::serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher) { - pflusher->ensureBuffer(sizeof(double)); - pbuffer->putDouble(value); - } - - void BasePVDouble::deserialize(ByteBuffer *pbuffer, - DeserializableControl *pflusher) { - pflusher->ensureData(sizeof(double)); - value = pbuffer->getDouble(); - } - - bool BasePVDouble::operator==(PVField& pvField) - { - return getConvert()->equals(this, &pvField); - } - - bool BasePVDouble::operator!=(PVField& pvField) - { - return !(getConvert()->equals(this, &pvField)); - } - -}} diff --git a/pvDataApp/factory/DefaultPVFloat.cpp b/pvDataApp/factory/DefaultPVFloat.cpp deleted file mode 100644 index 92c2b91..0000000 --- a/pvDataApp/factory/DefaultPVFloat.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/*PVFloat.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 -#include -#include -#include -#include "pvData.h" -#include "convert.h" -#include "factory.h" -#include "byteBuffer.h" - -namespace epics { namespace pvData { - - class BasePVFloat : public PVFloat { - public: - BasePVFloat(PVStructure *parent,ScalarConstPtr scalar); - virtual ~BasePVFloat(); - virtual float get(); - virtual void put(float val); - virtual void serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher) ; - virtual void deserialize(ByteBuffer *pbuffer, - DeserializableControl *pflusher); - virtual bool operator==(PVField& pv) ; - virtual bool operator!=(PVField& pv) ; - private: - float value; - }; - - BasePVFloat::BasePVFloat(PVStructure *parent,ScalarConstPtr scalar) - : PVFloat(parent,scalar),value(0.0) - {} - - BasePVFloat::~BasePVFloat() {} - - float BasePVFloat::get() { return value;} - - void BasePVFloat::put(float val){value = val;} - - void BasePVFloat::serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher) { - pflusher->ensureBuffer(sizeof(float)); - pbuffer->putFloat(value); - } - - void BasePVFloat::deserialize(ByteBuffer *pbuffer, - DeserializableControl *pflusher) { - pflusher->ensureData(sizeof(float)); - value = pbuffer->getFloat(); - } - - bool BasePVFloat::operator==(PVField& pvField) - { - return getConvert()->equals(this, &pvField); - } - - bool BasePVFloat::operator!=(PVField& pvField) - { - return !(getConvert()->equals(this, &pvField)); - } - -}} diff --git a/pvDataApp/factory/DefaultPVInt.cpp b/pvDataApp/factory/DefaultPVInt.cpp deleted file mode 100644 index 00fc048..0000000 --- a/pvDataApp/factory/DefaultPVInt.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/*PVInt.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 -#include -#include -#include -#include "pvData.h" -#include "convert.h" -#include "factory.h" -#include "byteBuffer.h" - -namespace epics { namespace pvData { - - class BasePVInt : public PVInt { - public: - BasePVInt(PVStructure *parent,ScalarConstPtr scalar); - virtual ~BasePVInt(); - virtual int32 get(); - virtual void put(int32 val); - virtual void serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher) ; - virtual void deserialize(ByteBuffer *pbuffer, - DeserializableControl *pflusher); - virtual bool operator==(PVField& pv) ; - virtual bool operator!=(PVField& pv) ; - private: - int32 value; - }; - - BasePVInt::BasePVInt(PVStructure *parent,ScalarConstPtr scalar) - : PVInt(parent,scalar),value(0) - {} - - BasePVInt::~BasePVInt() {} - - int32 BasePVInt::get() { return value;} - - void BasePVInt::put(int32 val){value = val;} - - void BasePVInt::serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher) { - pflusher->ensureBuffer(sizeof(int32)); - pbuffer->putInt(value); - } - - void BasePVInt::deserialize(ByteBuffer *pbuffer, - DeserializableControl *pflusher) { - pflusher->ensureData(sizeof(int32)); - value = pbuffer->getInt(); - } - - bool BasePVInt::operator==(PVField& pvField) - { - return getConvert()->equals(this, &pvField); - } - - bool BasePVInt::operator!=(PVField& pvField) - { - return !(getConvert()->equals(this, &pvField)); - } - -}} diff --git a/pvDataApp/factory/DefaultPVLong.cpp b/pvDataApp/factory/DefaultPVLong.cpp deleted file mode 100644 index ddff999..0000000 --- a/pvDataApp/factory/DefaultPVLong.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/*PVLong.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 -#include -#include -#include -#include "pvData.h" -#include "convert.h" -#include "factory.h" -#include "byteBuffer.h" - -namespace epics { namespace pvData { - - class BasePVLong : public PVLong { - public: - BasePVLong(PVStructure *parent,ScalarConstPtr scalar); - virtual ~BasePVLong(); - virtual int64 get(); - virtual void put(int64 val); - virtual void serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher) ; - virtual void deserialize(ByteBuffer *pbuffer, - DeserializableControl *pflusher); - virtual bool operator==(PVField& pv) ; - virtual bool operator!=(PVField& pv) ; - private: - int64 value; - }; - - BasePVLong::BasePVLong(PVStructure *parent,ScalarConstPtr scalar) - : PVLong(parent,scalar),value(0) - {} - - BasePVLong::~BasePVLong() {} - - int64 BasePVLong::get() { return value;} - - void BasePVLong::put(int64 val){value = val;} - - void BasePVLong::serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher) { - pflusher->ensureBuffer(sizeof(int64)); - pbuffer->putLong(value); - } - - void BasePVLong::deserialize(ByteBuffer *pbuffer, - DeserializableControl *pflusher) { - pflusher->ensureData(sizeof(int64)); - value = pbuffer->getLong(); - } - - bool BasePVLong::operator==(PVField& pvField) - { - return getConvert()->equals(this, &pvField); - } - - bool BasePVLong::operator!=(PVField& pvField) - { - return !(getConvert()->equals(this, &pvField)); - } - -}} diff --git a/pvDataApp/factory/DefaultPVShort.cpp b/pvDataApp/factory/DefaultPVShort.cpp deleted file mode 100644 index 8662283..0000000 --- a/pvDataApp/factory/DefaultPVShort.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/*PVShort.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 -#include -#include -#include -#include "pvData.h" -#include "convert.h" -#include "factory.h" -#include "byteBuffer.h" - -namespace epics { namespace pvData { - - class BasePVShort : public PVShort { - public: - BasePVShort(PVStructure *parent,ScalarConstPtr scalar); - virtual ~BasePVShort(); - virtual int16 get(); - virtual void put(int16 val); - virtual void serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher) ; - virtual void deserialize(ByteBuffer *pbuffer, - DeserializableControl *pflusher); - virtual bool operator==(PVField& pv) ; - virtual bool operator!=(PVField& pv) ; - private: - int16 value; - }; - - BasePVShort::BasePVShort(PVStructure *parent,ScalarConstPtr scalar) - : PVShort(parent,scalar),value(0) - {} - - BasePVShort::~BasePVShort() {} - - int16 BasePVShort::get() { return value;} - - void BasePVShort::put(int16 val){value = val;} - - void BasePVShort::serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher) { - pflusher->ensureBuffer(sizeof(int16)); - pbuffer->putShort(value); - } - - void BasePVShort::deserialize(ByteBuffer *pbuffer, - DeserializableControl *pflusher) { - pflusher->ensureData(sizeof(int16)); - value = pbuffer->getShort(); - } - - bool BasePVShort::operator==(PVField& pvField) - { - return getConvert()->equals(this, &pvField); - } - - bool BasePVShort::operator!=(PVField& pvField) - { - return !(getConvert()->equals(this, &pvField)); - } - -}} diff --git a/pvDataApp/factory/DefaultPVString.cpp b/pvDataApp/factory/DefaultPVString.cpp deleted file mode 100644 index 5b30ff9..0000000 --- a/pvDataApp/factory/DefaultPVString.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/*PVString.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 -#include -#include -#include -#include "pvData.h" -#include "convert.h" -#include "factory.h" -#include "byteBuffer.h" -#include "serializeHelper.h" - -namespace epics { namespace pvData { - - class BasePVString : public PVString { - public: - BasePVString(PVStructure *parent,ScalarConstPtr scalar); - virtual ~BasePVString(); - virtual String get(); - virtual void put(String val); - virtual void serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher) ; - virtual void deserialize(ByteBuffer *pbuffer, - DeserializableControl *pflusher); - virtual bool operator==(PVField& pv) ; - virtual bool operator!=(PVField& pv) ; - private: - String value; - }; - - BasePVString::BasePVString(PVStructure *parent,ScalarConstPtr scalar) - : PVString(parent,scalar),value("") - {} - - BasePVString::~BasePVString() {} - - String BasePVString::get() { return value;} - - void BasePVString::put(String val){value = val;} - - void BasePVString::serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher) { - SerializeHelper::serializeString(value, pbuffer, pflusher); - } - - void BasePVString::deserialize(ByteBuffer *pbuffer, - DeserializableControl *pflusher) { - value = SerializeHelper::deserializeString(pbuffer, pflusher); - } - - bool BasePVString::operator==(PVField& pvField) - { - return getConvert()->equals(this, &pvField); - } - - bool BasePVString::operator!=(PVField& pvField) - { - return !(getConvert()->equals(this, &pvField)); - } - -}} diff --git a/pvDataApp/factory/PVDataCreateFactory.cpp b/pvDataApp/factory/PVDataCreateFactory.cpp index 40aab9c..b00aa68 100644 --- a/pvDataApp/factory/PVDataCreateFactory.cpp +++ b/pvDataApp/factory/PVDataCreateFactory.cpp @@ -18,13 +18,6 @@ #include "PVArray.cpp" #include "PVScalarArray.cpp" #include "PVStructure.cpp" -#include "DefaultPVBoolean.cpp" -#include "DefaultPVByte.cpp" -#include "DefaultPVShort.cpp" -#include "DefaultPVInt.cpp" -#include "DefaultPVLong.cpp" -#include "DefaultPVFloat.cpp" -#include "DefaultPVDouble.cpp" #include "DefaultPVString.cpp" #include "DefaultPVBooleanArray.cpp" #include "DefaultPVByteArray.cpp" @@ -42,6 +35,99 @@ static Convert* convert = 0; static FieldCreate * fieldCreate = 0; static PVDataCreate* pvDataCreate = 0; +/** Default storage for scalar values + */ +template +class BasePVScalar : public PVScalarValue { +public: + typedef T value_type; + typedef T* pointer; + typedef const T* const_pointer; + + BasePVScalar(PVStructure *parent,ScalarConstPtr scalar); + virtual ~BasePVScalar(); + virtual T get(); + virtual void put(T val); + virtual void serialize(ByteBuffer *pbuffer, + SerializableControl *pflusher); + virtual void deserialize(ByteBuffer *pbuffer, + DeserializableControl *pflusher); + virtual bool operator==(PVField& pv) ; + virtual bool operator!=(PVField& pv) ; +private: + T value; +}; + +template +BasePVScalar::BasePVScalar(PVStructure *parent,ScalarConstPtr scalar) + : PVScalarValue(parent,scalar),value(0) +{} +//Note: '0' is a suitable default for all POD types (not String) + +template +BasePVScalar::~BasePVScalar() {} + +template +T BasePVScalar::get() { return value;} + +template +void BasePVScalar::put(T val){value = val;} + +template +void BasePVScalar::serialize(ByteBuffer *pbuffer, + SerializableControl *pflusher) { + pflusher->ensureBuffer(1); + pbuffer->putBoolean(value); +} + +template +void BasePVScalar::deserialize(ByteBuffer *pbuffer, + DeserializableControl *pflusher) +{ + pflusher->ensureData(1); + value = pbuffer->getBoolean(); +} + +template +bool BasePVScalar::operator==(PVField& pvField) +{ + return getConvert()->equals(this, &pvField); +} + +template +bool BasePVScalar::operator!=(PVField& pvField) +{ + return !(getConvert()->equals(this, &pvField)); +} + +// Specializations for scalar String + +template<> +BasePVScalar::BasePVScalar(PVStructure *parent,ScalarConstPtr scalar) +: PVScalarValue(parent,scalar),value() +{} + +template<> +void BasePVScalar::serialize(ByteBuffer *pbuffer, + SerializableControl *pflusher) { + SerializeHelper::serializeString(value, pbuffer, pflusher); +} + +template<> +void BasePVScalar::deserialize(ByteBuffer *pbuffer, + DeserializableControl *pflusher) { + value = SerializeHelper::deserializeString(pbuffer, pflusher); +} + +typedef BasePVScalar BasePVBoolean; +typedef BasePVScalar BasePVByte; +typedef BasePVScalar BasePVShort; +typedef BasePVScalar BasePVInt; +typedef BasePVScalar BasePVLong; +typedef BasePVScalar BasePVFloat; +typedef BasePVScalar BasePVDouble; +typedef BasePVScalar BasePVString; + PVDataCreate::PVDataCreate(){ } PVField *PVDataCreate::createPVField(PVStructure *parent,