copy schematic

This commit is contained in:
Matej Sekoranja
2015-02-11 11:30:39 +01:00
parent 388799d39d
commit a277a4fdd5
3 changed files with 19 additions and 4 deletions

View File

@@ -448,6 +448,8 @@ bool Convert::isCopyUnionCompatible(
return *(from.get()) == *(to.get());
}
static PVDataCreatePtr pvDataCreate = getPVDataCreate();
void Convert::copyUnion(PVUnionPtr const & from, PVUnionPtr const & to)
{
if(to->isImmutable()) {
@@ -462,14 +464,27 @@ void Convert::copyUnion(PVUnionPtr const & from, PVUnionPtr const & to)
PVFieldPtr fromValue = from->get();
if (from->getUnion()->isVariant())
{
to->set(from->get());
if (fromValue.get() == 0)
to->set(PVField::shared_pointer());
else
{
PVFieldPtr toValue = to->get();
if (toValue.get() == 0 || *toValue->getField() != *fromValue->getField())
{
toValue = pvDataCreate->createPVField(fromValue->getField());
to->set(toValue);
}
copy(fromValue, toValue);
}
}
else
{
if (fromValue.get() == 0)
to->select(PVUnion::UNDEFINED_INDEX);
else
to->set(from->getSelectedIndex(),from->get());
{
copy(fromValue, to->select(from->getSelectedIndex()));
}
}
}

View File

@@ -179,7 +179,7 @@ void PVStructureArray::deserialize(ByteBuffer *pbuffer,
data[i].reset();
}
else {
if(data[i].get()==NULL) {
if(data[i].get()==NULL || !data[i].unique()) {
data[i] = pvDataCreate->createPVStructure(structure);
}
data[i]->deserialize(pbuffer, pcontrol);

View File

@@ -178,7 +178,7 @@ void PVUnionArray::deserialize(ByteBuffer *pbuffer,
data[i].reset();
}
else {
if(data[i].get()==NULL) {
if(data[i].get()==NULL || !data[i].unique()) {
data[i] = pvDataCreate->createPVUnion(punion);
}
data[i]->deserialize(pbuffer, pcontrol);