Apple Developer Connection
Advanced Search
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page >

LStreamコードの変更

このセクションで説明する変更を加えると、LStreamが必ずデータをビッグエンディアンとして読み書きするようになります。これらの変更を行うと、以下の結果が得られます。

バイトスワップが必要かどうかを確認するには、必ずListing D-1内のすべてのメソッド呼び出し(これらのメソッドのサブクラス化されたバージョンへの呼び出しもすべて含む)を評価します。

Listing D-1  バイトスワップを必要とする可能性がある呼び出し

LStream::PutBytes
LStream::WriteData
LStream::WriteBlock
LStream::operator << (Handle inHandle)
LStream::GetBytes
LStream::ReadData
LStream::ReadBlock
LStream::PeekData
LStream::operator >> (Handle &outHandle)
LStream::WritePtr
LStream::ReadPtr
LStream::WriteHandle
LStream::ReadHandle

PPobリソースにカスタムクラスがある場合は、LStream::ReadDataの呼び出しを避けるためにLStreamコンストラクタを変更してください。具体的には、LControlLListBox、およびほかのPowerPlantクラスのLStreamコンストラクタを以下の各セクションで変更するのと同様に、コードを変更する必要があります。変更する必要があるファイル別に分類したセクションで、必要なコード変更について説明します。

LStream.h

単一のWriteBlock呼び出しのoperator << (const Rect &inRect)メソッドを以下のとおり変更します。

Rect rect;
rect.top = CFSwapInt16HostToBig(inRect.top);
rect.left = CFSwapInt16HostToBig(inRect.left);
rect.right= CFSwapInt16HostToBig(inRect.right);
rect.bottom = CFSwapInt16HostToBig(inRect.bottom);
WriteBlock(&rect, sizeof(rect));

単一のWriteBlock呼び出しのoperator << (const Point &inPoint)メソッドを以下のとおり変更します。

Point pt;
pt.v = CFSwapInt16HostToBig(inPoint.v);
pt.h = CFSwapInt16HostToBig(inPoint.h);
WriteBlock(&pt, sizeof(pt));

単一のWriteBlock呼び出しのoperator << (SInt16 inNum)メソッドを以下のとおり変更します。

SInt16 n;
n = CFSwapInt16HostToBig(inNum);
WriteBlock(&n, sizeof(n));

単一のWriteBlock呼び出しのoperator << (UInt16 inNum)メソッドを以下のとおり変更します。

UInt16 n;
n = CFSwapInt16HostToBig(inNum);
WriteBlock(&n, sizeof(n));

単一のWriteBlock呼び出しのoperator << (SInt32 inNum)メソッドを以下のとおり変更します。

SInt32 n;
n = CFSwapInt32HostToBig(inNum);
WriteBlock(&n, sizeof(n));

単一のWriteBlock呼び出しのoperator << (UInt32 inNum)メソッドを以下のとおり変更します。

UInt32 n;
n = CFSwapInt32HostToBig(inNum);
WriteBlock(&n, sizeof(n));

単一のWriteBlock呼び出しのoperator << (float inNum)メソッドを以下のとおり変更します。

CFSwappedFloat32 swappedFloat;
swappedFloat = CFConvertFloat32HostToSwapped(inNum);
WriteBlock(&swappedFloat, sizeof(swappedFloat));

単一のWriteBlock呼び出しのoperator << (bool inBool)メソッドを以下のとおり変更します。

UInt32 boolValue;
boolValue = CFSwapInt32HostToBig(inBool);
WriteBlock(&boolValue, sizeof(boolValue));

operator >> (Rect &outRect)メソッドで、ReadBlock呼び出しの後に以下を追加します。

outRect.top = CFSwapInt16BigToHost(outRect.top);
outRect.left = CFSwapInt16BigToHost(outRect.left);
outRect.right= CFSwapInt16BigToHost(outRect.right);
outRect.bottom = CFSwapInt16BigToHost(outRect.bottom);

operator >> (Point &outPoint)メソッドで、ReadBlock呼び出しの後に以下を追加します。

outPoint.v = CFSwapInt16BigToHost(outPoint.v);
outPoint.h = CFSwapInt16BigToHost(outPoint.h);

operator >> (SInt16 &outNum)メソッドで、ReadBlock呼び出しの後に以下を追加します。

outNum = CFSwapInt16BigToHost(outNum);

operator >> (UInt16 &outNum)メソッドで、ReadBlock呼び出しの後に以下を追加します。

outNum = CFSwapInt16BigToHost(outNum);

