factory: templates for BasePV*Array implementations
This commit is contained in:
@@ -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 <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
#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; i++) newValue[i] = value[i];
|
||||
delete[]value;
|
||||
value = newValue;
|
||||
PVArray::setCapacityLength(capacity,length);
|
||||
}
|
||||
|
||||
int DefaultPVBooleanArray::get(int offset, int len, BooleanArrayData *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;
|
||||
}
|
||||
|
||||
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<len;i++) {
|
||||
value[i+offset] = from[i+fromOffset];
|
||||
}
|
||||
PVArray::setLength(length);
|
||||
PVField::postPut();
|
||||
return len;
|
||||
}
|
||||
|
||||
void DefaultPVBooleanArray::shareData(BooleanArray shareValue,int capacity,int length)
|
||||
{
|
||||
delete[] value;
|
||||
value = shareValue;
|
||||
PVArray::setCapacityLength(capacity,length);
|
||||
}
|
||||
|
||||
void DefaultPVBooleanArray::serialize(ByteBuffer *pbuffer,
|
||||
SerializableControl *pflusher) {
|
||||
serialize(pbuffer, pflusher, 0, getLength());
|
||||
}
|
||||
|
||||
void DefaultPVBooleanArray::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
|
||||
int i = 0;
|
||||
while(true) {
|
||||
int maxIndex = min(size-i, pbuffer->getRemaining())+i;
|
||||
for(; i<maxIndex; i++)
|
||||
value[i] = pbuffer->getBoolean();
|
||||
if(i<size)
|
||||
pcontrol->ensureData(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(; i<maxIndex; i++)
|
||||
pbuffer->putBoolean(value[i]);
|
||||
if(i<end)
|
||||
pflusher->flushSerializeBuffer();
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool DefaultPVBooleanArray::operator==(PVField& pv)
|
||||
{
|
||||
return getConvert()->equals(this, &pv);
|
||||
}
|
||||
|
||||
bool DefaultPVBooleanArray::operator!=(PVField& pv)
|
||||
{
|
||||
return !(getConvert()->equals(this, &pv));
|
||||
}
|
||||
}}
|
||||
@@ -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 <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
#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; i++) newValue[i] = value[i];
|
||||
delete[]value;
|
||||
value = newValue;
|
||||
PVArray::setCapacityLength(capacity,length);
|
||||
}
|
||||
|
||||
int BasePVByteArray::get(int offset, int len, ByteArrayData *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;
|
||||
}
|
||||
|
||||
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<len;i++) {
|
||||
value[i+offset] = from[i+fromOffset];
|
||||
}
|
||||
PVArray::setLength(length);
|
||||
PVField::postPut();
|
||||
return len;
|
||||
}
|
||||
|
||||
void BasePVByteArray::shareData(ByteArray shareValue,int capacity,int length)
|
||||
{
|
||||
delete[] value;
|
||||
value = shareValue;
|
||||
PVArray::setCapacityLength(capacity,length);
|
||||
}
|
||||
|
||||
void BasePVByteArray::serialize(ByteBuffer *pbuffer,
|
||||
SerializableControl *pflusher) {
|
||||
serialize(pbuffer, pflusher, 0, getLength());
|
||||
}
|
||||
|
||||
void BasePVByteArray::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
|
||||
int i = 0;
|
||||
while(true) {
|
||||
int toRead = min(size-i, pbuffer->getRemaining());
|
||||
pbuffer->get((char *)value, i, toRead);
|
||||
i += toRead;
|
||||
if(i<size)
|
||||
pcontrol->ensureData(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(; i<maxIndex; i++)
|
||||
pbuffer->putByte(value[i]);
|
||||
if(i<end)
|
||||
pflusher->flushSerializeBuffer();
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool BasePVByteArray::operator==(PVField& pv)
|
||||
{
|
||||
return getConvert()->equals(this, &pv);
|
||||
}
|
||||
|
||||
bool BasePVByteArray::operator!=(PVField& pv)
|
||||
{
|
||||
return !(getConvert()->equals(this, &pv));
|
||||
}
|
||||
}}
|
||||
@@ -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 <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
#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; i++) newValue[i] = value[i];
|
||||
delete[]value;
|
||||
value = newValue;
|
||||
setCapacityLength(capacity,length);
|
||||
}
|
||||
|
||||
int BasePVDoubleArray::get(int offset, int len, DoubleArrayData *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;
|
||||
}
|
||||
|
||||
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<len;i++) {
|
||||
value[i+offset] = from[i+fromOffset];
|
||||
}
|
||||
PVArray::setLength(length);
|
||||
PVField::postPut();
|
||||
return len;
|
||||
}
|
||||
|
||||
void BasePVDoubleArray::shareData(
|
||||
double shareValue[],int capacity,int length)
|
||||
{
|
||||
delete[] value;
|
||||
value = shareValue;
|
||||
PVArray::setCapacityLength(capacity,length);
|
||||
}
|
||||
|
||||
void BasePVDoubleArray::serialize(ByteBuffer *pbuffer,
|
||||
SerializableControl *pflusher) {
|
||||
serialize(pbuffer, pflusher, 0, getLength());
|
||||
}
|
||||
|
||||
void BasePVDoubleArray::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
|
||||
int i = 0;
|
||||
while(true) {
|
||||
int maxIndex = min(size-i, (int)(pbuffer->getRemaining()
|
||||
/sizeof(double)))+i;
|
||||
for(; i<maxIndex; i++)
|
||||
value[i] = pbuffer->getDouble();
|
||||
if(i<size)
|
||||
pcontrol->ensureData(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(; i<maxIndex; i++)
|
||||
pbuffer->putDouble(value[i]);
|
||||
if(i<end)
|
||||
pflusher->flushSerializeBuffer();
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool BasePVDoubleArray::operator==(PVField& pv)
|
||||
{
|
||||
return getConvert()->equals(this, &pv);
|
||||
}
|
||||
|
||||
bool BasePVDoubleArray::operator!=(PVField& pv)
|
||||
{
|
||||
return !(getConvert()->equals(this, &pv));
|
||||
}
|
||||
}}
|
||||
@@ -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 <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
#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; i++) newValue[i] = value[i];
|
||||
delete[]value;
|
||||
value = newValue;
|
||||
PVArray::setCapacityLength(capacity,length);
|
||||
}
|
||||
|
||||
int BasePVFloatArray::get(int offset, int len, FloatArrayData *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;
|
||||
}
|
||||
|
||||
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<len;i++) {
|
||||
value[i+offset] = from[i+fromOffset];
|
||||
}
|
||||
PVArray::setLength(length);
|
||||
PVField::postPut();
|
||||
return len;
|
||||
}
|
||||
|
||||
void BasePVFloatArray::shareData(
|
||||
float shareValue[],int capacity,int length)
|
||||
{
|
||||
delete[] value;
|
||||
value = shareValue;
|
||||
PVArray::setCapacityLength(capacity,length);
|
||||
}
|
||||
|
||||
void BasePVFloatArray::serialize(ByteBuffer *pbuffer,
|
||||
SerializableControl *pflusher) {
|
||||
serialize(pbuffer, pflusher, 0, getLength());
|
||||
}
|
||||
|
||||
void BasePVFloatArray::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
|
||||
int i = 0;
|
||||
while(true) {
|
||||
int maxIndex = min(size-i, (int)(pbuffer->getRemaining()
|
||||
/sizeof(float)))+i;
|
||||
for(; i<maxIndex; i++)
|
||||
value[i] = pbuffer->getFloat();
|
||||
if(i<size)
|
||||
pcontrol->ensureData(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(; i<maxIndex; i++)
|
||||
pbuffer->putFloat(value[i]);
|
||||
if(i<end)
|
||||
pflusher->flushSerializeBuffer();
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool BasePVFloatArray::operator==(PVField& pv)
|
||||
{
|
||||
return getConvert()->equals(this, &pv);
|
||||
}
|
||||
|
||||
bool BasePVFloatArray::operator!=(PVField& pv)
|
||||
{
|
||||
return !(getConvert()->equals(this, &pv));
|
||||
}
|
||||
}}
|
||||
@@ -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 <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
#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; i++) newValue[i] = value[i];
|
||||
delete[]value;
|
||||
value = newValue;
|
||||
PVArray::setCapacityLength(capacity,length);
|
||||
}
|
||||
|
||||
int BasePVIntArray::get(int offset, int len, IntArrayData *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;
|
||||
}
|
||||
|
||||
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<len;i++) {
|
||||
value[i+offset] = from[i+fromOffset];
|
||||
}
|
||||
PVArray::setLength(length);
|
||||
PVField::postPut();
|
||||
return len;
|
||||
}
|
||||
|
||||
void BasePVIntArray::shareData(
|
||||
int32 shareValue[],int capacity,int length)
|
||||
{
|
||||
delete[] value;
|
||||
value = shareValue;
|
||||
PVArray::setCapacityLength(capacity,length);
|
||||
}
|
||||
|
||||
void BasePVIntArray::serialize(ByteBuffer *pbuffer,
|
||||
SerializableControl *pflusher) {
|
||||
serialize(pbuffer, pflusher, 0, getLength());
|
||||
}
|
||||
|
||||
void BasePVIntArray::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
|
||||
int i = 0;
|
||||
while(true) {
|
||||
int maxIndex = min(size-i, (int)(pbuffer->getRemaining()
|
||||
/sizeof(int32)))+i;
|
||||
for(; i<maxIndex; i++)
|
||||
value[i] = pbuffer->getInt();
|
||||
if(i<size)
|
||||
pcontrol->ensureData(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(; i<maxIndex; i++)
|
||||
pbuffer->putInt(value[i]);
|
||||
if(i<end)
|
||||
pflusher->flushSerializeBuffer();
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool BasePVIntArray::operator==(PVField& pv)
|
||||
{
|
||||
return getConvert()->equals(this, &pv);
|
||||
}
|
||||
|
||||
bool BasePVIntArray::operator!=(PVField& pv)
|
||||
{
|
||||
return !(getConvert()->equals(this, &pv));
|
||||
}
|
||||
}}
|
||||
@@ -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 <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
#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; i++) newValue[i] = value[i];
|
||||
delete[]value;
|
||||
value = newValue;
|
||||
PVArray::setCapacityLength(capacity,length);
|
||||
}
|
||||
|
||||
int BasePVLongArray::get(int offset, int len, LongArrayData *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;
|
||||
}
|
||||
|
||||
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<len;i++) {
|
||||
value[i+offset] = from[i+fromOffset];
|
||||
}
|
||||
PVArray::setLength(length);
|
||||
PVField::postPut();
|
||||
return len;
|
||||
}
|
||||
|
||||
void BasePVLongArray::shareData(
|
||||
int64 shareValue[],int capacity,int length)
|
||||
{
|
||||
delete[] value;
|
||||
value = shareValue;
|
||||
PVArray::setCapacityLength(capacity,length);
|
||||
}
|
||||
|
||||
void BasePVLongArray::serialize(ByteBuffer *pbuffer,
|
||||
SerializableControl *pflusher) {
|
||||
serialize(pbuffer, pflusher, 0, getLength());
|
||||
}
|
||||
|
||||
void BasePVLongArray::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
|
||||
int i = 0;
|
||||
while(true) {
|
||||
int maxIndex = min(size-i, (int)(pbuffer->getRemaining()
|
||||
/sizeof(int64)))+i;
|
||||
for(; i<maxIndex; i++)
|
||||
value[i] = pbuffer->getLong();
|
||||
if(i<size)
|
||||
pcontrol->ensureData(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(; i<maxIndex; i++)
|
||||
pbuffer->putLong(value[i]);
|
||||
if(i<end)
|
||||
pflusher->flushSerializeBuffer();
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool BasePVLongArray::operator==(PVField& pv)
|
||||
{
|
||||
return getConvert()->equals(this, &pv);
|
||||
}
|
||||
|
||||
bool BasePVLongArray::operator!=(PVField& pv)
|
||||
{
|
||||
return !(getConvert()->equals(this, &pv));
|
||||
}
|
||||
}}
|
||||
@@ -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 <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
#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; i++) newValue[i] = value[i];
|
||||
delete[]value;
|
||||
value = newValue;
|
||||
PVArray::setCapacityLength(capacity,length);
|
||||
}
|
||||
|
||||
int BasePVShortArray::get(int offset, int len, ShortArrayData *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;
|
||||
}
|
||||
|
||||
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<len;i++) {
|
||||
value[i+offset] = from[i+fromOffset];
|
||||
}
|
||||
PVArray::setLength(length);
|
||||
PVField::postPut();
|
||||
return len;
|
||||
}
|
||||
|
||||
void BasePVShortArray::shareData(
|
||||
int16 shareValue[],int capacity,int length)
|
||||
{
|
||||
delete[] value;
|
||||
value = shareValue;
|
||||
PVArray::setCapacityLength(capacity,length);
|
||||
}
|
||||
|
||||
void BasePVShortArray::serialize(ByteBuffer *pbuffer,
|
||||
SerializableControl *pflusher) {
|
||||
serialize(pbuffer, pflusher, 0, getLength());
|
||||
}
|
||||
|
||||
void BasePVShortArray::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
|
||||
int i = 0;
|
||||
while(true) {
|
||||
int maxIndex = min(size-i, (int)(pbuffer->getRemaining()
|
||||
/sizeof(int16)))+i;
|
||||
for(; i<maxIndex; i++)
|
||||
value[i] = pbuffer->getShort();
|
||||
if(i<size)
|
||||
pcontrol->ensureData(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(; i<maxIndex; i++)
|
||||
pbuffer->putShort(value[i]);
|
||||
if(i<end)
|
||||
pflusher->flushSerializeBuffer();
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool BasePVShortArray::operator==(PVField& pv)
|
||||
{
|
||||
return getConvert()->equals(this, &pv);
|
||||
}
|
||||
|
||||
bool BasePVShortArray::operator!=(PVField& pv)
|
||||
{
|
||||
return !(getConvert()->equals(this, &pv));
|
||||
}
|
||||
}}
|
||||
@@ -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 <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
#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; i++) newValue[i] = value[i];
|
||||
delete[]value;
|
||||
value = newValue;
|
||||
PVArray::setCapacityLength(capacity,length);
|
||||
}
|
||||
|
||||
int BasePVStringArray::get(int offset, int len, StringArrayData *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;
|
||||
}
|
||||
|
||||
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<len;i++) {
|
||||
value[i+offset] = from[i+fromOffset];
|
||||
}
|
||||
PVArray::setLength(length);
|
||||
PVField::postPut();
|
||||
return len;
|
||||
}
|
||||
|
||||
void BasePVStringArray::shareData(
|
||||
String shareValue[],int capacity,int length)
|
||||
{
|
||||
delete[] value;
|
||||
value = shareValue;
|
||||
PVArray::setCapacityLength(capacity,length);
|
||||
}
|
||||
|
||||
void BasePVStringArray::serialize(ByteBuffer *pbuffer,
|
||||
SerializableControl *pflusher) {
|
||||
serialize(pbuffer, pflusher, 0, getLength());
|
||||
}
|
||||
|
||||
void BasePVStringArray::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<size; i++)
|
||||
value[i] = SerializeHelper::deserializeString(pbuffer,
|
||||
pcontrol);
|
||||
// set new length
|
||||
setLength(size);
|
||||
postPut();
|
||||
}
|
||||
// TODO null arrays (size == -1) not supported
|
||||
}
|
||||
|
||||
void BasePVStringArray::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<end; i++)
|
||||
SerializeHelper::serializeString(value[i], pbuffer, pflusher);
|
||||
}
|
||||
|
||||
bool BasePVStringArray::operator==(PVField& pv)
|
||||
{
|
||||
return getConvert()->equals(this, &pv);
|
||||
}
|
||||
|
||||
bool BasePVStringArray::operator!=(PVField& pv)
|
||||
{
|
||||
return !(getConvert()->equals(this, &pv));
|
||||
}
|
||||
}}
|
||||
@@ -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<float> BasePVFloat;
|
||||
typedef BasePVScalar<double> BasePVDouble;
|
||||
typedef BasePVScalar<String> BasePVString;
|
||||
|
||||
|
||||
/** Default storage for arrays
|
||||
*/
|
||||
template<typename T>
|
||||
class DefaultPVArray : public PVValueArray<T> {
|
||||
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<T> *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<typename T>
|
||||
DefaultPVArray<T>::DefaultPVArray(PVStructure *parent,
|
||||
ScalarArrayConstPtr scalarArray)
|
||||
: PVValueArray<T>(parent,scalarArray),value(new T[0])
|
||||
{ }
|
||||
|
||||
template<typename T>
|
||||
DefaultPVArray<T>::~DefaultPVArray()
|
||||
{
|
||||
delete[] value;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void DefaultPVArray<T>::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<length; i++) newValue[i] = value[i];
|
||||
delete[]value;
|
||||
value = newValue;
|
||||
PVArray::setCapacityLength(capacity,length);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int DefaultPVArray<T>::get(int offset, int len, PVArrayData<T> *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<typename T>
|
||||
int DefaultPVArray<T>::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;i<len;i++) {
|
||||
value[i+offset] = from[i+fromOffset];
|
||||
}
|
||||
PVArray::setLength(length);
|
||||
this->postPut();
|
||||
return len;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void DefaultPVArray<T>::shareData(pointer shareValue,int capacity,int length)
|
||||
{
|
||||
delete[] value;
|
||||
value = shareValue;
|
||||
PVArray::setCapacityLength(capacity,length);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void DefaultPVArray<T>::serialize(ByteBuffer *pbuffer,
|
||||
SerializableControl *pflusher) {
|
||||
serialize(pbuffer, pflusher, 0, PVArray::getLength());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void DefaultPVArray<T>::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(; i<maxIndex; i++)
|
||||
value[i] = pbuffer->getBoolean();
|
||||
if(i<size)
|
||||
pcontrol->ensureData(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<typename T>
|
||||
void DefaultPVArray<T>::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<int>(end-i, pbuffer->getRemaining())+i;
|
||||
for(; i<maxIndex; i++)
|
||||
pbuffer->putBoolean(value[i]);
|
||||
if(i<end)
|
||||
pflusher->flushSerializeBuffer();
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool DefaultPVArray<T>::operator==(PVField& pv)
|
||||
{
|
||||
return getConvert()->equals(this, &pv);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool DefaultPVArray<T>::operator!=(PVField& pv)
|
||||
{
|
||||
return !(getConvert()->equals(this, &pv));
|
||||
}
|
||||
|
||||
// specializations for String
|
||||
|
||||
template<>
|
||||
void DefaultPVArray<String>::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<size; i++)
|
||||
value[i] = SerializeHelper::deserializeString(pbuffer,
|
||||
pcontrol);
|
||||
// set new length
|
||||
setLength(size);
|
||||
postPut();
|
||||
}
|
||||
// TODO null arrays (size == -1) not supported
|
||||
}
|
||||
|
||||
template<>
|
||||
void DefaultPVArray<String>::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<end; i++)
|
||||
SerializeHelper::serializeString(value[i], pbuffer, pflusher);
|
||||
}
|
||||
|
||||
typedef DefaultPVArray<bool> DefaultPVBooleanArray;
|
||||
typedef DefaultPVArray<int8> BasePVByteArray;
|
||||
typedef DefaultPVArray<int16> BasePVShortArray;
|
||||
typedef DefaultPVArray<int32> BasePVIntArray;
|
||||
typedef DefaultPVArray<int64> BasePVLongArray;
|
||||
typedef DefaultPVArray<float> BasePVFloatArray;
|
||||
typedef DefaultPVArray<double> BasePVDoubleArray;
|
||||
typedef DefaultPVArray<String> BasePVStringArray;
|
||||
|
||||
// Factory
|
||||
|
||||
PVDataCreate::PVDataCreate(){ }
|
||||
|
||||
PVField *PVDataCreate::createPVField(PVStructure *parent,
|
||||
|
||||
Reference in New Issue
Block a user