Cloning Reference Targets
 
 
 

If you wish to clone an object derived from ReferenceTarget you must use RemapDir::CloneRef() or ::CloneRefHierarchy() instead of ReferenceTarget::Clone(). This will correctly perform backpatching of references in the reference hierarchy. If backpatching is not performed, a reference graph can keep references to the original object, instead of to the copied object.

ReferenceTarget* Clone(ReferenceTarget* aTarget)
  {
    return CloneRefHierarchy(aTarget);
  }  
};

In some cases you may need to clone a group of references, in which case you would need to use an instance of RemapDir. The following code demonstrates such a scenario:

PRSControl& PRSControl::operator=(const PRSControl& ctrl) {
  RemapDir *remap = NewRemapDir();
  ReplaceReference(PRS_POS_REF,remap->CloneRef(ctrl.pos));
  ReplaceReference(PRS_ROT_REF,remap->CloneRef(ctrl.rot));
  ReplaceReference(PRS_SCL_REF,remap->CloneRef(ctrl.scl));
  
  // Make sure that if any sub-controller references this 
  // controller that it will get backpatched correctly  
  remap->AddEntry(ctrl,this);
  remap->DeleteThis();
  mLocked = ctrl.mLocked;
  return(*this);
}
See Also