CDumpContext クラスCDumpContext Class
人が読み取ることができる形式でテキストを出力するために、ストリームに依存した診断出力をサポートします。Supports stream-oriented diagnostic output in the form of human-readable text.
構文Syntax
class CDumpContext
メンバーMembers
パブリック コンストラクターPublic Constructors
名前Name | 説明Description |
---|---|
CDumpContext:: CDumpContextCDumpContext::CDumpContext | CDumpContext オブジェクトを構築します。Constructs a CDumpContext object. |
パブリック メソッドPublic Methods
名前Name | 説明Description |
---|---|
CDumpContext::D umpAsHexCDumpContext::DumpAsHex | 指定された項目を16進形式でダンプします。Dumps the indicated item in hexadecimal format. |
CDumpContext:: FlushCDumpContext::Flush | ダンプコンテキストバッファー内のすべてのデータをフラッシュします。Flushes any data in the dump context buffer. |
CDumpContext:: GetDepthCDumpContext::GetDepth | ダンプの深さに対応する整数を取得します。Gets an integer corresponding to the depth of the dump. |
CDumpContext:: HexDumpCDumpContext::HexDump | 配列に格納されているバイトを16進形式でダンプします。Dumps bytes contained in an array in hexadecimal format. |
CDumpContext:: SetDepthCDumpContext::SetDepth | ダンプの深さを設定します。Sets the depth of the dump. |
パブリック演算子Public Operators
名前Name | 説明Description |
---|---|
CDumpContext:: operator <<CDumpContext::operator << | 変数とオブジェクトをダンプコンテキストに挿入します。Inserts variables and objects into the dump context. |
解説Remarks
CDumpContext
に基底クラスがありません。CDumpContext
does not have a base class.
ダンプの大部分には、事前オブジェクトである afxDumpを使用でき CDumpContext
ます。You can use afxDump, a predeclared CDumpContext
object, for most of your dumping. afxDump
オブジェクトは、Microsoft Foundation Class ライブラリのデバッグバージョンでのみ使用できます。The afxDump
object is available only in the Debug version of the Microsoft Foundation Class Library.
いくつかのメモリ 診断サービス が afxDump
出力に使用します。Several of the memory diagnostic services use afxDump
for their output.
Windows 環境では、定義済みのオブジェクトからの出力は、 afxDump
概念的にはストリームに似て cerr
いますが、windows の関数を使用してデバッガーにルーティングされ OutputDebugString
ます。Under the Windows environment, the output from the predefined afxDump
object, conceptually similar to the cerr
stream, is routed to the debugger via the Windows function OutputDebugString
.
CDumpContext
クラスには、 << CObject
オブジェクトのデータをダンプするポインターのオーバーロードされた挿入 () 演算子があります。The CDumpContext
class has an overloaded insertion ( <<) operator for CObject
pointers that dumps the object's data. 派生オブジェクトにカスタムダンプ形式が必要な場合は、 CObject::D umpをオーバーライドします。If you need a custom dump format for a derived object, override CObject::Dump. ほとんどの Microsoft Foundation クラスは、オーバーライドさ Dump
れたメンバー関数を実装します。Most Microsoft Foundation classes implement an overridden Dump
member function.
、、など、から派生していないクラスには、、、などの CObject
CString
頻繁に CTime
CTimeSpan
CDumpContext
使用される構造と同様に、独自のオーバーロードされた挿入演算子があり CFileStatus
CPoint
CRect
ます。Classes that are not derived from CObject
, such as CString
, CTime
, and CTimeSpan
, have their own overloaded CDumpContext
insertion operators, as do often-used structures such as CFileStatus
, CPoint
, and CRect
.
クラスの実装で IMPLEMENT_DYNAMIC または IMPLEMENT_SERIAL マクロを使用すると、は、 CObject::Dump
派生クラスの名前を出力し CObject
ます。If you use the IMPLEMENT_DYNAMIC or IMPLEMENT_SERIAL macro in the implementation of your class, then CObject::Dump
will print the name of your CObject
-derived class. それ以外の場合は印刷され CObject
ます。Otherwise, it will print CObject
.
クラスは、 CDumpContext
ライブラリのデバッグバージョンとリリースバージョンの両方で使用できますが、 Dump
メンバー関数はデバッグバージョンでのみ定義されています。The CDumpContext
class is available with both the Debug and Release versions of the library, but the Dump
member function is defined only in the Debug version. #Ifdef _DEBUG ステートメントを使用して / #endif
、カスタムメンバー関数を含む診断コードをかっこで囲み Dump
ます。Use #ifdef _DEBUG / #endif
statements to bracket your diagnostic code, including your custom Dump
member functions.
独自のオブジェクトを作成する前に CDumpContext
、 CFile
ダンプ先として機能するオブジェクトを作成する必要があります。Before you create your own CDumpContext
object, you must create a CFile
object that serves as the dump destination.
の詳細につい CDumpContext
ては、「 MFC アプリケーションのデバッグ」を参照してください。For more information on CDumpContext
, see Debugging MFC Applications.
#define _DEBUG#define _DEBUG
継承階層Inheritance Hierarchy
CDumpContext
要件Requirements
ヘッダー: afxHeader: afx.h
CDumpContext:: CDumpContextCDumpContext::CDumpContext
クラスのオブジェクトを構築 CDumpContext
します。Constructs an object of class CDumpContext
.
CDumpContext(CFile* pFile = NULL);
パラメーターParameters
pFilepFile
CFile
ダンプ先のオブジェクトへのポインター。A pointer to the CFile
object that is the dump destination.
解説Remarks
afxDump
オブジェクトは自動的に構築されます。The afxDump
object is constructed automatically.
ダンプコンテキストがアクティブになっている間は、基になるに書き込みません CFile
。それ以外の場合は、ダンプの影響を受けることになります。Do not write to the underlying CFile
while the dump context is active; otherwise, you will interfere with the dump. Windows 環境では、出力は Windows の関数を介してデバッガーにルーティングされ OutputDebugString
ます。Under the Windows environment, the output is routed to the debugger via the Windows function OutputDebugString
.
例Example
CFile f;
if (!f.Open(_T("dump.txt"), CFile::modeCreate | CFile::modeWrite))
{
AFXDUMP(_T("Unable to open file\n"));
exit(1);
}
CDumpContext dc(&f);
CDumpContext::D umpAsHexCDumpContext::DumpAsHex
指定された型を16進数値としてダンプします。Dumps the specified type formatted as hexadecimal numbers.
CDumpContext& DumpAsHex(BYTE b);
CDumpContext& DumpAsHex(DWORD dw);
CDumpContext& DumpAsHex(int n);
CDumpContext& DumpAsHex(LONG l);
CDumpContext& DumpAsHex(LONGLONG n);
CDumpContext& DumpAsHex(UINT u);
CDumpContext& DumpAsHex(ULONGLONG n);
CDumpContext& DumpAsHex(WORD w);
戻り値Return Value
CDumpContext
オブジェクトへの参照です。A reference to a CDumpContext
object.
解説Remarks
このメンバー関数を呼び出して、指定した型の項目を16進数値としてダンプします。Call this member function to dump the item of the specified type as a hexadecimal number. 配列をダンプするには、 CDumpContext:: HexDumpを呼び出します。To dump an array, call CDumpContext::HexDump.
例Example
#if _DEBUG
afxDump.DumpAsHex(115);
#endif
CDumpContext:: FlushCDumpContext::Flush
バッファー内の残りのデータを、ダンプコンテキストにアタッチされたファイルに強制的に書き込むようにします。Forces any data remaining in buffers to be written to the file attached to the dump context.
void Flush();
例Example
#if _DEBUG
afxDump.Flush();
#endif
CDumpContext:: GetDepthCDumpContext::GetDepth
Deep または浅いダンプが処理中かどうかを判断します。Determines whether a deep or shallow dump is in process.
int GetDepth() const;
戻り値Return Value
によって設定されたダンプの深さ SetDepth
。The depth of the dump as set by SetDepth
.
例Example
Setdepthの例を参照してください。See the example for SetDepth.
CDumpContext:: HexDumpCDumpContext::HexDump
16進数値として書式設定されたバイトの配列をダンプします。Dumps an array of bytes formatted as hexadecimal numbers.
void HexDump(
LPCTSTR lpszLine,
BYTE* pby,
int nBytes,
int nWidth);
パラメーターParameters
lpszLinelpszLine
新しい行の先頭に出力する文字列。A string to output at the start of a new line.
pbypby
ダンプするバイトを格納しているバッファーへのポインター。A pointer to a buffer containing the bytes to dump.
nBytesnBytes
ダンプするバイト数。The number of bytes to dump.
nWidthnWidth
行ごとにダンプされる最大バイト数 (出力行の幅ではありません)。Maximum number of bytes dumped per line (not the width of the output line).
解説Remarks
1つの特定の項目の種類を16進数としてダンプするには、 CDumpContext::D umpashexを呼び出します。To dump a single, specific item type as a hexadecimal number, call CDumpContext::DumpAsHex.
例Example
#if _DEBUG
TCHAR test[] = _T("This is a test of CDumpContext::HexDump\n");
afxDump.HexDump(_T("."), (BYTE *)test, sizeof(test), 20);
#endif
CDumpContext:: operator <<CDumpContext::operator <<
指定されたデータをダンプコンテキストに出力します。Outputs the specified data to the dump context.
CDumpContext& operator<<(const CObject* pOb);
CDumpContext& operator<<(const CObject& ob);
CDumpContext& operator<<(LPCTSTR lpsz);
CDumpContext& operator<<(const void* lp);
CDumpContext& operator<<(BYTE by);
CDumpContext& operator<<(WORD w);
CDumpContext& operator<<(DWORD dw);
CDumpContext& operator<<(int n);
CDumpContext& operator<<(double d);
CDumpContext& operator<<(float f);
CDumpContext& operator<<(LONG l);
CDumpContext& operator<<(UINT u);
CDumpContext& operator<<(LPCWSTR lpsz);
CDumpContext& operator<<(LPCSTR lpsz);
CDumpContext& operator<<(LONGLONG n);
CDumpContext& operator<<(ULONGLONG n);
CDumpContext& operator<<(HWND h);
CDumpContext& operator<<(HDC h);
CDumpContext& operator<<(HMENU h);
CDumpContext& operator<<(HACCEL h);
CDumpContext& operator<<(HFONT h);
戻り値Return Value
CDumpContext
参照。A CDumpContext
reference. 戻り値を使用すると、1行のソースコードに複数の挿入を書き込むことができます。Using the return value, you can write multiple insertions on a single line of source code.
解説Remarks
挿入演算子は、 CObject
ポインターやほとんどのプリミティブ型に対してオーバーロードされます。The insertion operator is overloaded for CObject
pointers as well as for most primitive types. 文字へのポインターは、文字列の内容のダンプを生成します。へのポインターは、 void
アドレスの16進数のダンプだけを生成します。A pointer to character results in a dump of string contents; a pointer to void
results in a hexadecimal dump of the address only. LONGLONG では、64ビット符号付き整数のダンプが生成されます。ULONGLONG は、64ビット符号なし整数のダンプを生成します。A LONGLONG results in a dump of a 64-bit signed integer; A ULONGLONG results in a dump of a 64-bit unsigned integer.
クラスの実装で IMPLEMENT_DYNAMIC または IMPLEMENT_SERIAL マクロを使用する場合、挿入演算子によって、から CObject::Dump
派生したクラスの名前が出力され CObject
ます。If you use the IMPLEMENT_DYNAMIC or IMPLEMENT_SERIAL macro in the implementation of your class, then the insertion operator, through CObject::Dump
, will print the name of your CObject
-derived class. それ以外の場合は印刷され CObject
ます。Otherwise, it will print CObject
. クラスの関数をオーバーライドすると Dump
、16進数のダンプではなく、オブジェクトの内容に対してより意味のある出力を提供できます。If you override the Dump
function of the class, then you can provide a more meaningful output of the object's contents instead of a hexadecimal dump.
例Example
#if _DEBUG
CStringList li;
li.AddHead(_T("item 0"));
li.AddHead(_T("item 1"));
CString s = _T("test");
int i = 7;
long lo = 1000000000L;
LONGLONG lolo = 12345678901234i64;
afxDump << _T("list=") << &li << _T("string=")
<< s << _T("int=") << i << _T("long=") << lo
<< _T("LONGLONG=") << lolo << _T("\n");
#endif
CDumpContext:: SetDepthCDumpContext::SetDepth
ダンプの深さを設定します。Sets the depth for the dump.
void SetDepth(int nNewDepth);
パラメーターParameters
nNewDepthnNewDepth
新しい深さの値。The new depth value.
解説Remarks
プリミティブ型をダンプする場合、または CObject
他のオブジェクトへのポインターが含まれていない単純な場合は、値を0にするだけで十分です。If you are dumping a primitive type or simple CObject
that contains no pointers to other objects, then a value of 0 is sufficient. 0より大きい値は、すべてのオブジェクトが再帰的にダンプされる詳細ダンプを指定します。A value greater than 0 specifies a deep dump where all objects are dumped recursively. たとえば、コレクションの詳細ダンプによって、コレクションのすべての要素がダンプされます。For example, a deep dump of a collection will dump all elements of the collection. 派生クラスでは、他の特定の深さの値を使用できます。You may use other specific depth values in your derived classes.
注意
詳細ダンプで循環参照が検出されないため、無限ループが発生する可能性があります。Circular references are not detected in deep dumps and can result in infinite loops.
例Example
#if _DEBUG
afxDump.SetDepth(1); // Specifies deep dump
ASSERT(afxDump.GetDepth() == 1);
#endif
関連項目See also
階層図Hierarchy Chart
CFile クラスCFile Class
CObject クラスCObject Class