CTR-Pia  5.4.3
Game Communication Engine
 全て クラス ネームスペース 関数 変数 型定義 列挙型 列挙型の値 ページ
common_Singleton.h
1 /*--------------------------------------------------------------------------------*
2  Copyright (C)Nintendo All rights reserved.
3 
4  These coded instructions, statements, and computer programs contain proprietary
5  information of Nintendo and/or its licensed developers and are protected by
6  national and international copyright laws. They may not be disclosed to third
7  parties or copied or duplicated in any form, in whole or in part, without the
8  prior written consent of Nintendo.
9 
10  The content herein is highly confidential and should be handled accordingly.
11  *--------------------------------------------------------------------------------*/
12 
13 
14 #pragma once
15 
16 #include <nn/pia/common/common_Definitions.h>
17 
18 #include <nn/pia/common/common_Api.h>
19 
20 
21 // このマクロは、シングルトンに対応する.cppファイルの冒頭付近に記入してください。
22 #define NN_PIA_COMMON_SINGLETON_DEFINE(CLASSNAME) CLASSNAME* CLASSNAME::s_pInstance = NULL
23 
24 
25 // このマクロは、シングルトンに対応する.cppファイルで記入してください。
26 #define NN_PIA_COMMON_SINGLETON_CREATE_INSTANCE_IMPL(CLASSNAME) \
27  \
28 nn::pia::Result CLASSNAME::CreateInstance(void) \
29  \
30 { \
31  if (!IsInitialized()) \
32  { \
33  PIA_RETURN_RESULT_WITH_REPORT(ResultNotInitialized, "PiaCommon is not initialized."); \
34  } \
35  if (!IsInSetupMode()) \
36  { \
37  PIA_RETURN_RESULT_WITH_REPORT(ResultInvalidState, "Singleton must be created between nn::pia::common::BeginSetup() and nn::pia::common::EndSetup()."); \
38  } \
39  if (s_pInstance) \
40  { \
41  PIA_RETURN_RESULT_WITH_REPORT(ResultAlreadyExists, "Singleton is already created."); \
42  } \
43  \
44  /* RootObjectから派生させていれば、RootObject::new が使われ、*/ \
45  /* グローバルnewは使われないはず。 */ \
46  s_pInstance = new CLASSNAME(); \
47  PIA_ASSERT(PIA_IS_VALID_POINTER(s_pInstance)); \
48  \
49  return ResultSuccess(); \
50  \
51 }
52 
53 
54 // このマクロは、シングルトンに対応する.cppファイルで記入してください。
55 #define NN_PIA_COMMON_SINGLETON_DESTROY_INSTANCE_IMPL(CLASSNAME) \
56  \
57 void CLASSNAME::DestroyInstance(void) \
58  \
59 { \
60  if (s_pInstance) \
61  { \
62  /* RootObjectから派生させていれば、RootObject::delete が使われ、 */ \
63  /* グローバルdeleteは使われないはず。 */ \
64  delete s_pInstance; \
65  s_pInstance = NULL; \
66  } \
67  \
68 }
69 
70 
71 namespace nn
72 {
73 namespace pia
74 {
75 namespace common
76 {
77 }
78 }
79 } // end of namespace nn::pia::common