Massive name changes to factory.
The changes make it clear what is a default implementation and what implements base classes defined in pvData.h.
This commit is contained in:
165
pvDataApp/factory/DefaultPVStringArray.cpp
Normal file
165
pvDataApp/factory/DefaultPVStringArray.cpp
Normal file
@@ -0,0 +1,165 @@
|
||||
/*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));
|
||||
}
|
||||
}}
|
||||
Reference in New Issue
Block a user