serialization added

This commit is contained in:
Matej Sekoranja
2010-11-01 23:28:03 +01:00
parent 304a9c60d0
commit f751d075c5
23 changed files with 1417 additions and 329 deletions

View File

@@ -9,6 +9,7 @@
#include "pvData.h"
#include "factory.h"
#include "AbstractPVScalarArray.h"
#include "serializeHelper.h"
namespace epics { namespace pvData {
@@ -33,8 +34,8 @@ namespace epics { namespace pvData {
SerializableControl *pflusher, int offset, int count) ;
virtual void toString(StringBuilder buf);
virtual void toString(StringBuilder buf,int indentLevel);
virtual bool operator==(PVField *pv) ;
virtual bool operator!=(PVField *pv) ;
virtual bool operator==(PVField& pv) ;
virtual bool operator!=(PVField& pv) ;
private:
String *value;
};
@@ -42,7 +43,7 @@ namespace epics { namespace pvData {
BasePVStringArray::BasePVStringArray(PVStructure *parent,
ScalarArrayConstPtr scalarArray)
: PVStringArray(parent,scalarArray),value(new String[0])
{ }
{ }
BasePVStringArray::~BasePVStringArray()
{
@@ -59,14 +60,14 @@ namespace epics { namespace pvData {
}
int length = PVArray::getLength();
if(length>capacity) length = capacity;
String *newValue = new String[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 BasePVStringArray::get(int offset, int len, StringArrayData *data)
{
int n = len;
int length = PVArray::getLength();
@@ -105,7 +106,7 @@ namespace epics { namespace pvData {
}
PVArray::setLength(length);
PVField::postPut();
return len;
return len;
}
void BasePVStringArray::shareData(
@@ -117,21 +118,45 @@ namespace epics { namespace pvData {
}
void BasePVStringArray::serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher)
{
throw std::logic_error(notImplemented);
SerializableControl *pflusher) {
serialize(pbuffer, pflusher, 0, getLength());
}
void BasePVStringArray::deserialize(ByteBuffer *pbuffer,
DeserializableControl *pflusher)
{
throw std::logic_error(notImplemented);
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)
{
throw std::logic_error(notImplemented);
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);
}
void BasePVStringArray::toString(StringBuilder buf)
@@ -146,14 +171,14 @@ namespace epics { namespace pvData {
PVField::toString(buf,indentLevel);
}
bool BasePVStringArray::operator==(PVField *pv)
bool BasePVStringArray::operator==(PVField& pv)
{
return getConvert()->equals(this,pv);
return getConvert()->equals(this, &pv);
}
bool BasePVStringArray::operator!=(PVField *pv)
bool BasePVStringArray::operator!=(PVField& pv)
{
return !(getConvert()->equals(this,pv));
return !(getConvert()->equals(this, &pv));
}
}}
#endif /* BASEPVSTRINGARRAY_H */