From 890c72bad40cd38343e5b6d58c83c38143a2b735 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*Array implementations --- pvDataApp/factory/DefaultPVBooleanArray.cpp | 182 --------------- pvDataApp/factory/DefaultPVByteArray.cpp | 182 --------------- pvDataApp/factory/DefaultPVDoubleArray.cpp | 185 --------------- pvDataApp/factory/DefaultPVFloatArray.cpp | 185 --------------- pvDataApp/factory/DefaultPVIntArray.cpp | 185 --------------- pvDataApp/factory/DefaultPVLongArray.cpp | 185 --------------- pvDataApp/factory/DefaultPVShortArray.cpp | 185 --------------- pvDataApp/factory/DefaultPVStringArray.cpp | 165 ------------- pvDataApp/factory/PVDataCreateFactory.cpp | 244 +++++++++++++++++++- 9 files changed, 235 insertions(+), 1463 deletions(-) delete mode 100644 pvDataApp/factory/DefaultPVBooleanArray.cpp delete mode 100644 pvDataApp/factory/DefaultPVByteArray.cpp delete mode 100644 pvDataApp/factory/DefaultPVDoubleArray.cpp delete mode 100644 pvDataApp/factory/DefaultPVFloatArray.cpp delete mode 100644 pvDataApp/factory/DefaultPVIntArray.cpp delete mode 100644 pvDataApp/factory/DefaultPVLongArray.cpp delete mode 100644 pvDataApp/factory/DefaultPVShortArray.cpp delete mode 100644 pvDataApp/factory/DefaultPVStringArray.cpp diff --git a/pvDataApp/factory/DefaultPVBooleanArray.cpp b/pvDataApp/factory/DefaultPVBooleanArray.cpp deleted file mode 100644 index 1883a10..0000000 --- a/pvDataApp/factory/DefaultPVBooleanArray.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/*PVBooleanArrray.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 "factory.h" -#include "serializeHelper.h" - -using std::min; - -namespace epics { namespace pvData { - - class DefaultPVBooleanArray : public PVBooleanArray { - public: - DefaultPVBooleanArray(PVStructure *parent,ScalarArrayConstPtr scalarArray); - virtual ~DefaultPVBooleanArray(); - virtual void setCapacity(int capacity); - virtual int get(int offset, int length, BooleanArrayData *data) ; - virtual int put(int offset,int length,BooleanArray from, - int fromOffset); - virtual void shareData(BooleanArray value,int capacity,int length); - // from Serializable - virtual void serialize(ByteBuffer *pbuffer,SerializableControl *pflusher) ; - virtual void deserialize(ByteBuffer *pbuffer,DeserializableControl *pflusher); - virtual void serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher, int offset, int count) ; - virtual bool operator==(PVField& pv) ; - virtual bool operator!=(PVField& pv) ; - private: - bool *value; - }; - - DefaultPVBooleanArray::DefaultPVBooleanArray(PVStructure *parent, - ScalarArrayConstPtr scalarArray) - : PVBooleanArray(parent,scalarArray),value(new bool[0]) - { } - - DefaultPVBooleanArray::~DefaultPVBooleanArray() - { - delete[] value; - } - - void DefaultPVBooleanArray::setCapacity(int capacity) - { - if(PVArray::getCapacity()==capacity) return; - if(!PVArray::isCapacityMutable()) { - std::string message("not capacityMutable"); - PVField::message(message, errorMessage); - return; - } - int length = PVArray::getLength(); - if(length>capacity) length = capacity; - bool *newValue = new bool[capacity]; - for(int i=0; i length) { - n = length-offset; - if(n<0) n = 0; - } - data->data = value; - data->offset = offset; - return n; - } - - int DefaultPVBooleanArray::put(int offset,int len, - BooleanArray from,int fromOffset) - { - if(PVField::isImmutable()) { - PVField::message("field is immutable",errorMessage); - return 0; - } - if(from==value) return len; - if(len<1) return 0; - int length = PVArray::getLength(); - int capacity = PVArray::getCapacity(); - if(offset+len > length) { - int newlength = offset + len; - if(newlength>capacity) { - setCapacity(newlength); - newlength = PVArray::getCapacity(); - len = newlength - offset; - if(len<=0) return 0; - } - length = newlength; - } - for(int i=0;i=0) { - // prepare array, if necessary - if(size>getCapacity()) setCapacity(size); - // retrieve value from the buffer - int i = 0; - while(true) { - int maxIndex = min(size-i, pbuffer->getRemaining())+i; - for(; igetBoolean(); - if(iensureData(1); // // TODO is there a better way to ensureData? - else - break; - } - // set new length - setLength(size); - postPut(); - } - // TODO null arrays (size == -1) not supported - } - - void DefaultPVBooleanArray::serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher, int offset, int count) { - // cache - int length = getLength(); - - // check bounds - if(offset<0) - offset = 0; - else if(offset>length) offset = length; - if(count<0) count = length; - - int maxCount = length-offset; - if(count>maxCount) count = maxCount; - - // write - SerializeHelper::writeSize(count, pbuffer, pflusher); - int end = offset+count; - int i = offset; - while(true) { - int maxIndex = min(end-i, pbuffer->getRemaining())+i; - for(; iputBoolean(value[i]); - if(iflushSerializeBuffer(); - else - break; - } - } - - bool DefaultPVBooleanArray::operator==(PVField& pv) - { - return getConvert()->equals(this, &pv); - } - - bool DefaultPVBooleanArray::operator!=(PVField& pv) - { - return !(getConvert()->equals(this, &pv)); - } -}} diff --git a/pvDataApp/factory/DefaultPVByteArray.cpp b/pvDataApp/factory/DefaultPVByteArray.cpp deleted file mode 100644 index f54efdb..0000000 --- a/pvDataApp/factory/DefaultPVByteArray.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/*PVByteArray.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 "factory.h" -#include "serializeHelper.h" - -using std::min; - -namespace epics { namespace pvData { - - class BasePVByteArray : public PVByteArray { - public: - BasePVByteArray(PVStructure *parent,ScalarArrayConstPtr scalarArray); - virtual ~BasePVByteArray(); - virtual void setCapacity(int capacity); - virtual int get(int offset, int length, ByteArrayData *data) ; - virtual int put(int offset,int length,ByteArray from, - int fromOffset); - virtual void shareData(ByteArray value,int capacity,int length); - // from Serializable - virtual void serialize(ByteBuffer *pbuffer,SerializableControl *pflusher) ; - virtual void deserialize(ByteBuffer *pbuffer,DeserializableControl *pflusher); - virtual void serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher, int offset, int count) ; - virtual bool operator==(PVField& pv) ; - virtual bool operator!=(PVField& pv) ; - private: - int8 *value; - }; - - BasePVByteArray::BasePVByteArray(PVStructure *parent, - ScalarArrayConstPtr scalarArray) - : PVByteArray(parent,scalarArray),value(new int8[0]) - { } - - BasePVByteArray::~BasePVByteArray() - { - delete[] value; - } - - void BasePVByteArray::setCapacity(int capacity) - { - if(PVArray::getCapacity()==capacity) return; - if(!PVArray::isCapacityMutable()) { - std::string message("not capacityMutable"); - PVField::message(message, errorMessage); - return; - } - int length = PVArray::getLength(); - if(length>capacity) length = capacity; - int8 *newValue = new int8[capacity]; - for(int i=0; i length) { - n = length-offset; - if(n<0) n = 0; - } - data->data = value; - data->offset = offset; - return n; - } - - int BasePVByteArray::put(int offset,int len, - ByteArray from,int fromOffset) - { - if(PVField::isImmutable()) { - PVField::message("field is immutable",errorMessage); - return 0; - } - if(from==value) return len; - if(len<1) return 0; - int length = PVArray::getLength(); - int capacity = PVArray::getCapacity(); - if(offset+len > length) { - int newlength = offset + len; - if(newlength>capacity) { - setCapacity(newlength); - newlength = PVArray::getCapacity(); - len = newlength - offset; - if(len<=0) return 0; - } - length = newlength; - } - for(int i=0;i=0) { - // prepare array, if necessary - if(size>getCapacity()) setCapacity(size); - // retrieve value from the buffer - int i = 0; - while(true) { - int toRead = min(size-i, pbuffer->getRemaining()); - pbuffer->get((char *)value, i, toRead); - i += toRead; - if(iensureData(1); // TODO: is there a better way to ensureData? - else - break; - } - // set new length - setLength(size); - postPut(); - } - // TODO null arrays (size == -1) not supported - } - - void BasePVByteArray::serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher, int offset, int count) { - // cache - int length = getLength(); - - // check bounds - if(offset<0) - offset = 0; - else if(offset>length) offset = length; - if(count<0) count = length; - - int maxCount = length-offset; - if(count>maxCount) count = maxCount; - - // write - SerializeHelper::writeSize(count, pbuffer, pflusher); - int end = offset+count; - int i = offset; - while(true) { - int maxIndex = min(end-i, pbuffer->getRemaining())+i; - for(; iputByte(value[i]); - if(iflushSerializeBuffer(); - else - break; - } - } - - bool BasePVByteArray::operator==(PVField& pv) - { - return getConvert()->equals(this, &pv); - } - - bool BasePVByteArray::operator!=(PVField& pv) - { - return !(getConvert()->equals(this, &pv)); - } -}} diff --git a/pvDataApp/factory/DefaultPVDoubleArray.cpp b/pvDataApp/factory/DefaultPVDoubleArray.cpp deleted file mode 100644 index f163c3e..0000000 --- a/pvDataApp/factory/DefaultPVDoubleArray.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/*PVDoubleArray.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 "factory.h" -#include "serializeHelper.h" - -using std::min; - -namespace epics { namespace pvData { - - class BasePVDoubleArray : public PVDoubleArray { - public: - BasePVDoubleArray(PVStructure *parent,ScalarArrayConstPtr scalarArray); - virtual ~BasePVDoubleArray(); - virtual void setCapacity(int capacity); - virtual int get(int offset, int length, DoubleArrayData *data) ; - virtual int put(int offset,int length,DoubleArray from, - int fromOffset); - virtual void shareData(double value[],int capacity,int length); - // from Serializable - virtual void serialize(ByteBuffer *pbuffer,SerializableControl *pflusher) ; - virtual void deserialize(ByteBuffer *pbuffer,DeserializableControl *pflusher); - virtual void serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher, int offset, int count) ; - virtual bool operator==(PVField& pv) ; - virtual bool operator!=(PVField& pv) ; - private: - double *value; - }; - - BasePVDoubleArray::BasePVDoubleArray(PVStructure *parent, - ScalarArrayConstPtr scalarArray) - : PVDoubleArray(parent,scalarArray),value(new double[0]) - { } - - BasePVDoubleArray::~BasePVDoubleArray() - { - delete[] value; - } - - void BasePVDoubleArray::setCapacity(int capacity) - { - if(getCapacity()==capacity) return; - if(!isCapacityMutable()) { - std::string message("not capacityMutable"); - PVField::message(message, errorMessage); - return; - } - int length = PVArray::getLength(); - if(length>capacity) length = capacity; - double *newValue = new double[capacity]; - for(int i=0; i length) { - n = length-offset; - if(n<0) n = 0; - } - data->data = value; - data->offset = offset; - return n; - } - - int BasePVDoubleArray::put(int offset,int len, - DoubleArray from,int fromOffset) - { - if(PVField::isImmutable()) { - PVField::message("field is immutable",errorMessage); - return 0; - } - if(from==value) return len; - if(len<1) return 0; - int length = PVArray::getLength(); - int capacity = PVArray::getCapacity(); - if(offset+len > length) { - int newlength = offset + len; - if(newlength>capacity) { - setCapacity(newlength); - newlength = PVArray::getCapacity(); - len = newlength - offset; - if(len<=0) return 0; - } - length = newlength; - } - for(int i=0;i=0) { - // prepare array, if necessary - if(size>getCapacity()) setCapacity(size); - // retrieve value from the buffer - int i = 0; - while(true) { - int maxIndex = min(size-i, (int)(pbuffer->getRemaining() - /sizeof(double)))+i; - for(; igetDouble(); - if(iensureData(sizeof(double)); - else - break; - } - // set new length - setLength(size); - postPut(); - } - // TODO null arrays (size == -1) not supported - } - - void BasePVDoubleArray::serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher, int offset, int count) { - // cache - int length = getLength(); - - // check bounds - if(offset<0) - offset = 0; - else if(offset>length) offset = length; - if(count<0) count = length; - - int maxCount = length-offset; - if(count>maxCount) count = maxCount; - - // write - SerializeHelper::writeSize(count, pbuffer, pflusher); - int end = offset+count; - int i = offset; - while(true) { - int maxIndex = min(end-i, (int)(pbuffer->getRemaining() - /sizeof(double)))+i; - for(; iputDouble(value[i]); - if(iflushSerializeBuffer(); - else - break; - } - } - - bool BasePVDoubleArray::operator==(PVField& pv) - { - return getConvert()->equals(this, &pv); - } - - bool BasePVDoubleArray::operator!=(PVField& pv) - { - return !(getConvert()->equals(this, &pv)); - } -}} diff --git a/pvDataApp/factory/DefaultPVFloatArray.cpp b/pvDataApp/factory/DefaultPVFloatArray.cpp deleted file mode 100644 index db9981a..0000000 --- a/pvDataApp/factory/DefaultPVFloatArray.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/*PVFloatArray.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 "factory.h" -#include "serializeHelper.h" - -namespace epics { namespace pvData { - - using std::min; - - class BasePVFloatArray : public PVFloatArray { - public: - BasePVFloatArray(PVStructure *parent,ScalarArrayConstPtr scalarArray); - virtual ~BasePVFloatArray(); - virtual void setCapacity(int capacity); - virtual int get(int offset, int length, FloatArrayData *data) ; - virtual int put(int offset,int length,FloatArray from, - int fromOffset); - virtual void shareData(float value[],int capacity,int length); - // from Serializable - virtual void serialize(ByteBuffer *pbuffer,SerializableControl *pflusher) ; - virtual void deserialize(ByteBuffer *pbuffer,DeserializableControl *pflusher); - virtual void serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher, int offset, int count) ; - virtual bool operator==(PVField& pv) ; - virtual bool operator!=(PVField& pv) ; - private: - float *value; - }; - - BasePVFloatArray::BasePVFloatArray(PVStructure *parent, - ScalarArrayConstPtr scalarArray) - : PVFloatArray(parent,scalarArray),value(new float[0]) - { } - - BasePVFloatArray::~BasePVFloatArray() - { - delete[] value; - } - - void BasePVFloatArray::setCapacity(int capacity) - { - if(PVArray::getCapacity()==capacity) return; - if(!PVArray::isCapacityMutable()) { - std::string message("not capacityMutable"); - PVField::message(message, errorMessage); - return; - } - int length = PVArray::getLength(); - if(length>capacity) length = capacity; - float *newValue = new float[capacity]; - for(int i=0; i length) { - n = length-offset; - if(n<0) n = 0; - } - data->data = value; - data->offset = offset; - return n; - } - - int BasePVFloatArray::put(int offset,int len, - FloatArray from,int fromOffset) - { - if(PVField::isImmutable()) { - PVField::message("field is immutable",errorMessage); - return 0; - } - if(from==value) return len; - if(len<1) return 0; - int length = PVArray::getLength(); - int capacity = PVArray::getCapacity(); - if(offset+len > length) { - int newlength = offset + len; - if(newlength>capacity) { - setCapacity(newlength); - newlength = PVArray::getCapacity(); - len = newlength - offset; - if(len<=0) return 0; - } - length = newlength; - } - for(int i=0;i=0) { - // prepare array, if necessary - if(size>getCapacity()) setCapacity(size); - // retrieve value from the buffer - int i = 0; - while(true) { - int maxIndex = min(size-i, (int)(pbuffer->getRemaining() - /sizeof(float)))+i; - for(; igetFloat(); - if(iensureData(sizeof(float)); // TODO: is there a better way to ensureData? - else - break; - } - // set new length - setLength(size); - postPut(); - } - // TODO null arrays (size == -1) not supported - } - - void BasePVFloatArray::serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher, int offset, int count) { - // cache - int length = getLength(); - - // check bounds - if(offset<0) - offset = 0; - else if(offset>length) offset = length; - if(count<0) count = length; - - int maxCount = length-offset; - if(count>maxCount) count = maxCount; - - // write - SerializeHelper::writeSize(count, pbuffer, pflusher); - int end = offset+count; - int i = offset; - while(true) { - int maxIndex = min(end-i, (int)(pbuffer->getRemaining() - /sizeof(float)))+i; - for(; iputFloat(value[i]); - if(iflushSerializeBuffer(); - else - break; - } - } - - bool BasePVFloatArray::operator==(PVField& pv) - { - return getConvert()->equals(this, &pv); - } - - bool BasePVFloatArray::operator!=(PVField& pv) - { - return !(getConvert()->equals(this, &pv)); - } -}} diff --git a/pvDataApp/factory/DefaultPVIntArray.cpp b/pvDataApp/factory/DefaultPVIntArray.cpp deleted file mode 100644 index e0befae..0000000 --- a/pvDataApp/factory/DefaultPVIntArray.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/*PVIntArray.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 "factory.h" -#include "serializeHelper.h" - -using std::min; - -namespace epics { namespace pvData { - - class BasePVIntArray : public PVIntArray { - public: - BasePVIntArray(PVStructure *parent,ScalarArrayConstPtr scalarArray); - virtual ~BasePVIntArray(); - virtual void setCapacity(int capacity); - virtual int get(int offset, int length, IntArrayData *data) ; - virtual int put(int offset,int length,IntArray from, - int fromOffset); - virtual void shareData(int32 value[],int capacity,int length); - // from Serializable - virtual void serialize(ByteBuffer *pbuffer,SerializableControl *pflusher) ; - virtual void deserialize(ByteBuffer *pbuffer,DeserializableControl *pflusher); - virtual void serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher, int offset, int count) ; - virtual bool operator==(PVField& pv) ; - virtual bool operator!=(PVField& pv) ; - private: - int32 *value; - }; - - BasePVIntArray::BasePVIntArray(PVStructure *parent, - ScalarArrayConstPtr scalarArray) - : PVIntArray(parent,scalarArray),value(new int32[0]) - { } - - BasePVIntArray::~BasePVIntArray() - { - delete[] value; - } - - void BasePVIntArray::setCapacity(int capacity) - { - if(PVArray::getCapacity()==capacity) return; - if(!PVArray::isCapacityMutable()) { - std::string message("not capacityMutable"); - PVField::message(message, errorMessage); - return; - } - int length = PVArray::getLength(); - if(length>capacity) length = capacity; - int32 *newValue = new int32[capacity]; - for(int i=0; i length) { - n = length-offset; - if(n<0) n = 0; - } - data->data = value; - data->offset = offset; - return n; - } - - int BasePVIntArray::put(int offset,int len, - IntArray from,int fromOffset) - { - if(PVField::isImmutable()) { - PVField::message("field is immutable",errorMessage); - return 0; - } - if(from==value) return len; - if(len<1) return 0; - int length = PVArray::getLength(); - int capacity = PVArray::getCapacity(); - if(offset+len > length) { - int newlength = offset + len; - if(newlength>capacity) { - setCapacity(newlength); - newlength = PVArray::getCapacity(); - len = newlength - offset; - if(len<=0) return 0; - } - length = newlength; - } - for(int i=0;i=0) { - // prepare array, if necessary - if(size>getCapacity()) setCapacity(size); - // retrieve value from the buffer - int i = 0; - while(true) { - int maxIndex = min(size-i, (int)(pbuffer->getRemaining() - /sizeof(int32)))+i; - for(; igetInt(); - if(iensureData(sizeof(int32)); // TODO: is there a better way to ensureData? - else - break; - } - // set new length - setLength(size); - postPut(); - } - // TODO null arrays (size == -1) not supported - } - - void BasePVIntArray::serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher, int offset, int count) { - // cache - int length = getLength(); - - // check bounds - if(offset<0) - offset = 0; - else if(offset>length) offset = length; - if(count<0) count = length; - - int maxCount = length-offset; - if(count>maxCount) count = maxCount; - - // write - SerializeHelper::writeSize(count, pbuffer, pflusher); - int end = offset+count; - int i = offset; - while(true) { - int maxIndex = min(end-i, (int)(pbuffer->getRemaining() - /sizeof(int32)))+i; - for(; iputInt(value[i]); - if(iflushSerializeBuffer(); - else - break; - } - } - - bool BasePVIntArray::operator==(PVField& pv) - { - return getConvert()->equals(this, &pv); - } - - bool BasePVIntArray::operator!=(PVField& pv) - { - return !(getConvert()->equals(this, &pv)); - } -}} diff --git a/pvDataApp/factory/DefaultPVLongArray.cpp b/pvDataApp/factory/DefaultPVLongArray.cpp deleted file mode 100644 index 4da1410..0000000 --- a/pvDataApp/factory/DefaultPVLongArray.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/*PVLongArray.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 "factory.h" -#include "serializeHelper.h" - -using std::min; - -namespace epics { namespace pvData { - - class BasePVLongArray : public PVLongArray { - public: - BasePVLongArray(PVStructure *parent,ScalarArrayConstPtr scalarArray); - virtual ~BasePVLongArray(); - virtual void setCapacity(int capacity); - virtual int get(int offset, int length, LongArrayData *data) ; - virtual int put(int offset,int length,LongArray from, - int fromOffset); - virtual void shareData(int64 value[],int capacity,int length); - // from Serializable - virtual void serialize(ByteBuffer *pbuffer,SerializableControl *pflusher) ; - virtual void deserialize(ByteBuffer *pbuffer,DeserializableControl *pflusher); - virtual void serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher, int offset, int count) ; - virtual bool operator==(PVField& pv) ; - virtual bool operator!=(PVField& pv) ; - private: - int64 *value; - }; - - BasePVLongArray::BasePVLongArray(PVStructure *parent, - ScalarArrayConstPtr scalarArray) - : PVLongArray(parent,scalarArray),value(new int64[0]) - { } - - BasePVLongArray::~BasePVLongArray() - { - delete[] value; - } - - void BasePVLongArray::setCapacity(int capacity) - { - if(PVArray::getCapacity()==capacity) return; - if(!PVArray::isCapacityMutable()) { - std::string message("not capacityMutable"); - PVField::message(message, errorMessage); - return; - } - int length = PVArray::getLength(); - if(length>capacity) length = capacity; - int64 *newValue = new int64[capacity]; - for(int i=0; i length) { - n = length-offset; - if(n<0) n = 0; - } - data->data = value; - data->offset = offset; - return n; - } - - int BasePVLongArray::put(int offset,int len, - LongArray from,int fromOffset) - { - if(PVField::isImmutable()) { - PVField::message("field is immutable",errorMessage); - return 0; - } - if(from==value) return len; - if(len<1) return 0; - int length = PVArray::getLength(); - int capacity = PVArray::getCapacity(); - if(offset+len > length) { - int newlength = offset + len; - if(newlength>capacity) { - setCapacity(newlength); - newlength = PVArray::getCapacity(); - len = newlength - offset; - if(len<=0) return 0; - } - length = newlength; - } - for(int i=0;i=0) { - // prepare array, if necessary - if(size>getCapacity()) setCapacity(size); - // retrieve value from the buffer - int i = 0; - while(true) { - int maxIndex = min(size-i, (int)(pbuffer->getRemaining() - /sizeof(int64)))+i; - for(; igetLong(); - if(iensureData(sizeof(int64)); // TODO: is there a better way to ensureData? - else - break; - } - // set new length - setLength(size); - postPut(); - } - // TODO null arrays (size == -1) not supported - } - - void BasePVLongArray::serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher, int offset, int count) { - // cache - int length = getLength(); - - // check bounds - if(offset<0) - offset = 0; - else if(offset>length) offset = length; - if(count<0) count = length; - - int maxCount = length-offset; - if(count>maxCount) count = maxCount; - - // write - SerializeHelper::writeSize(count, pbuffer, pflusher); - int end = offset+count; - int i = offset; - while(true) { - int maxIndex = min(end-i, (int)(pbuffer->getRemaining() - /sizeof(int64)))+i; - for(; iputLong(value[i]); - if(iflushSerializeBuffer(); - else - break; - } - } - - bool BasePVLongArray::operator==(PVField& pv) - { - return getConvert()->equals(this, &pv); - } - - bool BasePVLongArray::operator!=(PVField& pv) - { - return !(getConvert()->equals(this, &pv)); - } -}} diff --git a/pvDataApp/factory/DefaultPVShortArray.cpp b/pvDataApp/factory/DefaultPVShortArray.cpp deleted file mode 100644 index 602b2cf..0000000 --- a/pvDataApp/factory/DefaultPVShortArray.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/*PVShortArray.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 "factory.h" -#include "serializeHelper.h" - -using std::min; - -namespace epics { namespace pvData { - - class BasePVShortArray : public PVShortArray { - public: - BasePVShortArray(PVStructure *parent,ScalarArrayConstPtr scalarArray); - virtual ~BasePVShortArray(); - virtual void setCapacity(int capacity); - virtual int get(int offset, int length, ShortArrayData *data) ; - virtual int put(int offset,int length,ShortArray from, - int fromOffset); - virtual void shareData(int16 value[],int capacity,int length); - // from Serializable - virtual void serialize(ByteBuffer *pbuffer,SerializableControl *pflusher) ; - virtual void deserialize(ByteBuffer *pbuffer,DeserializableControl *pflusher); - virtual void serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher, int offset, int count) ; - virtual bool operator==(PVField& pv) ; - virtual bool operator!=(PVField& pv) ; - private: - int16 *value; - }; - - BasePVShortArray::BasePVShortArray(PVStructure *parent, - ScalarArrayConstPtr scalarArray) - : PVShortArray(parent,scalarArray),value(new int16[0]) - { } - - BasePVShortArray::~BasePVShortArray() - { - delete[] value; - } - - void BasePVShortArray::setCapacity(int capacity) - { - if(PVArray::getCapacity()==capacity) return; - if(!PVArray::isCapacityMutable()) { - std::string message("not capacityMutable"); - PVField::message(message, errorMessage); - return; - } - int length = PVArray::getLength(); - if(length>capacity) length = capacity; - int16 *newValue = new int16[capacity]; - for(int i=0; i length) { - n = length-offset; - if(n<0) n = 0; - } - data->data = value; - data->offset = offset; - return n; - } - - int BasePVShortArray::put(int offset,int len, - ShortArray from,int fromOffset) - { - if(PVField::isImmutable()) { - PVField::message("field is immutable",errorMessage); - return 0; - } - if(from==value) return len; - if(len<1) return 0; - int length = PVArray::getLength(); - int capacity = PVArray::getCapacity(); - if(offset+len > length) { - int newlength = offset + len; - if(newlength>capacity) { - setCapacity(newlength); - newlength = PVArray::getCapacity(); - len = newlength - offset; - if(len<=0) return 0; - } - length = newlength; - } - for(int i=0;i=0) { - // prepare array, if necessary - if(size>getCapacity()) setCapacity(size); - // retrieve value from the buffer - int i = 0; - while(true) { - int maxIndex = min(size-i, (int)(pbuffer->getRemaining() - /sizeof(int16)))+i; - for(; igetShort(); - if(iensureData(sizeof(int16)); // TODO: is there a better way to ensureData? - else - break; - } - // set new length - setLength(size); - postPut(); - } - // TODO null arrays (size == -1) not supported - } - - void BasePVShortArray::serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher, int offset, int count) { - // cache - int length = getLength(); - - // check bounds - if(offset<0) - offset = 0; - else if(offset>length) offset = length; - if(count<0) count = length; - - int maxCount = length-offset; - if(count>maxCount) count = maxCount; - - // write - SerializeHelper::writeSize(count, pbuffer, pflusher); - int end = offset+count; - int i = offset; - while(true) { - int maxIndex = min(end-i, (int)(pbuffer->getRemaining() - /sizeof(int16)))+i; - for(; iputShort(value[i]); - if(iflushSerializeBuffer(); - else - break; - } - } - - bool BasePVShortArray::operator==(PVField& pv) - { - return getConvert()->equals(this, &pv); - } - - bool BasePVShortArray::operator!=(PVField& pv) - { - return !(getConvert()->equals(this, &pv)); - } -}} diff --git a/pvDataApp/factory/DefaultPVStringArray.cpp b/pvDataApp/factory/DefaultPVStringArray.cpp deleted file mode 100644 index 774a6ba..0000000 --- a/pvDataApp/factory/DefaultPVStringArray.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/*PVStringArray.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 "factory.h" -#include "serializeHelper.h" - -namespace epics { namespace pvData { - - class BasePVStringArray : public PVStringArray { - public: - BasePVStringArray(PVStructure *parent,ScalarArrayConstPtr scalarArray); - virtual ~BasePVStringArray(); - virtual void setCapacity(int capacity); - virtual int get(int offset, int length, StringArrayData *data) ; - virtual int put(int offset,int length,StringArray from, - int fromOffset); - virtual void shareData(String value[],int capacity,int length); - // from Serializable - virtual void serialize(ByteBuffer *pbuffer,SerializableControl *pflusher) ; - virtual void deserialize(ByteBuffer *pbuffer,DeserializableControl *pflusher); - virtual void serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher, int offset, int count) ; - virtual bool operator==(PVField& pv) ; - virtual bool operator!=(PVField& pv) ; - private: - String *value; - }; - - BasePVStringArray::BasePVStringArray(PVStructure *parent, - ScalarArrayConstPtr scalarArray) - : PVStringArray(parent,scalarArray),value(new String[0]) - { } - - BasePVStringArray::~BasePVStringArray() - { - delete[] value; - } - - void BasePVStringArray::setCapacity(int capacity) - { - if(PVArray::getCapacity()==capacity) return; - if(!PVArray::isCapacityMutable()) { - std::string message("not capacityMutable"); - PVField::message(message, errorMessage); - return; - } - int length = PVArray::getLength(); - if(length>capacity) length = capacity; - String *newValue = new String[capacity]; - for(int i=0; i length) { - n = length-offset; - if(n<0) n = 0; - } - data->data = value; - data->offset = offset; - return n; - } - - int BasePVStringArray::put(int offset,int len, - StringArray from,int fromOffset) - { - if(PVField::isImmutable()) { - PVField::message("field is immutable",errorMessage); - return 0; - } - if(from==value) return len; - if(len<1) return 0; - int length = PVArray::getLength(); - int capacity = PVArray::getCapacity(); - if(offset+len > length) { - int newlength = offset + len; - if(newlength>capacity) { - setCapacity(newlength); - newlength = PVArray::getCapacity(); - len = newlength - offset; - if(len<=0) return 0; - } - length = newlength; - } - for(int i=0;i=0) { - // prepare array, if necessary - if(size>getCapacity()) setCapacity(size); - // retrieve value from the buffer - for(int i = 0; ilength) offset = length; - if(count<0) count = length; - - int maxCount = length-offset; - if(count>maxCount) count = maxCount; - - // write - SerializeHelper::writeSize(count, pbuffer, pflusher); - int end = offset+count; - for(int i = offset; iequals(this, &pv); - } - - bool BasePVStringArray::operator!=(PVField& pv) - { - return !(getConvert()->equals(this, &pv)); - } -}} diff --git a/pvDataApp/factory/PVDataCreateFactory.cpp b/pvDataApp/factory/PVDataCreateFactory.cpp index b00aa68..0f93a86 100644 --- a/pvDataApp/factory/PVDataCreateFactory.cpp +++ b/pvDataApp/factory/PVDataCreateFactory.cpp @@ -18,15 +18,6 @@ #include "PVArray.cpp" #include "PVScalarArray.cpp" #include "PVStructure.cpp" -#include "DefaultPVString.cpp" -#include "DefaultPVBooleanArray.cpp" -#include "DefaultPVByteArray.cpp" -#include "DefaultPVShortArray.cpp" -#include "DefaultPVIntArray.cpp" -#include "DefaultPVLongArray.cpp" -#include "DefaultPVFloatArray.cpp" -#include "DefaultPVDoubleArray.cpp" -#include "DefaultPVStringArray.cpp" #include "DefaultPVStructureArray.cpp" namespace epics { namespace pvData { @@ -128,6 +119,241 @@ typedef BasePVScalar BasePVFloat; typedef BasePVScalar BasePVDouble; typedef BasePVScalar BasePVString; + +/** Default storage for arrays + */ +template +class DefaultPVArray : public PVValueArray { +public: + typedef T value_type; + typedef T* pointer; + typedef const T* const_pointer; + + DefaultPVArray(PVStructure *parent,ScalarArrayConstPtr scalarArray); + virtual ~DefaultPVArray(); + virtual void setCapacity(int capacity); + virtual int get(int offset, int length, PVArrayData *data) ; + virtual int put(int offset,int length, pointer from, + int fromOffset); + virtual void shareData(pointer value,int capacity,int length); + // from Serializable + virtual void serialize(ByteBuffer *pbuffer,SerializableControl *pflusher) ; + virtual void deserialize(ByteBuffer *pbuffer,DeserializableControl *pflusher); + virtual void serialize(ByteBuffer *pbuffer, + SerializableControl *pflusher, int offset, int count) ; + virtual bool operator==(PVField& pv) ; + virtual bool operator!=(PVField& pv) ; +private: + pointer value; +}; + +template +DefaultPVArray::DefaultPVArray(PVStructure *parent, + ScalarArrayConstPtr scalarArray) +: PVValueArray(parent,scalarArray),value(new T[0]) +{ } + +template +DefaultPVArray::~DefaultPVArray() +{ + delete[] value; +} + +template +void DefaultPVArray::setCapacity(int capacity) +{ + if(PVArray::getCapacity()==capacity) return; + if(!PVArray::isCapacityMutable()) { + std::string message("not capacityMutable"); + PVField::message(message, errorMessage); + return; + } + int length = PVArray::getLength(); + if(length>capacity) length = capacity; + T *newValue = new T[capacity]; + for(int i=0; i +int DefaultPVArray::get(int offset, int len, PVArrayData *data) +{ + int n = len; + int length = PVArray::getLength(); + if(offset+len > length) { + n = length-offset; + if(n<0) n = 0; + } + data->data = value; + data->offset = offset; + return n; +} + +template +int DefaultPVArray::put(int offset,int len, + pointer from,int fromOffset) +{ + if(PVField::isImmutable()) { + PVField::message("field is immutable",errorMessage); + return 0; + } + if(from==value) return len; + if(len<1) return 0; + int length = PVArray::getLength(); + int capacity = PVArray::getCapacity(); + if(offset+len > length) { + int newlength = offset + len; + if(newlength>capacity) { + setCapacity(newlength); + newlength = PVArray::getCapacity(); + len = newlength - offset; + if(len<=0) return 0; + } + length = newlength; + } + for(int i=0;ipostPut(); + return len; +} + +template +void DefaultPVArray::shareData(pointer shareValue,int capacity,int length) +{ + delete[] value; + value = shareValue; + PVArray::setCapacityLength(capacity,length); +} + +template +void DefaultPVArray::serialize(ByteBuffer *pbuffer, + SerializableControl *pflusher) { + serialize(pbuffer, pflusher, 0, PVArray::getLength()); +} + +template +void DefaultPVArray::deserialize(ByteBuffer *pbuffer, + DeserializableControl *pcontrol) { + int size = SerializeHelper::readSize(pbuffer, pcontrol); + if(size>=0) { + // prepare array, if necessary + if(size>PVArray::getCapacity()) PVArray::setCapacity(size); + // retrieve value from the buffer + int i = 0; + while(true) { + int maxIndex = std::min(size-i, pbuffer->getRemaining())+i; + for(; igetBoolean(); + if(iensureData(1); // // TODO is there a better way to ensureData? + else + break; + } + // set new length + PVArray::setLength(size); + PVField::postPut(); + } + // TODO null arrays (size == -1) not supported +} + +template +void DefaultPVArray::serialize(ByteBuffer *pbuffer, + SerializableControl *pflusher, int offset, int count) { + // cache + int length = PVArray::getLength(); + + // check bounds + if(offset<0) + offset = 0; + else if(offset>length) offset = length; + if(count<0) count = length; + + int maxCount = length-offset; + if(count>maxCount) count = maxCount; + + // write + SerializeHelper::writeSize(count, pbuffer, pflusher); + int end = offset+count; + int i = offset; + while(true) { + int maxIndex = std::min(end-i, pbuffer->getRemaining())+i; + for(; iputBoolean(value[i]); + if(iflushSerializeBuffer(); + else + break; + } +} + +template +bool DefaultPVArray::operator==(PVField& pv) +{ + return getConvert()->equals(this, &pv); +} + +template +bool DefaultPVArray::operator!=(PVField& pv) +{ + return !(getConvert()->equals(this, &pv)); +} + +// specializations for String + +template<> +void DefaultPVArray::deserialize(ByteBuffer *pbuffer, + DeserializableControl *pcontrol) { + int size = SerializeHelper::readSize(pbuffer, pcontrol); + if(size>=0) { + // prepare array, if necessary + if(size>getCapacity()) setCapacity(size); + // retrieve value from the buffer + for(int i = 0; i +void DefaultPVArray::serialize(ByteBuffer *pbuffer, + SerializableControl *pflusher, int offset, int count) { + int length = getLength(); + + // check bounds + if(offset<0) + offset = 0; + else if(offset>length) offset = length; + if(count<0) count = length; + + int maxCount = length-offset; + if(count>maxCount) count = maxCount; + + // write + SerializeHelper::writeSize(count, pbuffer, pflusher); + int end = offset+count; + for(int i = offset; i DefaultPVBooleanArray; +typedef DefaultPVArray BasePVByteArray; +typedef DefaultPVArray BasePVShortArray; +typedef DefaultPVArray BasePVIntArray; +typedef DefaultPVArray BasePVLongArray; +typedef DefaultPVArray BasePVFloatArray; +typedef DefaultPVArray BasePVDoubleArray; +typedef DefaultPVArray BasePVStringArray; + +// Factory + PVDataCreate::PVDataCreate(){ } PVField *PVDataCreate::createPVField(PVStructure *parent,