using new copy API

This commit is contained in:
Matej Sekoranja
2015-02-18 10:03:18 +01:00
parent 1d58caf40d
commit c8c0498cdf
11 changed files with 17 additions and 183 deletions

View File

@@ -85,143 +85,6 @@ 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::tr1::static_pointer_cast<PVUnionArray>(from);
PVUnionArray::shared_pointer toS = std::tr1::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 ?
maskBitSet->nextClearBit(static_cast<uint32>(offset)) :
maskBitSet->nextSetBit(static_cast<uint32>(offset));
// no more changes or no changes in this structure
if(next<0||next>=static_cast<int32>(offset+numberFields)) return;
// entire structure
if(static_cast<int32>(offset)==next) {
copyStructureUnchecked(from, to);
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];
offset = pvField->getFieldOffset();
int32 inumberFields = static_cast<int32>(pvField->getNumberFields());
next = inverse ?
maskBitSet->nextClearBit(static_cast<uint32>(offset)) :
maskBitSet->nextSetBit(static_cast<uint32>(offset));
// no more changes
if(next<0) return;
// no change in this pvField
if(next>=static_cast<int32>(offset+inumberFields)) continue;
// 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]);
partialCopy(fromPVStructure, toPVStructure, maskBitSet, inverse);
}
}
}
}}