operator >> (SInt32 &outNum)メソッドで、ReadBlock呼び出しの後に以下を追加します。

outNum = CFSwapInt32BigToHost(outNum);

operator >> (UInt32 &outNum)メソッドで、ReadBlock呼び出しの後に以下を追加します。

outNum = CFSwapInt32BigToHost(outNum);

operator >> (float &outNum)メソッドで、ReadBlock呼び出しの後に以下を追加します。

CFSwappedFloat32 swappedFloat;
ReadBlock(&swappedFloat, sizeof(swappedFloat));
outNum = CFConvertFloat32SwappedToHost(swappedFloat);

operator >> (bool &outBool)メソッドで、ReadBlock呼び出しの後に以下を追加します。

UInt32 boolValue;
ReadBlock(&boolValue, sizeof(boolValue));
outBool = CFSwapInt32BigToHost(boolValue);

LStream.cp

operator << (double inNum)メソッドで、#if TARGET_CPU_PPCブロックを以下のとおり変更します。

#if TARGET_CPU_PPC || TARGET_CPU_X86
// PowerPCとインテルのdouble -- これらはすでに8バイトなので、
// 必要に応じてスワップして書き込む。
 
Assert_(sizeof(inNum) == 8);
CFSwappedFloat64 swappedDouble = CFConvertDoubleHostToSwapped(inNum);
WriteBlock(&swappedDouble, sizeof(swappedDouble));

operator >> (double& outNum)メソッドで、#if TARGET_CPU_PPCブロックを以下のとおり変更します。

#if TARGET_CPU_PPC || TARGET_CPU_X86
// PowerPCとインテルの double -- これらはすでに8バイトなので、
// 必要に応じて読み取ってスワップする。
 
Assert_(sizeof(outNum) == 8);
CFSwappedFloat64 swappedDouble;
ReadBlock(&swappedDouble, sizeof(swappedDouble));
outNum = CFConvertDoubleSwappedToHost(swappedDouble);

LControl.cp

LStreamコンストラクタで、次の行を置き換えます。

inStream->ReadData(&controlInfo, sizeof(SControlInfo));

以下の行に置き換えます。

*inStream >> controlInfo.valueMessage;
*inStream >> controlInfo.value;
*inStream >> controlInfo.minValue;
*inStream >> controlInfo.maxValue;

LListBox.cp

LStreamコンストラクタで、次の行を置き換えます。

inStream->ReadData(&listInfo, sizeof(SListBoxInfo));

以下の行に置き換えます。

*inStream >> listInfo.hasHorizScroll;
*inStream >> listInfo.hasVertScroll;
*inStream >> listInfo.hasGrow;
*inStream >> listInfo.hasFocusBox;
*inStream >> listInfo.doubleClickMessage;
*inStream >> listInfo.textTraitsID;
*inStream >> listInfo.LDEFid;
*inStream >> listInfo.numberOfItems;

RestorePlace(LStream *inPlace)メソッドで、次の行を置き換えます。

 inPlace->ReadData(&theRect, sizeof(Rect));

以下の行に置き換えます。

*inPlace >> theRect;

このメソッドをずっと下にスクロールして、if (vScroll != nil)という行のすぐ下にある次の行を置き換えます。

inPlace->ReadData(&theRect, sizeof(Rect));

以下の行に置き換えます。

*inPlace >> theRect;

もう一度同じメソッドの中で、if (hScroll != nil)という行のすぐ下にある次の行を置き換えます。

inPlace->ReadData(&theRect, sizeof(Rect));

以下の行に置き換えます。

*inPlace >> theRect;

LPane.cp

LStreamコンストラクタで、次の行を置き換えます。

inStream->ReadData(&thePaneInfo, sizeof(SPaneInfo));

以下の行に置き換えます。

SInt32 viewPtr;
*inStream >> thePaneInfo.paneID;
*inStream >> thePaneInfo.width;
*inStream >> thePaneInfo.height;
*inStream >> thePaneInfo.visible;
*inStream >> thePaneInfo.enabled;
*inStream >> thePaneInfo.bindings.left;
*inStream >> thePaneInfo.bindings.top;
*inStream >> thePaneInfo.bindings.right;
*inStream >> thePaneInfo.bindings.bottom;
*inStream >> thePaneInfo.left;
*inStream >> thePaneInfo.top;
*inStream >> thePaneInfo.userCon;
*inStream >> viewPtr;
thePaneInfo.superView = reinterpret_cast<LView *>(viewPtr);

LPrintout.cp

LStreamコンストラクタで、次の行を置き換えます。

