Serializing Controllers

When writing the ReferenceMaker::Load() and ReferenceMaker::Save() methods of a controller it is important that the before you read or write any custom data (i.e. chunks) that you call the Control::Load() and Control::Save() functions.

The following code demonstrates how this works:

#define LOCK_CHUNK  0x2535  //the lock value

IOResult IndePosition::Save(ISave *isave)
{
  Control::Save(isave);

  ULONG nb;
  int on = (mLocked==true) ? 1 :0;
  isave->BeginChunk(LOCK_CHUNK);
  isave->Write(&on, sizeof(on), &nb); 
  isave->EndChunk();   

  return IO_OK;
}

IOResult IndePosition::Load(ILoad *iload)
{
  ULONG nb;
  IOResult res;
  res = Control::Load(iload);
  if (res!=IO_OK) return res;
  while (IO_OK==(res=iload->OpenChunk()))
  {
    ULONG curID = iload->CurChunkID();
    if (curID==LOCK_CHUNK)
    {
       int on;
       res=iload->Read(&on, sizeof(on), &nb);      
       mLocked = on ? true : false;
    }
    iload->CloseChunk();
    if (res!=IO_OK)  return res;
  }
  return IO_OK; 
}

This is necessary so that the Control base clas is given a chance to serialize the before and after out of range type (ORT) values.