Solution46
CDebug.cpp
[詳解]
1 //=============================================================================
2 /// @file
3 /// デバッグクラス実装ファイル
4 ///
5 /// デバッグクラス実装ファイルです。
6 ///
7 /// $Id: CDebug.cpp 245 2019-03-20 15:03:41Z admin $
8 /// $Date: 2019-03-21 00:03:41 +0900 (2019/03/21 (木)) $
9 /// $Author: admin $
10 ///
11 /// @attention なし
12 
13 #pragma managed( push, off )
14 
15 //=============================================================================
16 // インクルードファイル
17 #include <CDebug.h>
18 #include <LibUtility.h>
19 #include <stdio.h>
20 
21 //=============================================================================
22 // 共通ライブラリ名前空間
23 namespace LibCommon {
24  //=========================================================================
25  // デバッグクラス
26  //=========================================================================
27  // 構築子と解体子
28  //-------------------------------------------------------------------------
29  // コンストラクタ
30  CDebug::CDebug() noexcept
31  // 基底クラスコンストラクタ
32  : CStreamOut()
33  // メンバ変数初期化
34  , m_szString()
35  {
36  // コンストラクタ実行通知
38  }
39 
40  //-------------------------------------------------------------------------
41  // デストラクタ
42  CDebug::~CDebug() noexcept {
43  // デストラクタ実行通知
45  }
46 
47  //=========================================================================
48  // 公開関数
49  //-------------------------------------------------------------------------
50  // 文字列出力関数
51  bool CDebug::OutputString( wchar_t const* pszString ) noexcept {
52  // 処理ブロック
53  bool result = false;
54  do {
55  // 文字列ポインタを調べる
56  if ( nullptr == pszString ) {
57  // 失敗!
58  break;
59  }
60 
61  // 文字列長を取得する
62  int nCount = static_cast< int >( ::wcslen( pszString ) );
63  if ( BUFFER_SIZE >= nCount ) {
64  // デバッグコンソールに文字列出力する
65  ::OutputDebugStringW( pszString );
66  }
67  // 巡回する
68  else for ( int nIndex = 0, nSize = 0; nCount > nIndex; nIndex += nSize, nCount -= nSize ) {
69  // 1回に出力する文字数を取得する
70  if ( BUFFER_SIZE > nCount ) {
71  nSize = nCount;
72  }
73  else {
74  nSize = BUFFER_SIZE;
75  }
76 
77  // 文字列バッファにコピーする
78  ::wcsncpy_s( m_szString, &pszString[ nIndex ], nSize );
79 
80  // 終端文字コードを設定する
81  m_szString[ nSize ] = L'\0';
82 
83  // デバッグコンソールに文字列出力する
84  ::OutputDebugStringW( m_szString );
85  }
86 
87  // 成功!
88  result = true;
89  } while ( false );
90 
91  // 実行結果を返す
92  return result;
93  }
94 }
95 
96 #pragma managed( pop )
#define NotifyConstructor()
コンストラクタ実行通知マクロ
Definition: LibUtility.h:24
デバッグクラスヘッダファイル
CDebug() noexcept
コンストラクタ
Definition: CDebug.cpp:30
#define NotifyDestructor()
デストラクタ実行通知マクロ
Definition: LibUtility.h:25
virtual bool OutputString(wchar_t const *pszString) noexcept override
文字列出力関数
Definition: CDebug.cpp:51
共通ライブラリ名前空間
Definition: CArray.h:23
virtual ~CDebug() noexcept
デストラクタ
Definition: CDebug.cpp:42
wchar_t m_szString[BUFFER_SIZE+1]
文字列バッファ
Definition: CDebug.h:114
ストリーム出力クラス
Definition: CStreamOut.h:30
ユーティリティライブラリヘッダファイル
static int const BUFFER_SIZE
文字列バッファサイズ
Definition: CDebug.h:109