factory: templates for BasePV* implementations

This commit is contained in:
Michael Davidsaver
2011-02-08 13:28:03 -05:00
parent 07a6bbaebd
commit 3dae9f8728
9 changed files with 93 additions and 535 deletions

View File

@@ -1,67 +0,0 @@
/*PVBoolean.cpp*/
/**
* 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.
*/
#include <cstddef>
#include <cstdlib>
#include <string>
#include <cstdio>
#include "pvData.h"
#include "convert.h"
#include "factory.h"
#include "byteBuffer.h"
namespace epics { namespace pvData {
class BasePVBoolean : public PVBoolean {
public:
BasePVBoolean(PVStructure *parent,ScalarConstPtr scalar);
virtual ~BasePVBoolean();
virtual bool get();
virtual void put(bool val);
virtual void serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher);
virtual void deserialize(ByteBuffer *pbuffer,
DeserializableControl *pflusher);
virtual bool operator==(PVField& pv) ;
virtual bool operator!=(PVField& pv) ;
private:
bool value;
};
BasePVBoolean::BasePVBoolean(PVStructure *parent,ScalarConstPtr scalar)
: PVBoolean(parent,scalar),value(false)
{}
BasePVBoolean::~BasePVBoolean() {}
bool BasePVBoolean::get() { return value;}
void BasePVBoolean::put(bool val){value = val;}
void BasePVBoolean::serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher) {
pflusher->ensureBuffer(1);
pbuffer->putBoolean(value);
}
void BasePVBoolean::deserialize(ByteBuffer *pbuffer,
DeserializableControl *pflusher)
{
pflusher->ensureData(1);
value = pbuffer->getBoolean();
}
bool BasePVBoolean::operator==(PVField& pvField)
{
return getConvert()->equals(this, &pvField);
}
bool BasePVBoolean::operator!=(PVField& pvField)
{
return !(getConvert()->equals(this, &pvField));
}
}}

View File

@@ -1,66 +0,0 @@
/*PVByte.cpp*/
/**
* 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.
*/
#include <cstddef>
#include <cstdlib>
#include <string>
#include <cstdio>
#include "pvData.h"
#include "convert.h"
#include "factory.h"
#include "byteBuffer.h"
namespace epics { namespace pvData {
class BasePVByte : public PVByte {
public:
BasePVByte(PVStructure *parent,ScalarConstPtr scalar);
virtual ~BasePVByte();
virtual int8 get();
virtual void put(int8 val);
virtual void serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher) ;
virtual void deserialize(ByteBuffer *pbuffer,
DeserializableControl *pflusher);
virtual bool operator==(PVField& pv) ;
virtual bool operator!=(PVField& pv) ;
private:
int8 value;
};
BasePVByte::BasePVByte(PVStructure *parent,ScalarConstPtr scalar)
: PVByte(parent,scalar),value(0)
{}
BasePVByte::~BasePVByte() {}
int8 BasePVByte::get() { return value;}
void BasePVByte::put(int8 val){value = val;}
void BasePVByte::serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher) {
pflusher->ensureBuffer(1);
pbuffer->putByte(value);
}
void BasePVByte::deserialize(ByteBuffer *pbuffer,
DeserializableControl *pflusher) {
pflusher->ensureData(1);
value = pbuffer->getByte();
}
bool BasePVByte::operator==(PVField& pvField)
{
return getConvert()->equals(this, &pvField);
}
bool BasePVByte::operator!=(PVField& pvField)
{
return !(getConvert()->equals(this, &pvField));
}
}}

View File

