Creating and Changing References
 
 
 

The same mechanism is used for creating and changing (replacing) a reference. References from a reference maker to a reference target are created by first declaring a RefTargetHandle initialized to NULL, and then by calling ReferenceMaker::ReplaceReference() for each reference. The ReferenceMaker::ReplaceReference() method is also be used to reassign a reference instead of ReferenceMaker::SetReference().

Note: you should always initialize a RefTargetHandle to NULL before its first use.

The following sample code demonstrates these steps:

class MyRefMaker : publicReferenceMaker
{
private:
  // Note: RefTargetHandle is in fact a pointer to ReferenceTarget
  RefTargetHandle target;
 
public:
 
 MyRefMaker(RefTargetHandle ref)
    : target(NULL)
  {
    ReplaceReference(0, ref);
  }
 
  intNumRefs() {
     return 1;
  }  
 
  RefTargetHandle GetReference(int i) {
    assert(i == 0);
    return target;
  }
 
  voidSetReference(inti, RefTargetHandle rtarg) {
    assert(i==0) ;
    target = rtarg;
  }
 
  RefResult NotifyRefChanged(Interval changeInt, RefTargetHandle hTarget,
     PartID& partID, RefMessage message)
  {
     if (hTarget == target) {
        // perform processing according to the message        
     }     
  }
};