PVDataCreateFactory.cpp now complete
This commit is contained in:
@@ -34,169 +34,212 @@
|
||||
|
||||
namespace epics { namespace pvData {
|
||||
|
||||
static FieldCreate * fieldCreate = 0;
|
||||
static PVDataCreate* pvDataCreate = 0;
|
||||
static Convert* convert = 0;
|
||||
static FieldCreate * fieldCreate = 0;
|
||||
static PVDataCreate* pvDataCreate = 0;
|
||||
|
||||
PVDataCreate::PVDataCreate(){};
|
||||
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");
|
||||
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 should never get here");
|
||||
throw std::logic_error(message);
|
||||
}
|
||||
|
||||
PVField *PVDataCreate::createPVField(PVStructure *parent,
|
||||
String 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 should never get here");
|
||||
throw std::logic_error(message);
|
||||
}
|
||||
|
||||
PVField *PVDataCreate::createPVField(PVStructure *parent,
|
||||
String 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 pvBoolean:
|
||||
return new BasePVBoolean(parent,scalar);
|
||||
case pvByte:
|
||||
return new BasePVByte(parent,scalar);
|
||||
case pvShort:
|
||||
return new BasePVShort(parent,scalar);
|
||||
case pvInt:
|
||||
return new BasePVInt(parent,scalar);
|
||||
case pvLong:
|
||||
return new BasePVLong(parent,scalar);
|
||||
case pvFloat:
|
||||
return new BasePVFloat(parent,scalar);
|
||||
case pvDouble:
|
||||
return new BasePVDouble(parent,scalar);
|
||||
case pvString:
|
||||
return new BasePVString(parent,scalar);
|
||||
}
|
||||
String message("PVDataCreate::createPVScalar should never get here");
|
||||
throw std::logic_error(message);
|
||||
}
|
||||
|
||||
PVScalar *PVDataCreate::createPVScalar(PVStructure *parent,ScalarConstPtr scalar)
|
||||
{
|
||||
ScalarType scalarType = scalar->getScalarType();
|
||||
switch(scalarType) {
|
||||
case pvBoolean:
|
||||
return new BasePVBoolean(parent,scalar);
|
||||
case pvByte:
|
||||
return new BasePVByte(parent,scalar);
|
||||
case pvShort:
|
||||
return new BasePVShort(parent,scalar);
|
||||
case pvInt:
|
||||
return new BasePVInt(parent,scalar);
|
||||
case pvLong:
|
||||
return new BasePVLong(parent,scalar);
|
||||
case pvFloat:
|
||||
return new BasePVFloat(parent,scalar);
|
||||
case pvDouble:
|
||||
return new BasePVDouble(parent,scalar);
|
||||
case pvString:
|
||||
return new BasePVString(parent,scalar);
|
||||
default:
|
||||
throw std::logic_error(notImplemented);
|
||||
}
|
||||
throw std::logic_error(notImplemented);
|
||||
};
|
||||
|
||||
PVScalar *PVDataCreate::createPVScalar(PVStructure *parent,
|
||||
String fieldName,ScalarType scalarType)
|
||||
{
|
||||
if(fieldCreate==0) fieldCreate = getFieldCreate();
|
||||
ScalarConstPtr scalar = fieldCreate->createScalar(fieldName,scalarType);
|
||||
return createPVScalar(parent,scalar);
|
||||
};
|
||||
|
||||
PVScalar *PVDataCreate::createPVScalar(PVStructure *parent,
|
||||
String 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:
|
||||
return new BasePVBooleanArray(parent,scalarArray);
|
||||
case pvByte:
|
||||
return new BasePVByteArray(parent,scalarArray);
|
||||
case pvShort:
|
||||
return new BasePVShortArray(parent,scalarArray);
|
||||
case pvInt:
|
||||
return new BasePVIntArray(parent,scalarArray);
|
||||
case pvLong:
|
||||
return new BasePVLongArray(parent,scalarArray);
|
||||
case pvFloat:
|
||||
return new BasePVFloatArray(parent,scalarArray);
|
||||
case pvDouble:
|
||||
return new BasePVDoubleArray(parent,scalarArray);
|
||||
case pvString:
|
||||
return new BasePVStringArray(parent,scalarArray);
|
||||
}
|
||||
throw std::logic_error(notImplemented);
|
||||
|
||||
};
|
||||
|
||||
PVScalarArray *PVDataCreate::createPVScalarArray(PVStructure *parent,
|
||||
String fieldName,ScalarType elementType)
|
||||
{
|
||||
throw std::logic_error(notImplemented);
|
||||
};
|
||||
|
||||
PVScalarArray *PVDataCreate::createPVScalarArray(PVStructure *parent,
|
||||
String 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,
|
||||
String fieldName,FieldConstPtrArray fields)
|
||||
{
|
||||
throw std::logic_error(notImplemented);
|
||||
};
|
||||
|
||||
PVStructure *PVDataCreate::createPVStructure(PVStructure *parent,
|
||||
String fieldName,PVStructure *structToClone)
|
||||
{
|
||||
throw std::logic_error(notImplemented);
|
||||
};
|
||||
PVScalar *PVDataCreate::createPVScalar(PVStructure *parent,
|
||||
String fieldName,ScalarType scalarType)
|
||||
{
|
||||
if(fieldCreate==0) fieldCreate = getFieldCreate();
|
||||
ScalarConstPtr scalar = fieldCreate->createScalar(fieldName,scalarType);
|
||||
return createPVScalar(parent,scalar);
|
||||
}
|
||||
|
||||
|
||||
class PVDataCreateExt : public PVDataCreate {
|
||||
public:
|
||||
PVDataCreateExt(): PVDataCreate(){};
|
||||
};
|
||||
PVScalar *PVDataCreate::createPVScalar(PVStructure *parent,
|
||||
String fieldName,PVScalar * scalarToClone)
|
||||
{
|
||||
if(convert==0) convert = getConvert();
|
||||
PVScalar *pvScalar = createPVScalar(parent,fieldName,
|
||||
scalarToClone->getScalar()->getScalarType());
|
||||
convert->copyScalar(scalarToClone, pvScalar);
|
||||
PVScalarMap attributes = scalarToClone->getPVAuxInfo()->getInfos();
|
||||
PVAuxInfo *pvAttribute = pvScalar->getPVAuxInfo();
|
||||
PVScalarMapIter p;
|
||||
for(p=attributes.begin(); p!=attributes.end(); p++) {
|
||||
String key = p->first;
|
||||
PVScalar *fromAttribute = p->second;
|
||||
PVScalar *toAttribute = pvAttribute->createInfo(key,
|
||||
fromAttribute->getScalar()->getScalarType());
|
||||
convert->copyScalar(fromAttribute,toAttribute);
|
||||
}
|
||||
return pvScalar;
|
||||
}
|
||||
|
||||
PVDataCreate * getPVDataCreate() {
|
||||
static Mutex mutex = Mutex();
|
||||
Lock xx(&mutex);
|
||||
PVScalarArray *PVDataCreate::createPVScalarArray(PVStructure *parent,
|
||||
ScalarArrayConstPtr scalarArray)
|
||||
{
|
||||
switch(scalarArray->getElementType()) {
|
||||
case pvBoolean:
|
||||
return new BasePVBooleanArray(parent,scalarArray);
|
||||
case pvByte:
|
||||
return new BasePVByteArray(parent,scalarArray);
|
||||
case pvShort:
|
||||
return new BasePVShortArray(parent,scalarArray);
|
||||
case pvInt:
|
||||
return new BasePVIntArray(parent,scalarArray);
|
||||
case pvLong:
|
||||
return new BasePVLongArray(parent,scalarArray);
|
||||
case pvFloat:
|
||||
return new BasePVFloatArray(parent,scalarArray);
|
||||
case pvDouble:
|
||||
return new BasePVDoubleArray(parent,scalarArray);
|
||||
case pvString:
|
||||
return new BasePVStringArray(parent,scalarArray);
|
||||
}
|
||||
throw std::logic_error(notImplemented);
|
||||
|
||||
}
|
||||
|
||||
if(pvDataCreate==0) pvDataCreate = new PVDataCreateExt();
|
||||
return pvDataCreate;
|
||||
PVScalarArray *PVDataCreate::createPVScalarArray(PVStructure *parent,
|
||||
String fieldName,ScalarType elementType)
|
||||
{
|
||||
if(fieldCreate==0) fieldCreate = getFieldCreate();
|
||||
return createPVScalarArray(parent,
|
||||
fieldCreate->createScalarArray(fieldName, elementType));
|
||||
}
|
||||
|
||||
PVScalarArray *PVDataCreate::createPVScalarArray(PVStructure *parent,
|
||||
String fieldName,PVScalarArray * arrayToClone)
|
||||
{
|
||||
if(convert==0) convert = getConvert();
|
||||
PVScalarArray *pvArray = createPVScalarArray(parent,fieldName,
|
||||
arrayToClone->getScalarArray()->getElementType());
|
||||
convert->copyScalarArray(arrayToClone,0, pvArray,0,arrayToClone->getLength());
|
||||
PVScalarMap attributes = arrayToClone->getPVAuxInfo()->getInfos();
|
||||
PVAuxInfo *pvAttribute = pvArray->getPVAuxInfo();
|
||||
PVScalarMapIter p;
|
||||
for(p=attributes.begin(); p!=attributes.end(); p++) {
|
||||
String key = p->first;
|
||||
PVScalar *fromAttribute = p->second;
|
||||
PVScalar *toAttribute = pvAttribute->createInfo(key,
|
||||
fromAttribute->getScalar()->getScalarType());
|
||||
convert->copyScalar(fromAttribute,toAttribute);
|
||||
}
|
||||
return pvArray;
|
||||
}
|
||||
|
||||
PVStructureArray *PVDataCreate::createPVStructureArray(PVStructure *parent,
|
||||
StructureArrayConstPtr structureArray)
|
||||
{
|
||||
return new BasePVStructureArray(parent,structureArray);
|
||||
}
|
||||
|
||||
PVStructure *PVDataCreate::createPVStructure(PVStructure *parent,
|
||||
StructureConstPtr structure)
|
||||
{
|
||||
return new BasePVStructure(parent,structure);
|
||||
}
|
||||
|
||||
PVStructure *PVDataCreate::createPVStructure(PVStructure *parent,
|
||||
String fieldName,int numberFields,FieldConstPtrArray fields)
|
||||
{
|
||||
if(fieldCreate==0) fieldCreate = getFieldCreate();
|
||||
StructureConstPtr structure = fieldCreate->createStructure(
|
||||
fieldName,numberFields, fields);
|
||||
return new BasePVStructure(parent,structure);
|
||||
}
|
||||
|
||||
PVStructure *PVDataCreate::createPVStructure(PVStructure *parent,
|
||||
String fieldName,PVStructure *structToClone)
|
||||
{
|
||||
if(fieldCreate==0) fieldCreate = getFieldCreate();
|
||||
if(convert==0) convert = getConvert();
|
||||
FieldConstPtrArray fields = 0;
|
||||
int numberFields = 0;
|
||||
if(structToClone==0) {
|
||||
fields = new FieldConstPtr[0];
|
||||
} else {
|
||||
fields = structToClone->getStructure()->getFields();
|
||||
numberFields = structToClone->getStructure()->getNumberFields();
|
||||
}
|
||||
StructureConstPtr structure = fieldCreate->createStructure(fieldName,numberFields,fields);
|
||||
PVStructure *pvStructure = new BasePVStructure(parent,structure);
|
||||
if(structToClone!=0) convert->copyStructure(structToClone,pvStructure);
|
||||
return pvStructure;
|
||||
}
|
||||
|
||||
|
||||
class PVDataCreateExt : public PVDataCreate {
|
||||
public:
|
||||
PVDataCreateExt(): PVDataCreate(){}
|
||||
};
|
||||
|
||||
PVDataCreate * getPVDataCreate() {
|
||||
static Mutex mutex = Mutex();
|
||||
Lock xx(&mutex);
|
||||
|
||||
if(pvDataCreate==0) pvDataCreate = new PVDataCreateExt();
|
||||
return pvDataCreate;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user