changes to PVStructureArray
This commit is contained in:
@@ -1,60 +0,0 @@
|
||||
/*DefaultPVStructureArray.h*/
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
#ifndef DEFAULTPVSTRUCTUREARRAY_H
|
||||
#define DEFAULTPVSTRUCTUREARRAY_H
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
#include <pv/pvData.h>
|
||||
#include <pv/convert.h>
|
||||
#include <pv/factory.h>
|
||||
#include <pv/serializeHelper.h>
|
||||
|
||||
namespace epics { namespace pvData {
|
||||
|
||||
class BasePVStructureArray : public PVStructureArray {
|
||||
public:
|
||||
POINTER_DEFINITIONS(PVStructureArray);
|
||||
typedef PVStructurePtr* pointer;
|
||||
typedef std::vector<PVStructurePtr> vector;
|
||||
typedef std::tr1::shared_ptr<vector> shared_vector;
|
||||
|
||||
BasePVStructureArray(PVStructure *parent,
|
||||
StructureArrayConstPtr structureArray);
|
||||
virtual ~BasePVStructureArray();
|
||||
virtual StructureArrayConstPtr getStructureArray();
|
||||
virtual std::size_t append(std::size_t number);
|
||||
virtual bool remove(std::size_t offset,std::size_t number);
|
||||
virtual void compress();
|
||||
virtual void setCapacity(std::size_t capacity);
|
||||
virtual std::size_t get(std::size_t offset, std::size_t length,
|
||||
StructureArrayData &data);
|
||||
virtual std::size_t put(std::size_t offset,std::size_t length,
|
||||
vector const & from, std::size_t fromOffset);
|
||||
virtual void shareData(
|
||||
shared_vector const & value,
|
||||
std::size_t capacity,
|
||||
std::size_t length);
|
||||
virtual pointer getRaw();
|
||||
virtual pointer getRaw() const;
|
||||
virtual vector const & getVector(){return *value.get();}
|
||||
virtual shared_vector const & getSharedVector(){return value;};
|
||||
|
||||
virtual void serialize(ByteBuffer *pbuffer,
|
||||
SerializableControl *pflusher) const;
|
||||
virtual void deserialize(ByteBuffer *buffer,
|
||||
DeserializableControl *pflusher);
|
||||
virtual void serialize(ByteBuffer *pbuffer,
|
||||
SerializableControl *pflusher, std::size_t offset, std::size_t count) const ;
|
||||
private:
|
||||
StructureArrayConstPtr structureArray;
|
||||
shared_vector value;
|
||||
};
|
||||
}}
|
||||
|
||||
#endif /*DEFAULTPVSTRUCTUREARRAY_H*/
|
||||
@@ -32,10 +32,10 @@ size_t PVStructureArray::append(size_t number)
|
||||
size_t newLength = currentLength + number;
|
||||
setCapacity(newLength);
|
||||
StructureConstPtr structure = structureArray->getStructure();
|
||||
PVStructurePtrArray vec = *value.get();
|
||||
PVStructurePtrArray *to = value.get();
|
||||
for(size_t i=currentLength; i<newLength; i++) {
|
||||
PVStructurePtr pvStructure(getPVDataCreate()->createPVStructure(structure));
|
||||
vec[i].swap(pvStructure);
|
||||
(*to)[i].swap(pvStructure);
|
||||
}
|
||||
return newLength;
|
||||
}
|
||||
@@ -119,14 +119,13 @@ size_t PVStructureArray::get(
|
||||
}
|
||||
|
||||
size_t PVStructureArray::put(size_t offset,size_t len,
|
||||
PVStructurePtr* const from, size_t fromOffset)
|
||||
const_vector const & from, size_t fromOffset)
|
||||
{
|
||||
if(isImmutable()) {
|
||||
message(String("field is immutable"), errorMessage);
|
||||
return 0;
|
||||
}
|
||||
std::vector<PVStructurePtr> to = *value.get();
|
||||
if(from==&to[0]) return len;
|
||||
if(&from==value.get()) return 0;
|
||||
if(len<1) return 0;
|
||||
size_t length = getLength();
|
||||
size_t capacity = getCapacity();
|
||||
@@ -142,7 +141,7 @@ size_t PVStructureArray::put(size_t offset,size_t len,
|
||||
length = newlength;
|
||||
setLength(length);
|
||||
}
|
||||
to = *value.get();
|
||||
PVStructurePtrArray *to = value.get();
|
||||
StructureConstPtr structure = structureArray->getStructure();
|
||||
for(size_t i=0; i<len; i++) {
|
||||
PVStructurePtr frompv = from[i+fromOffset];
|
||||
@@ -152,8 +151,7 @@ size_t PVStructureArray::put(size_t offset,size_t len,
|
||||
"Element is not a compatible structure"));
|
||||
}
|
||||
}
|
||||
PVStructurePtr pvStructure(frompv);
|
||||
to[i+offset].swap(pvStructure);
|
||||
(*to)[i+offset] = frompv;
|
||||
}
|
||||
postPut();
|
||||
setLength(length);
|
||||
|
||||
@@ -483,6 +483,7 @@ public:
|
||||
typedef const PVStructurePtr* const_pointer;
|
||||
typedef PVArrayData<PVStructurePtr> ArrayDataType;
|
||||
typedef std::vector<PVStructurePtr> vector;
|
||||
typedef const std::vector<PVStructurePtr> const_vector;
|
||||
typedef std::tr1::shared_ptr<vector> shared_vector;
|
||||
typedef PVStructureArray &reference;
|
||||
typedef const PVStructureArray& const_reference;
|
||||
@@ -530,7 +531,7 @@ public:
|
||||
* @return The number of elements put into the array.
|
||||
*/
|
||||
virtual std::size_t put(std::size_t offset,std::size_t length,
|
||||
pointer const from, std::size_t fromOffset);
|
||||
const_vector const & from, std::size_t fromOffset);
|
||||
/**
|
||||
* Share data from another source.
|
||||
* @param value The data to share.
|
||||
|
||||
@@ -41,13 +41,7 @@ void testPVStructureArray(FILE * fd) {
|
||||
palarms.push_back(
|
||||
pvDataCreate->createPVStructure(standardField->alarm()));
|
||||
}
|
||||
PVStructurePtr *xxx = &palarms[0];
|
||||
for(size_t i=0;i<na; i++) {
|
||||
buffer.clear();
|
||||
xxx[i]->toString(&buffer);
|
||||
printf("xxx[%d]\n%s\n",(int)i,buffer.c_str());
|
||||
}
|
||||
pvAlarmStructure->put(0,2,xxx,0);
|
||||
pvAlarmStructure->put(0,2,palarms,0);
|
||||
buffer.clear();
|
||||
pvAlarmStructure->toString(&buffer);
|
||||
fprintf(fd,"pvAlarmStructure\n%s\n",buffer.c_str());
|
||||
|
||||
Reference in New Issue
Block a user