unchecked copy
This commit is contained in:
@@ -4,8 +4,6 @@
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
|
||||
#include <pv/convert.h>
|
||||
|
||||
#define epicsExportSharedSymbols
|
||||
#include <pv/serializationHelper.h>
|
||||
#include <pv/introspectionRegistry.h>
|
||||
@@ -87,11 +85,99 @@ void SerializationHelper::serializeFull(ByteBuffer* buffer, SerializableControl*
|
||||
}
|
||||
}
|
||||
|
||||
ConvertPtr SerializationHelper::_convert(getConvert());
|
||||
|
||||
void SerializationHelper::copyUnchecked(
|
||||
epics::pvData::PVField::shared_pointer const & from,
|
||||
epics::pvData::PVField::shared_pointer const & to)
|
||||
{
|
||||
switch(from->getField()->getType())
|
||||
{
|
||||
case scalar:
|
||||
{
|
||||
PVScalar::shared_pointer fromS = std::tr1::static_pointer_cast<PVScalar>(from);
|
||||
PVScalar::shared_pointer toS = std::tr1::static_pointer_cast<PVScalar>(to);
|
||||
toS->assign(*fromS.get());
|
||||
break;
|
||||
}
|
||||
case scalarArray:
|
||||
{
|
||||
PVScalarArray::shared_pointer fromS = std::tr1::static_pointer_cast<PVScalarArray>(from);
|
||||
PVScalarArray::shared_pointer toS = std::tr1::static_pointer_cast<PVScalarArray>(to);
|
||||
toS->assign(*fromS.get());
|
||||
break;
|
||||
}
|
||||
case structure:
|
||||
{
|
||||
PVStructure::shared_pointer fromS = std::tr1::static_pointer_cast<PVStructure>(from);
|
||||
PVStructure::shared_pointer toS = std::tr1::static_pointer_cast<PVStructure>(to);
|
||||
copyStructureUnchecked(fromS, toS);
|
||||
break;
|
||||
}
|
||||
case structureArray:
|
||||
{
|
||||
PVStructureArray::shared_pointer fromS = std::tr1::static_pointer_cast<PVStructureArray>(from);
|
||||
PVStructureArray::shared_pointer toS = std::tr1::static_pointer_cast<PVStructureArray>(to);
|
||||
toS->replace(fromS->view());
|
||||
break;
|
||||
}
|
||||
case union_:
|
||||
{
|
||||
PVUnion::shared_pointer fromS = std::tr1::static_pointer_cast<PVUnion>(from);
|
||||
PVUnion::shared_pointer toS = std::tr1::static_pointer_cast<PVUnion>(to);
|
||||
_convert->copyUnion(fromS, toS);
|
||||
break;
|
||||
}
|
||||
case unionArray:
|
||||
{
|
||||
PVUnionArray::shared_pointer fromS = std::static_pointer_cast<PVUnionArray>(from);
|
||||
PVUnionArray::shared_pointer toS = std::static_pointer_cast<PVUnionArray>(to);
|
||||
toS->replace(fromS->view());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
throw std::logic_error("SerializationHelper::copyUnchecked unknown type");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SerializationHelper::copyStructureUnchecked(
|
||||
PVStructure::shared_pointer const & from,
|
||||
PVStructure::shared_pointer const & to)
|
||||
{
|
||||
|
||||
if (from.get() == to.get())
|
||||
return;
|
||||
|
||||
PVFieldPtrArray const & fromPVFields = from->getPVFields();
|
||||
PVFieldPtrArray const & toPVFields = to->getPVFields();
|
||||
|
||||
size_t fieldsSize = fromPVFields.size();
|
||||
for(size_t i = 0; i<fieldsSize; i++) {
|
||||
PVFieldPtr pvField = fromPVFields[i];
|
||||
int32 inumberFields = static_cast<int32>(pvField->getNumberFields());
|
||||
|
||||
// serialize field or fields
|
||||
if(inumberFields==1) {
|
||||
copyUnchecked(pvField, toPVFields[i]);
|
||||
} else {
|
||||
PVStructure::shared_pointer fromPVStructure = std::tr1::static_pointer_cast<PVStructure>(pvField);
|
||||
PVStructure::shared_pointer toPVStructure = std::tr1::static_pointer_cast<PVStructure>(toPVFields[i]);
|
||||
copyStructureUnchecked(fromPVStructure, toPVStructure);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SerializationHelper::partialCopy(PVStructure::shared_pointer const & from,
|
||||
PVStructure::shared_pointer const & to,
|
||||
BitSet::shared_pointer const & maskBitSet,
|
||||
bool inverse) {
|
||||
|
||||
if (from.get() == to.get())
|
||||
return;
|
||||
|
||||
size_t numberFields = from->getNumberFields();
|
||||
size_t offset = from->getFieldOffset();
|
||||
int32 next = inverse ?
|
||||
@@ -103,7 +189,7 @@ void SerializationHelper::partialCopy(PVStructure::shared_pointer const & from,
|
||||
|
||||
// entire structure
|
||||
if(static_cast<int32>(offset)==next) {
|
||||
getConvert()->copy(from, to);
|
||||
copyStructureUnchecked(from, to);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -126,7 +212,7 @@ void SerializationHelper::partialCopy(PVStructure::shared_pointer const & from,
|
||||
|
||||
// serialize field or fields
|
||||
if(inumberFields==1) {
|
||||
getConvert()->copy(pvField, toPVFields[i]);
|
||||
copyUnchecked(pvField, toPVFields[i]);
|
||||
} else {
|
||||
PVStructure::shared_pointer fromPVStructure = std::tr1::static_pointer_cast<PVStructure>(pvField);
|
||||
PVStructure::shared_pointer toPVStructure = std::tr1::static_pointer_cast<PVStructure>(toPVFields[i]);
|
||||
|
||||
Reference in New Issue
Block a user