From 294684636d132d58aac177802555514efe68910d Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Wed, 2 Feb 2011 16:44:23 -0500 Subject: [PATCH] pvData.h: apply templates to PV* and PV*Array classes The scalar and array value interface classes are largely copy+paste so can easily be made templates PVScalarValue<> and PVValueArray<>. Currently parametrized only by value type. Also the *ArrayData helpers become PVArrayData<> --- pvDataApp/pv/pvData.h | 328 +++++++++--------------------------------- 1 file changed, 64 insertions(+), 264 deletions(-) diff --git a/pvDataApp/pv/pvData.h b/pvDataApp/pv/pvData.h index c6eef4d..e001156 100644 --- a/pvDataApp/pv/pvData.h +++ b/pvDataApp/pv/pvData.h @@ -22,24 +22,8 @@ class PostHandler; class PVField; class PVScalar; -class PVBoolean; -class PVByte; -class PVShort; -class PVInt; -class PVLong; -class PVFloat; -class PVDouble; -class PVString; class PVScalarArray; -class PVBooleanArray; -class PVByteArray; -class PVShortArray; -class PVIntArray; -class PVLongArray; -class PVFloatArray; -class PVDoubleArray; -class PVStringArray; class PVStructure; class PVStructureArray; @@ -113,6 +97,31 @@ protected: PVScalar(PVStructure *parent,ScalarConstPtr scalar); }; +template +class PVScalarValue : public PVScalar { +public: + typedef T value_type; + typedef T* pointer; + typedef const T* const_pointer; + + virtual ~PVScalarValue() {} + virtual T get() = 0; + virtual void put(T value) = 0; +protected: + PVScalarValue(PVStructure *parent,ScalarConstPtr scalar) + : PVScalar(parent,scalar) {} +private: +}; + +typedef PVScalarValue PVBoolean; +typedef PVScalarValue PVByte; +typedef PVScalarValue PVShort; +typedef PVScalarValue PVInt; +typedef PVScalarValue PVLong; +typedef PVScalarValue PVFloat; +typedef PVScalarValue PVDouble; +typedef PVScalarValue PVString; + class PVArray : public PVField, public SerializableArray { public: virtual ~PVArray(); @@ -135,6 +144,17 @@ private: class PVArrayPvt * pImpl; }; +template +class PVArrayData { +public: + typedef T value_type; + typedef T* pointer; + typedef const T* const_pointer; + + pointer data; + int offset; +}; + class PVScalarArray : public PVArray { public: @@ -152,11 +172,7 @@ protected: private: }; -class StructureArrayData { -public: - PVStructurePtrArray data; - int offset; -}; +typedef PVArrayData StructureArrayData; class PVStructureArray : public PVArray { public: @@ -227,267 +243,51 @@ private: class PVStructurePvt * pImpl; }; -class PVBoolean : public PVScalar { +template +class PVValueArray : public PVScalarArray { public: - virtual ~PVBoolean() {} - virtual bool get() = 0; - virtual void put(bool value) = 0; -protected: - PVBoolean(PVStructure *parent,ScalarConstPtr scalar) - : PVScalar(parent,scalar) {} -private: -}; + typedef T value_type; + typedef T* pointer; + typedef const T* const_pointer; + typedef PVArrayData ArrayDataType; -class PVByte : public PVScalar { -public: - virtual ~PVByte() {} - virtual int8 get() = 0; - virtual void put(int8 value) = 0; -protected: - PVByte(PVStructure *parent,ScalarConstPtr scalar) - : PVScalar(parent,scalar) {} -private: -}; - -class PVShort : public PVScalar { -public: - virtual ~PVShort() {} - virtual int16 get() = 0; - virtual void put(int16 value) = 0; -protected: - PVShort(PVStructure *parent,ScalarConstPtr scalar) - : PVScalar(parent,scalar) {} -private: -}; - -class PVInt : public PVScalar{ -public: - virtual ~PVInt() {} - virtual int32 get() = 0; - virtual void put(int32 value) = 0; -protected: - PVInt(PVStructure *parent,ScalarConstPtr scalar) - : PVScalar(parent,scalar) {} -private: -}; - -class PVLong : public PVScalar { -public: - virtual ~PVLong() {} - virtual int64 get() = 0; - virtual void put(int64 value) = 0; -protected: - PVLong(PVStructure *parent,ScalarConstPtr scalar) - : PVScalar(parent,scalar) {} -private: -}; - -class PVFloat : public PVScalar { -public: - virtual ~PVFloat() {} - virtual float get() = 0; - virtual void put(float value) = 0; -protected: - PVFloat(PVStructure *parent,ScalarConstPtr scalar) - : PVScalar(parent,scalar) {} -private: -}; - -class PVDouble : public PVScalar { -public: - virtual ~PVDouble() {} - virtual double get() = 0; - virtual void put(double value) = 0; -protected: - PVDouble(PVStructure *parent,ScalarConstPtr scalar) - : PVScalar(parent,scalar) {} -private: -}; - -class PVString : public PVScalar { -public: - virtual ~PVString() {} - virtual String get() = 0; - virtual void put(String value) = 0; -protected: - PVString(PVStructure *parent,ScalarConstPtr scalar) - : PVScalar(parent,scalar) {} -private: -}; - -class BooleanArrayData { -public: - BooleanArray data; - int offset; -}; - -class PVBooleanArray : public PVScalarArray { -public: - virtual ~PVBooleanArray() {} + virtual ~PVValueArray() {} virtual void setCapacity(int capacity) = 0; - virtual int get(int offset, int length, BooleanArrayData *data) = 0; - virtual int put(int offset,int length, BooleanArray from, int fromOffset) = 0; - virtual void shareData(BooleanArray value,int capacity,int length) = 0; + virtual int get(int offset, int length, ArrayDataType *data) = 0; + virtual int put(int offset,int length, pointer from, int fromOffset) = 0; + virtual void shareData(pointer value,int capacity,int length) = 0; virtual void serialize(ByteBuffer *pbuffer,SerializableControl *pflusher) = 0; virtual void deserialize(ByteBuffer *pbuffer,DeserializableControl *pflusher) = 0; protected: - PVBooleanArray(PVStructure *parent,ScalarArrayConstPtr scalar) + PVValueArray(PVStructure *parent,ScalarArrayConstPtr scalar) : PVScalarArray(parent,scalar) {} private: }; +typedef PVArrayData BooleanArrayData; +typedef PVValueArray PVBooleanArray; -class ByteArrayData { -public: - ByteArray data; - int offset; -}; +typedef PVArrayData ByteArrayData; +typedef PVValueArray PVByteArray; -class PVByteArray : public PVScalarArray { -public: - virtual ~PVByteArray() {} - virtual void setCapacity(int capacity) = 0; - virtual int get(int offset, int length, ByteArrayData *data) = 0; - virtual int put(int offset,int length, ByteArray from, int fromOffset) = 0; - virtual void shareData(ByteArray value,int capacity,int length) = 0; - virtual void serialize(ByteBuffer *pbuffer,SerializableControl *pflusher) = 0; - virtual void deserialize(ByteBuffer *pbuffer,DeserializableControl *pflusher) = 0; -protected: - PVByteArray(PVStructure *parent,ScalarArrayConstPtr scalar) - : PVScalarArray(parent,scalar) {} -private: -}; +typedef PVArrayData ShortArrayData; +typedef PVValueArray PVShortArray; -class ShortArrayData { -public: - ShortArray data; - int offset; -}; +typedef PVArrayData IntArrayData; +typedef PVValueArray PVIntArray; -class PVShortArray : public PVScalarArray { -public: - virtual ~PVShortArray() {} - virtual void setCapacity(int capacity) = 0; - virtual int get(int offset, int length, ShortArrayData *data) = 0; - virtual int put(int offset,int length, ShortArray from, int fromOffset) = 0; - virtual void shareData(ShortArray value,int capacity,int length) = 0; - virtual void serialize(ByteBuffer *pbuffer,SerializableControl *pflusher) = 0; - virtual void deserialize(ByteBuffer *pbuffer,DeserializableControl *pflusher) = 0; -protected: - PVShortArray(PVStructure *parent,ScalarArrayConstPtr scalar) - : PVScalarArray(parent,scalar) {} -private: -}; - -class IntArrayData { -public: - IntArray data; - int offset; -}; - -class PVIntArray : public PVScalarArray { -public: - virtual ~PVIntArray() {} - virtual void setCapacity(int capacity) = 0; - virtual int get(int offset, int length, IntArrayData *data) = 0; - virtual int put(int offset,int length, IntArray from, int fromOffset)= 0; - virtual void shareData(IntArray value,int capacity,int length)= 0; - virtual void serialize(ByteBuffer *pbuffer,SerializableControl *pflusher) = 0; - virtual void deserialize(ByteBuffer *pbuffer,DeserializableControl *pflusher)= 0; -protected: - PVIntArray(PVStructure *parent,ScalarArrayConstPtr scalar) - : PVScalarArray(parent,scalar) {} -private: -}; - -class LongArrayData { -public: - LongArray data; - int offset; -}; - -class PVLongArray : public PVScalarArray { -public: - virtual ~PVLongArray() {} - virtual void setCapacity(int capacity) = 0; - virtual int get(int offset, int length, LongArrayData *data) = 0; - virtual int put(int offset,int length, LongArray from, int fromOffset)= 0; - virtual void shareData(LongArray value,int capacity,int length)= 0; - virtual void serialize(ByteBuffer *pbuffer,SerializableControl *pflusher) = 0; - virtual void deserialize(ByteBuffer *pbuffer,DeserializableControl *pflusher)= 0; -protected: - PVLongArray(PVStructure *parent,ScalarArrayConstPtr scalar) - : PVScalarArray(parent,scalar) {} -private: -}; +typedef PVArrayData LongArrayData; +typedef PVValueArray PVLongArray; -class FloatArrayData { -public: - FloatArray data; - int offset; -}; +typedef PVArrayData FloatArrayData; +typedef PVValueArray PVFloatArray; -class PVFloatArray : public PVScalarArray { -public: - virtual ~PVFloatArray() {} - virtual void setCapacity(int capacity) = 0; - virtual int get(int offset, int length, FloatArrayData *data) = 0; - virtual int put(int offset,int length, FloatArray from, int fromOffset)= 0; - virtual void shareData(FloatArray value,int capacity,int length)= 0; - virtual void serialize(ByteBuffer *pbuffer,SerializableControl *pflusher) = 0; - virtual void deserialize(ByteBuffer *pbuffer,DeserializableControl *pflusher)= 0; -protected: - PVFloatArray(PVStructure *parent,ScalarArrayConstPtr scalar) - : PVScalarArray(parent,scalar) {} -private: -}; +typedef PVArrayData DoubleArrayData; +typedef PVValueArray PVDoubleArray; - -class DoubleArrayData { -public: - DoubleArrayData(){} - ~DoubleArrayData(){}; - DoubleArray data; - int offset; -}; - -class PVDoubleArray : public PVScalarArray { -public: - virtual ~PVDoubleArray() {} - virtual void setCapacity(int capacity) = 0; - virtual int get(int offset, int length, DoubleArrayData *data) = 0; - virtual int put(int offset,int length, DoubleArray from, int fromOffset) = 0; - virtual void shareData(DoubleArray value,int capacity,int length) = 0; - virtual void serialize(ByteBuffer *pbuffer,SerializableControl *pflusher) = 0; - virtual void deserialize(ByteBuffer *pbuffer,DeserializableControl *pflusher) = 0; -protected: - PVDoubleArray(PVStructure *parent,ScalarArrayConstPtr scalar) - : PVScalarArray(parent,scalar) {} -private: -}; - - -class StringArrayData { -public: - StringArray data; - int offset; -}; - -class PVStringArray : public PVScalarArray { -public: - virtual ~PVStringArray() {} - virtual void setCapacity(int capacity) = 0; - virtual int get(int offset, int length, StringArrayData *data) = 0; - virtual int put(int offset,int length, StringArray from, int fromOffset)= 0; - virtual void shareData(StringArray value,int capacity,int length)= 0; - virtual void serialize(ByteBuffer *pbuffer,SerializableControl *pflusher) = 0; - virtual void deserialize(ByteBuffer *pbuffer,DeserializableControl *pflusher)= 0; -protected: - PVStringArray(PVStructure *parent,ScalarArrayConstPtr scalar) - : PVScalarArray(parent,scalar) {} -private: -}; +typedef PVArrayData StringArrayData; +typedef PVValueArray PVStringArray; class PVDataCreate { public: