diff --git a/pvDataApp/factory/PVDataCreateFactory.cpp b/pvDataApp/factory/PVDataCreateFactory.cpp index 5e9ce2c..61b1ab6 100644 --- a/pvDataApp/factory/PVDataCreateFactory.cpp +++ b/pvDataApp/factory/PVDataCreateFactory.cpp @@ -67,7 +67,7 @@ void BasePVScalar::put(T val){value = val;} template void BasePVScalar::serialize(ByteBuffer *pbuffer, SerializableControl *pflusher) const { - pflusher->ensureBuffer(1); + pflusher->ensureBuffer(sizeof(T)); pbuffer->put(value); } @@ -75,7 +75,7 @@ template void BasePVScalar::deserialize(ByteBuffer *pbuffer, DeserializableControl *pflusher) { - pflusher->ensureData(1); + pflusher->ensureData(sizeof(T)); value = pbuffer->get(); } @@ -91,25 +91,6 @@ bool BasePVScalar::operator!=(PVField& pvField) return !(getConvert()->equals(this, &pvField)); } -// Specializations for scalar String - -template<> -BasePVScalar::BasePVScalar(PVStructure *parent,ScalarConstPtr scalar) -: PVScalarValue(parent,scalar),value() -{} - -template<> -void BasePVScalar::serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher) const { - SerializeHelper::serializeString(value, pbuffer, pflusher); -} - -template<> -void BasePVScalar::deserialize(ByteBuffer *pbuffer, - DeserializableControl *pflusher) { - value = SerializeHelper::deserializeString(pbuffer, pflusher); -} - typedef BasePVScalar BasePVBoolean; typedef BasePVScalar BasePVByte; typedef BasePVScalar BasePVShort; @@ -117,7 +98,83 @@ typedef BasePVScalar BasePVInt; typedef BasePVScalar BasePVLong; typedef BasePVScalar BasePVFloat; typedef BasePVScalar BasePVDouble; -typedef BasePVScalar BasePVString; + +// BasePVString is special case, since it implements SerializableArray +class BasePVString : public PVString { +public: + typedef String value_type; + typedef String* pointer; + typedef const String* const_pointer; + + BasePVString(PVStructure *parent,ScalarConstPtr scalar); + virtual ~BasePVString(); + virtual String get(); + virtual void put(String val); + virtual void serialize(ByteBuffer *pbuffer, + SerializableControl *pflusher) const; + virtual void deserialize(ByteBuffer *pbuffer, + DeserializableControl *pflusher); + virtual void serialize(ByteBuffer *pbuffer, + SerializableControl *pflusher, int offset, int count) const; + virtual bool operator==(PVField& pv) ; + virtual bool operator!=(PVField& pv) ; +private: + String value; +}; + +BasePVString::BasePVString(PVStructure *parent,ScalarConstPtr scalar) + : PVString(parent,scalar),value() +{} + +BasePVString::~BasePVString() {} + +String BasePVString::get() { return value;} + +void BasePVString::put(String val){value = val;} + +void BasePVString::serialize(ByteBuffer *pbuffer, + SerializableControl *pflusher) const +{ + SerializeHelper::serializeString(value, pbuffer, pflusher); +} + +void BasePVString::deserialize(ByteBuffer *pbuffer, + DeserializableControl *pflusher) +{ + value = SerializeHelper::deserializeString(pbuffer, pflusher); +} + +void BasePVString::serialize(ByteBuffer *pbuffer, + SerializableControl *pflusher, int offset, int count) const +{ + // check bounds + const int length = /*(value == null) ? 0 :*/ value.length(); + if (offset < 0) offset = 0; + else if (offset > length) offset = length; + if (count < 0) count = length; + + const int maxCount = length - offset; + if (count > maxCount) + count = maxCount; + + // write + SerializeHelper::serializeSubstring(value, offset, count, pbuffer, pflusher); +} + +bool BasePVString::operator==(PVField& pvField) +{ + return getConvert()->equals(this, &pvField); +} + +bool BasePVString::operator!=(PVField& pvField) +{ + return !(getConvert()->equals(this, &pvField)); +} + + + + + /** Default storage for arrays diff --git a/pvDataApp/pv/pvData.h b/pvDataApp/pv/pvData.h index fc8fbf0..8f5aaff 100644 --- a/pvDataApp/pv/pvData.h +++ b/pvDataApp/pv/pvData.h @@ -121,7 +121,16 @@ typedef PVScalarValue PVInt; typedef PVScalarValue PVLong; typedef PVScalarValue PVFloat; typedef PVScalarValue PVDouble; -typedef PVScalarValue PVString; + +// BasePVString is special case, since it implements SerializableArray +class PVString : public PVScalarValue, SerializableArray { +public: + virtual ~PVString() {} +protected: + PVString(PVStructure *parent,ScalarConstPtr scalar) + : PVScalarValue(parent,scalar) {} +}; + class PVArray : public PVField, public SerializableArray { public: