03.01.2013 Views

Chapter 1

Chapter 1

Chapter 1

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

void TShip::ExternalizeL(RWriteStream& aStream) const<br />

{<br />

aStream.WriteUint8L(iType);<br />

aStream.WriteInt8L(iLength);<br />

aStream.WriteInt8L(iRemaining);<br />

aStream.WriteInt8L(iStartX);<br />

aStream.WriteInt8L(iStartY);<br />

aStream.WriteInt8L(iDx);<br />

aStream.WriteInt8L(iDy);<br />

}<br />

The ship data is just a series of 8-bit integers. In all these functions, we don't expect the<br />

integer values to be more than 8 bits, so we specify this is what we want to store. This saves<br />

some space compared to storing a full 32 bits for each integer.<br />

Finally, the controller itself externalizes some extra persistent data: namely, its state and the<br />

current zoom factor:<br />

void CGameController::ExternalizeL(RWriteStream& aStream) const<br />

{<br />

aStream.WriteUint8L(iState);<br />

aStream.WriteInt32L(iZoomFactor);<br />

}<br />

Restoring the controller data<br />

We saw that the document's RestoreL() uses the controller's restoring NewL() function<br />

that takes CStreamStore and TStreamId arguments, which is coded as follows:<br />

CGameController* CGameController::NewL(const CStreamStore& aStore,<br />

{<br />

TStreamId aStreamId)<br />

CGameController* self = new(ELeave) CGameController;<br />

CleanupStack::PushL(self);<br />

self->RestoreL(aStore, aStreamId);<br />

CleanupStack::Pop();<br />

return self;<br />

}<br />

RestoreL() is private, like ConstructL(), so that it can't be accidentally called by<br />

CGameController's clients. Here it is:<br />

void CGameController::RestoreL(const CStreamStore& aStore, TStreamId<br />

aStreamId)<br />

{<br />

iEnv = CEikonEnv::Static();<br />

RStoreReadStream stream;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!