CTR Pia  4.11.3
Game Communication Engine
transport_Singleton.h
1 /*---------------------------------------------------------------------------*
2  Project: Pia
3  File: transport_Singleton.h
4 
5  Copyright Nintendo. All rights reserved.
6 
7  These coded instructions, statements, and computer programs contain
8  proprietary information of Nintendo of America Inc. and/or Nintendo
9  Company Ltd., and are protected by Federal copyright law. They may
10  not be disclosed to third parties or copied or duplicated in any form,
11  in whole or in part, without the prior written consent of Nintendo.
12  *---------------------------------------------------------------------------*/
13 
14 
15 #pragma once
16 
17 #include <pia/transport/transport_definitions.h>
18 
19 #include <pia/transport/transport_Api.h>
20 #include <pia/common/common_Log.h>
21 #include <pia/assert.h>
22 
23 
24 // Add this macro near the start of the CPP file that corresponds to the singleton.
25 #define NN_PIA_TRANSPORT_SINGLETON_DEFINE(CLASSNAME) CLASSNAME* CLASSNAME::s_pInstance = NULL
26 
27 
28 // For this macro, fill in the CPP file that corresponds to the singleton.
29 #define NN_PIA_TRANSPORT_SINGLETON_CREATE_INSTANCE_IMPL(CLASSNAME) \
30  \
31 nn::Result CLASSNAME::CreateInstance(void) \
32  \
33 { \
34  if (!IsInitialized()) \
35  { \
36  PIA_RETURN_RESULT_WITH_LOG(ResultNotInitialized, "PiaTransport is not initialized."); \
37  } \
38  if (!IsInSetupMode()) \
39  { \
40  PIA_RETURN_RESULT_WITH_LOG(ResultInvalidState, "Singleton must be created between nn::pia::transport::BeginSetup() and nn::pia::transport::EndSetup().") \
41  } \
42  if (s_pInstance) \
43  { \
44  PIA_RETURN_RESULT_WITH_LOG(ResultAlreadyExists, "Singleton is already created."); \
45  } \
46  \
47 /* <tt>RootObject::new</tt> is used if this class inherits <tt>RootObject</tt>.*/ \
48 /* Do not use global <tt>new</tt>. */ \
49  s_pInstance = new CLASSNAME(); \
50  PIA_ASSERT(PIA_IS_VALID_POINTER(s_pInstance)); \
51  \
52  return ResultSuccess(); \
53 }
54 
55 
56 // For this macro, fill in the CPP file that corresponds to the singleton.
57 #define NN_PIA_TRANSPORT_SINGLETON_DESTROY_INSTANCE_IMPL(CLASSNAME) \
58  \
59 void CLASSNAME::DestroyInstance(void) \
60  \
61 { \
62  if (s_pInstance) \
63  { \
64 /* <tt>RootObject::delete</tt> is used because this class inherits <tt>RootObject</tt>. */ \
65 /* Do not use global <tt>delete</tt>. */ \
66  delete s_pInstance; \
67  s_pInstance = NULL; \
68  } \
69  \
70 }
71 
72 
73 namespace nn
74 {
75 namespace pia
76 {
77 namespace transport
78 {
79 }
80 }
81 } // end of namespace nn::pia::transport
Definition: assert.h:115