@@ -1,66 +0,0 @@
/*BasePVDouble.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.
*/
#include <cstddef>
#include <cstdlib>
#include <string>
#include <cstdio>
#include "pvData.h"
#include "convert.h"
#include "factory.h"
#include "byteBuffer.h"
namespace epics { namespace pvData {
class BasePVDouble : public PVDouble {
public:
BasePVDouble(PVStructure *parent,ScalarConstPtr scalar);
virtual ~BasePVDouble();
virtual double get();
virtual void put(double val);
virtual void serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher) ;
virtual void deserialize(ByteBuffer *pbuffer,
DeserializableControl *pflusher);
virtual bool operator==(PVField& pv) ;
virtual bool operator!=(PVField& pv) ;
private:
double value;
};
BasePVDouble::BasePVDouble(PVStructure *parent,ScalarConstPtr scalar)
: PVDouble(parent,scalar),value(0.0)
{}
BasePVDouble::~BasePVDouble() {}
double BasePVDouble::get() { return value;}
void BasePVDouble::put(double val){value = val;}
void BasePVDouble::serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher) {
pflusher->ensureBuffer(sizeof(double));
pbuffer->putDouble(value);
}
void BasePVDouble::deserialize(ByteBuffer *pbuffer,
DeserializableControl *pflusher) {
pflusher->ensureData(sizeof(double));
value = pbuffer->getDouble();
}
bool BasePVDouble::operator==(PVField& pvField)
{
return getConvert()->equals(this, &pvField);
}
bool BasePVDouble::operator!=(PVField& pvField)
{
return !(getConvert()->equals(this, &pvField));
}
}}

View File

@@ -1,66 +0,0 @@
/*PVFloat.cpp*/
/**
* 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.
*/
#include <cstddef>
#include <cstdlib>
#include <string>
#include <cstdio>
#include "pvData.h"
#include "convert.h"
#include "factory.h"
#include "byteBuffer.h"
namespace epics { namespace pvData {
class BasePVFloat : public PVFloat {
public:
BasePVFloat(PVStructure *parent,ScalarConstPtr scalar);
virtual ~BasePVFloat();
virtual float get();
virtual void put(float val);
virtual void serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher) ;
virtual void deserialize(ByteBuffer *pbuffer,
DeserializableControl *pflusher);
virtual bool operator==(PVField& pv) ;
virtual bool operator!=(PVField& pv) ;
private:
float value;
};
BasePVFloat::BasePVFloat(PVStructure *parent,ScalarConstPtr scalar)
: PVFloat(parent,scalar),value(0.0)
{}
BasePVFloat::~BasePVFloat() {}
float BasePVFloat::get() { return value;}
void BasePVFloat::put(float val){value = val;}
void BasePVFloat::serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher) {
pflusher->ensureBuffer(sizeof(float));
pbuffer->putFloat(value);
}
void BasePVFloat::deserialize(ByteBuffer *pbuffer,
DeserializableControl *pflusher) {
pflusher->ensureData(sizeof(float));
value = pbuffer->getFloat();
}
bool BasePVFloat::operator==(PVField& pvField)
{
return getConvert()->equals(this, &pvField);
}
bool BasePVFloat::operator!=(PVField& pvField)
{
return !(getConvert()->equals(this, &pvField));
}
}}

View File

@@ -1,66 +0,0 @@
/*PVInt.cpp*/
/**
* 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.
*/
#include <cstddef>
#include <cstdlib>
#include <string>
#include <cstdio>
#include "pvData.h"
#include "convert.h"
#include "factory.h"
#include "byteBuffer.h"
namespace epics { namespace pvData {
class BasePVInt : public PVInt {
public:
BasePVInt(PVStructure *parent,ScalarConstPtr scalar);
virtual ~BasePVInt();
virtual int32 get();
virtual void put(int32 val);
virtual void serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher) ;
virtual void deserialize(ByteBuffer *pbuffer,
DeserializableControl *pflusher);
virtual bool operator==(PVField& pv) ;
virtual bool operator!=(PVField& pv) ;
private:
int32 value;
};
BasePVInt::BasePVInt(PVStructure *parent,ScalarConstPtr scalar)
: PVInt(parent,scalar),value(0)
{}
BasePVInt::~BasePVInt() {}
int32 BasePVInt::get() { return value;}
void BasePVInt::put(int32 val){value = val;}
void BasePVInt::serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher) {
pflusher->ensureBuffer(sizeof(int32));
pbuffer->putInt(value);
}
void BasePVInt::deserialize(ByteBuffer *pbuffer,
DeserializableControl *pflusher) {
pflusher->ensureData(sizeof(int32));
value = pbuffer->getInt();
}
bool BasePVInt::operator==(PVField& pvField)
{
return getConvert()->equals(this, &pvField);
}
bool BasePVInt::operator!=(PVField& pvField)
{
return !(getConvert()->equals(this, &pvField));
}
}}

View File

@@ -1,66 +0,0 @@
/*PVLong.cpp*/
/**
* 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.
*/
#include <cstddef>
#include <cstdlib>
#include <string>
#include <cstdio>
#include "pvData.h"
#include "convert.h"
#include "factory.h"
#include "byteBuffer.h"
namespace epics { namespace pvData {
class BasePVLong : public PVLong {
public:
BasePVLong(PVStructure *parent,ScalarConstPtr scalar);
virtual ~BasePVLong();
virtual int64 get();
virtual void put(int64 val);
virtual void serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher) ;
virtual void deserialize(ByteBuffer *pbuffer,
DeserializableControl *pflusher);
virtual bool operator==(PVField& pv) ;
virtual bool operator!=(PVField& pv) ;
private:
int64 value;
};
BasePVLong::BasePVLong(PVStructure *parent,ScalarConstPtr scalar)
: PVLong(parent,scalar),value(0)
{}
BasePVLong::~BasePVLong() {}
int64 BasePVLong::get() { return value;}
void BasePVLong::put(int64 val){value = val;}
void BasePVLong::serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher) {
pflusher->ensureBuffer(sizeof(int64));
pbuffer->putLong(value);
}
void BasePVLong::deserialize(ByteBuffer *pbuffer,
DeserializableControl *pflusher) {
pflusher->ensureData(sizeof(int64));
value = pbuffer->getLong();
}
bool BasePVLong::operator==(PVField& pvField)
{
return getConvert()->equals(this, &pvField);
}
bool BasePVLong::operator!=(PVField& pvField)
{
return !(getConvert()->equals(this, &pvField));
}
}}

View File

@@ -1,66 +0,0 @@
/*PVShort.cpp*/
/**
* 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.
*/
#include <cstddef>
#include <cstdlib>
#include <string>
#include <cstdio>
#include "pvData.h"
#include "convert.h"
#include "factory.h"
#include "byteBuffer.h"
namespace epics { namespace pvData {
class BasePVShort : public PVShort {
public:
BasePVShort(PVStructure *parent,ScalarConstPtr scalar);
virtual ~BasePVShort();
virtual int16 get();
virtual void put(int16 val);
virtual void serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher) ;
virtual void deserialize(ByteBuffer *pbuffer,
DeserializableControl *pflusher);
virtual bool operator==(PVField& pv) ;
virtual bool operator!=(PVField& pv) ;
private:
int16 value;
};
BasePVShort::BasePVShort(PVStructure *parent,ScalarConstPtr scalar)
: PVShort(parent,scalar),value(0)
{}
BasePVShort::~BasePVShort() {}
int16 BasePVShort::get() { return value;}
void BasePVShort::put(int16 val){value = val;}
void BasePVShort::serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher) {
pflusher->ensureBuffer(sizeof(int16));
pbuffer->putShort(value);
}
void BasePVShort::deserialize(ByteBuffer *pbuffer,
DeserializableControl *pflusher) {
pflusher->ensureData(sizeof(int16));
value = pbuffer->getShort();
}
bool BasePVShort::operator==(PVField& pvField)
{
return getConvert()->equals(this, &pvField);
}
bool BasePVShort::operator!=(PVField& pvField)
{
return !(getConvert()->equals(this, &pvField));
}
}}

View File

@@ -1,65 +0,0 @@
/*PVString.cpp*/
/**
* 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.
*/
#include <cstddef>
#include <cstdlib>
#include <string>
#include <cstdio>
#include "pvData.h"
#include "convert.h"
#include "factory.h"
#include "byteBuffer.h"
#include "serializeHelper.h"
namespace epics { namespace pvData {
class BasePVString : public PVString {
public:
BasePVString(PVStructure *parent,ScalarConstPtr scalar);
virtual ~BasePVString();
virtual String get();
virtual void put(String val);
virtual void serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher) ;
virtual void deserialize(ByteBuffer *pbuffer,
DeserializableControl *pflusher);
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) {
SerializeHelper::serializeString(value, pbuffer, pflusher);
}
void BasePVString::deserialize(ByteBuffer *pbuffer,
DeserializableControl *pflusher) {
value = SerializeHelper::deserializeString(pbuffer, pflusher);
}
bool BasePVString::operator==(PVField& pvField)
{
return getConvert()->equals(this, &pvField);
}
bool BasePVString::operator!=(PVField& pvField)
{
return !(getConvert()->equals(this, &pvField));
}
}}

View File

@@ -18,13 +18,6 @@
#include "PVArray.cpp"
#include "PVScalarArray.cpp"
#include "PVStructure.cpp"
#include "DefaultPVBoolean.cpp"
#include "DefaultPVByte.cpp"
#include "DefaultPVShort.cpp"
#include "DefaultPVInt.cpp"
#include "DefaultPVLong.cpp"
#include "DefaultPVFloat.cpp"
#include "DefaultPVDouble.cpp"
#include "DefaultPVString.cpp"
#include "DefaultPVBooleanArray.cpp"
#include "DefaultPVByteArray.cpp"
@@ -42,6 +35,99 @@ static Convert* convert = 0;
static FieldCreate * fieldCreate = 0;
static PVDataCreate* pvDataCreate = 0;
/** Default storage for scalar values
*/
template<typename T>
class BasePVScalar : public PVScalarValue<T> {
public:
typedef T value_type;
typedef T* pointer;
typedef const T* const_pointer;
BasePVScalar(PVStructure *parent,ScalarConstPtr scalar);
virtual ~BasePVScalar();
virtual T get();
virtual void put(T val);
virtual void serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher);
virtual void deserialize(ByteBuffer *pbuffer,
DeserializableControl *pflusher);
virtual bool operator==(PVField& pv) ;
virtual bool operator!=(PVField& pv) ;
private:
T value;
};
template<typename T>
BasePVScalar<T>::BasePVScalar(PVStructure *parent,ScalarConstPtr scalar)
: PVScalarValue<T>(parent,scalar),value(0)
{}
//Note: '0' is a suitable default for all POD types (not String)
template<typename T>
BasePVScalar<T>::~BasePVScalar() {}
template<typename T>
T BasePVScalar<T>::get() { return value;}
template<typename T>
void BasePVScalar<T>::put(T val){value = val;}
template<typename T>
void BasePVScalar<T>::serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher) {
pflusher->ensureBuffer(1);
pbuffer->putBoolean(value);
}
template<typename T>
void BasePVScalar<T>::deserialize(ByteBuffer *pbuffer,
DeserializableControl *pflusher)
{
pflusher->ensureData(1);
value = pbuffer->getBoolean();
}
template<typename T>
bool BasePVScalar<T>::operator==(PVField& pvField)
{
return getConvert()->equals(this, &pvField);
}
template<typename T>
bool BasePVScalar<T>::operator!=(PVField& pvField)
{
return !(getConvert()->equals(this, &pvField));
}
// Specializations for scalar String
template<>
BasePVScalar<String>::BasePVScalar(PVStructure *parent,ScalarConstPtr scalar)
: PVScalarValue<String>(parent,scalar),value()
{}
template<>
void BasePVScalar<String>::serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher) {
SerializeHelper::serializeString(value, pbuffer, pflusher);
}
template<>
void BasePVScalar<String>::deserialize(ByteBuffer *pbuffer,
DeserializableControl *pflusher) {
value = SerializeHelper::deserializeString(pbuffer, pflusher);
}
typedef BasePVScalar<bool> BasePVBoolean;
typedef BasePVScalar<int8> BasePVByte;
typedef BasePVScalar<int16> BasePVShort;
typedef BasePVScalar<int32> BasePVInt;
typedef BasePVScalar<int64> BasePVLong;
typedef BasePVScalar<float> BasePVFloat;
typedef BasePVScalar<double> BasePVDouble;
typedef BasePVScalar<String> BasePVString;
PVDataCreate::PVDataCreate(){ }
PVField *PVDataCreate::createPVField(PVStructure *parent,