/*BasePVIntArray.h*/ #ifndef BASEPVINTARRAY_H #define BASEPVINTARRAY_H #include #include #include #include #include #include #include "pvData.h" #include "factory.h" #include "AbstractPVScalarArray.h" #include "serializeHelper.h" using std::min; namespace epics { namespace pvData { PVIntArray::~PVIntArray() {} PVIntArray::PVIntArray(PVStructure *parent,ScalarArrayConstPtr scalar) : PVScalarArray(parent,scalar) {} 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(epicsInt32 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 void toString(StringBuilder buf); virtual void toString(StringBuilder buf,int indentLevel); virtual bool operator==(PVField& pv) ; virtual bool operator!=(PVField& pv) ; private: epicsInt32 *value; }; BasePVIntArray::BasePVIntArray(PVStructure *parent, ScalarArrayConstPtr scalarArray) : PVIntArray(parent,scalarArray),value(new epicsInt32[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; epicsInt32 *newValue = new epicsInt32[capacity]; for(int i=0; i 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=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(epicsInt32)))+i; for(; igetInt(); if(iensureData(sizeof(epicsInt32)); // 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(epicsInt32)))+i; for(; iputInt(value[i]); if(iflushSerializeBuffer(); else break; } } void BasePVIntArray::toString(StringBuilder buf) { toString(buf,1); } void BasePVIntArray::toString(StringBuilder buf,int indentLevel) { getConvert()->getString(buf,this,indentLevel); PVField::toString(buf,indentLevel); } bool BasePVIntArray::operator==(PVField& pv) { return getConvert()->equals(this, &pv); } bool BasePVIntArray::operator!=(PVField& pv) { return !(getConvert()->equals(this, &pv)); } }} #endif /* BASEPVINTARRAY_H */