2) implemented Lock. See effective C++ item 14.
This is as easy to use as Java synchronize.
3) wrapper on top of std::string. All usage of string in pvData is one of:
String - Just a std::string
StringBuilder - Used where StringBuilder is used in Java
StringConst - Just a "std::string const". This is used wherever String is used in Java
StringConstArray - Just like a String[] in Java.
4) The reference counting (incReferenceCount and decReferenceCount) are now private. It is completely handled by the implenentaion.
NO code that uses pvData needs even know about reference counting.
167 lines
5.1 KiB
C++
167 lines
5.1 KiB
C++
/*PVDataCreateFactory.cpp*/
|
|
#include <cstddef>
|
|
#include <cstdlib>
|
|
#include <string>
|
|
#include <cstdio>
|
|
#include <lock.h>
|
|
#include "pvData.h"
|
|
#include "convert.h"
|
|
#include "factory.h"
|
|
#include "AbstractPVField.h"
|
|
#include "AbstractPVScalar.h"
|
|
#include "AbstractPVArray.h"
|
|
#include "AbstractPVScalarArray.h"
|
|
#include "BasePVDouble.h"
|
|
#include "AbstractPVArray.h"
|
|
#include "BasePVDoubleArray.h"
|
|
#include "BasePVStructure.h"
|
|
#include "BasePVStructureArray.h"
|
|
|
|
namespace epics { namespace pvData {
|
|
|
|
static FieldCreate * fieldCreate = 0;
|
|
static PVDataCreate* pvDataCreate = 0;
|
|
|
|
PVDataCreate::PVDataCreate(){};
|
|
|
|
PVField *PVDataCreate::createPVField(PVStructure *parent,
|
|
FieldConstPtr field)
|
|
{
|
|
switch(field->getType()) {
|
|
case scalar:
|
|
return createPVScalar(parent,(ScalarConstPtr)field);
|
|
case scalarArray:
|
|
return (PVField *)createPVScalarArray(parent,
|
|
(ScalarArrayConstPtr)field);
|
|
case structure:
|
|
return (PVField *)createPVStructure(parent,
|
|
(StructureConstPtr)field);
|
|
case structureArray:
|
|
return createPVStructureArray(parent,
|
|
(StructureArrayConstPtr)field);
|
|
}
|
|
String message("PVDataCreate::createPVField");
|
|
throw std::invalid_argument(message);
|
|
};
|
|
|
|
PVField *PVDataCreate::createPVField(PVStructure *parent,
|
|
StringConst fieldName,PVField * fieldToClone)
|
|
{
|
|
switch(fieldToClone->getField()->getType()) {
|
|
case scalar:
|
|
return createPVScalar(parent,fieldName,(PVScalar*)fieldToClone);
|
|
case scalarArray:
|
|
return (PVField *)createPVScalarArray(parent,fieldName,
|
|
(PVScalarArray *)fieldToClone);
|
|
case structure:
|
|
return (PVField *)createPVStructure(parent,fieldName,
|
|
(PVStructure *)fieldToClone);
|
|
case structureArray:
|
|
String message(
|
|
"PVDataCreate::createPVField structureArray not valid fieldToClone");
|
|
throw std::invalid_argument(message);
|
|
}
|
|
String message("PVDataCreate::createPVField");
|
|
throw std::logic_error(message);
|
|
};
|
|
|
|
PVScalar *PVDataCreate::createPVScalar(PVStructure *parent,ScalarConstPtr scalar)
|
|
{
|
|
ScalarType scalarType = scalar->getScalarType();
|
|
switch(scalarType) {
|
|
case pvDouble:
|
|
return new BasePVDouble(parent,scalar);
|
|
default:
|
|
throw std::logic_error(notImplemented);
|
|
}
|
|
throw std::logic_error(notImplemented);
|
|
};
|
|
|
|
PVScalar *PVDataCreate::createPVScalar(PVStructure *parent,
|
|
StringConst fieldName,ScalarType scalarType)
|
|
{
|
|
if(fieldCreate==0) fieldCreate = getFieldCreate();
|
|
ScalarConstPtr scalar = fieldCreate->createScalar(fieldName,scalarType);
|
|
return createPVScalar(parent,scalar);
|
|
};
|
|
|
|
PVScalar *PVDataCreate::createPVScalar(PVStructure *parent,
|
|
StringConst fieldName,PVScalar * scalarToClone)
|
|
{
|
|
PVScalar *pvScalar = createPVScalar(parent,fieldName,
|
|
scalarToClone->getScalar()->getScalarType());
|
|
//MARTY MUST CALL CONVERT
|
|
//MARTY MUST COPY AUXInfo
|
|
return pvScalar;
|
|
};
|
|
|
|
PVScalarArray *PVDataCreate::createPVScalarArray(PVStructure *parent,
|
|
ScalarArrayConstPtr scalarArray)
|
|
{
|
|
switch(scalarArray->getElementType()) {
|
|
case pvBoolean: break;
|
|
case pvByte: break;
|
|
case pvShort: break;
|
|
case pvInt: break;
|
|
case pvLong: break;
|
|
case pvFloat: break;
|
|
case pvDouble:
|
|
return new BasePVDoubleArray(parent,scalarArray);
|
|
case pvString: break;
|
|
}
|
|
throw std::logic_error(notImplemented);
|
|
|
|
};
|
|
|
|
PVScalarArray *PVDataCreate::createPVScalarArray(PVStructure *parent,
|
|
StringConst fieldName,ScalarType elementType)
|
|
{
|
|
throw std::logic_error(notImplemented);
|
|
};
|
|
|
|
PVScalarArray *PVDataCreate::createPVScalarArray(PVStructure *parent,
|
|
StringConst fieldName,PVScalarArray * scalarArrayToClone)
|
|
{
|
|
throw std::logic_error(notImplemented);
|
|
};
|
|
|
|
PVStructureArray *PVDataCreate::createPVStructureArray(PVStructure *parent,
|
|
StructureArrayConstPtr structureArray)
|
|
{
|
|
throw std::logic_error(notImplemented);
|
|
};
|
|
|
|
PVStructure *PVDataCreate::createPVStructure(PVStructure *parent,
|
|
StructureConstPtr structure)
|
|
{
|
|
return new BasePVStructure(parent,structure);
|
|
};
|
|
|
|
PVStructure *PVDataCreate::createPVStructure(PVStructure *parent,
|
|
StringConst fieldName,FieldConstPtrArray fields)
|
|
{
|
|
throw std::logic_error(notImplemented);
|
|
};
|
|
|
|
PVStructure *PVDataCreate::createPVStructure(PVStructure *parent,
|
|
StringConst fieldName,PVStructure *structToClone)
|
|
{
|
|
throw std::logic_error(notImplemented);
|
|
};
|
|
|
|
|
|
class PVDataCreateExt : public PVDataCreate {
|
|
public:
|
|
PVDataCreateExt(): PVDataCreate(){};
|
|
};
|
|
|
|
PVDataCreate * getPVDataCreate() {
|
|
static Mutex *mutex = new Mutex();
|
|
Lock xx(mutex);
|
|
|
|
if(pvDataCreate==0) pvDataCreate = new PVDataCreateExt();
|
|
return pvDataCreate;
|
|
}
|
|
|
|
}}
|