inStream->ReadData(&thePrintoutInfo, sizeof(SPrintoutInfo));

以下の行に置き換えます。

*inStream >> thePrintoutInfo.width;
*inStream >> thePrintoutInfo.height;
*inStream >> thePrintoutInfo.active;
*inStream >> thePrintoutInfo.enabled;
*inStream >> thePrintoutInfo.userCon;
*inStream >> thePrintoutInfo.attributes;

LScroller.cp

LStreamコンストラクタで、次の行を置き換えます。

inStream->ReadData(&scrollerInfo, sizeof(SScrollerInfo));

以下の行に置き換えます。

*inStream >> scrollerInfo.horizBarLeftIndent;
*inStream >> scrollerInfo.horizBarRightIndent;
*inStream >> scrollerInfo.vertBarTopIndent;
*inStream >> scrollerInfo.vertBarBottomIndent;
*inStream >> scrollerInfo.scrollingViewID;

LTable.cp

LStreamコンストラクタで、次の行を置き換えます。

inStream->ReadData(&tableInfo, sizeof(STableInfo));

以下の行に置き換えます。

*inStream >> tableInfo.numberOfRows;
*inStream >> tableInfo.numberOfCols;
*inStream >> tableInfo.rowHeight;
*inStream >> tableInfo.colWidth;
*inStream >> tableInfo.cellDataSize;

LView.cp

LStreamコンストラクタで、次の行を置き換えます。

inStream->ReadData(&viewInfo, sizeof(SViewInfo));

以下の行に置き換えます。

*inStream >> viewInfo.imageSize.width;
*inStream >> viewInfo.imageSize.height;
*inStream >> viewInfo.scrollPos.h;
*inStream >> viewInfo.scrollPos.v;
*inStream >> viewInfo.scrollUnit.h;
*inStream >> viewInfo.scrollUnit.v;
*inStream >> viewInfo.reconcileOverhang;

LWindow.cp

LStreamコンストラクタで、次の行を置き換えます。

inStream->ReadData(&windowInfo, sizeof(SWindowInfo));

以下の行に置き換えます。

*inStream >> windowInfo.WINDid;
*inStream >> windowInfo.layer;
*inStream >> windowInfo.attributes;
*inStream >> windowInfo.minimumWidth;
*inStream >> windowInfo.minimumHeight;
*inStream >> windowInfo.maximumWidth;
*inStream >> windowInfo.maximumHeight;
*inStream >> windowInfo.standardSize.width;
*inStream >> windowInfo.standardSize.height;
*inStream >> windowInfo.userCon;

LPopupGroupBox.cp

LStreamコンストラクタで、次の行を置き換えます。

inStream->ReadData(&cInfo, sizeof(SControlInfo));

以下の行に置き換えます。

*inStream >> cInfo.valueMessage;
*inStream >> cInfo.value;
*inStream >> cInfo.minValue;
*inStream >> cInfo.maxValue;

LControlView.cp

LStreamコンストラクタで、次の行を置き換えます。

inStream->ReadData(&cInfo, sizeof(SControlInfo));

以下の行に置き換えます。

*inStream >> cInfo.valueMessage;
*inStream >> cInfo.value;
*inStream >> cInfo.minValue;
*inStream >> cInfo.maxValue;

LScrollerView.cp

LStreamコンストラクタで、次の行を置き換えます。

inStream->ReadData(&scrollerInfo, sizeof(SScrollerViewInfo));

以下の行に置き換えます。

*inStream >> scrollerInfo.horizBarLeftIndent;
*inStream >> scrollerInfo.horizBarRightIndent;
*inStream >> scrollerInfo.vertBarTopIndent;
*inStream >> scrollerInfo.vertBarBottomIndent;
*inStream >> scrollerInfo.scrollingViewID;

LPageController.cp

LStreamコンストラクタで、以下の行を置き換えます。

inStream->ReadData( &mBackColor, sizeof(RGBColor));
inStream->ReadData( &mFaceColor, sizeof(RGBColor));
inStream->ReadData( &mPushedTextColor, sizeof(RGBColor));

以下の行に置き換えます。

*inStream >> mBackColor.red;
*inStream >> mBackColor.green;
*inStream >> mBackColor.blue;
*inStream >> mFaceColor.red;
*inStream >> mFaceColor.green;
*inStream >> mFaceColor.blue;
*inStream >> mPushedTextColor.red;
*inStream >> mPushedTextColor.green;
*inStream >> mPushedTextColor.blue;


< Previous PageNext Page >


Last updated: 2006-03-08




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice