From 5d6205cb44dbdec7e4f2a0df8fb854d43a4b6060 Mon Sep 17 00:00:00 2001 From: Marty Kraimer Date: Sun, 8 Jul 2012 08:38:57 -0400 Subject: [PATCH] changes to PVStructureArray --- pvDataApp/factory/DefaultPVStructureArray.h | 60 --------------------- pvDataApp/factory/PVStructureArray.cpp | 14 +++-- pvDataApp/pv/pvData.h | 3 +- testApp/pv/testPVStructureArray.cpp | 8 +-- 4 files changed, 9 insertions(+), 76 deletions(-) delete mode 100644 pvDataApp/factory/DefaultPVStructureArray.h diff --git a/pvDataApp/factory/DefaultPVStructureArray.h b/pvDataApp/factory/DefaultPVStructureArray.h deleted file mode 100644 index a34ec3d..0000000 --- a/pvDataApp/factory/DefaultPVStructureArray.h +++ /dev/null @@ -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 -#include -#include -#include -#include -#include -#include -#include - -namespace epics { namespace pvData { - -class BasePVStructureArray : public PVStructureArray { -public: - POINTER_DEFINITIONS(PVStructureArray); - typedef PVStructurePtr* pointer; - typedef std::vector vector; - typedef std::tr1::shared_ptr 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*/ diff --git a/pvDataApp/factory/PVStructureArray.cpp b/pvDataApp/factory/PVStructureArray.cpp index 18d7c1e..683b550 100644 --- a/pvDataApp/factory/PVStructureArray.cpp +++ b/pvDataApp/factory/PVStructureArray.cpp @@ -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; icreatePVStructure(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 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 ArrayDataType; typedef std::vector vector; + typedef const std::vector const_vector; typedef std::tr1::shared_ptr 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. diff --git a/testApp/pv/testPVStructureArray.cpp b/testApp/pv/testPVStructureArray.cpp index 503b828..889dc96 100644 --- a/testApp/pv/testPVStructureArray.cpp +++ b/testApp/pv/testPVStructureArray.cpp @@ -41,13 +41,7 @@ void testPVStructureArray(FILE * fd) { palarms.push_back( pvDataCreate->createPVStructure(standardField->alarm())); } - PVStructurePtr *xxx = &palarms[0]; -for(size_t i=0;itoString(&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());