nlib
SimpleSingleton.h
[詳解]
1 
2 /*---------------------------------------------------------------------------*
3 
4  Project: CrossRoad
5  Copyright (C)2012-2016 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 #ifndef INCLUDE_NN_NLIB_SIMPLESINGLETON_H_
17 #define INCLUDE_NN_NLIB_SIMPLESINGLETON_H_
18 
19 #include "nn/nlib/Config.h"
20 
21 NLIB_NAMESPACE_BEGIN
22 
23 template <class T>
25  private:
26  // This ensures Instance() called before main()
27  struct Creator {
28  Creator() { SimpleSingleton<T>::Instance(); }
29  inline void DummyFunc() const {}
30  };
31  static Creator creator;
32 
33  public:
34  static T& Instance() {
35  static T obj;
36 
37  // This ensures 'obj' is already constructed
38  // when called from a static object's constructor.
39  creator.DummyFunc();
40  return obj;
41  }
42  static T& GetInstance() { return Instance(); }
43 
44  private:
47 };
48 
49 template <class T>
51 
52 NLIB_NAMESPACE_END
53 
54 #endif // INCLUDE_NN_NLIB_SIMPLESINGLETON_H_
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName で指定されたクラスのコピーコンストラクタと代入演算子を禁止します。
Definition: Config.h:158
main関数の実行前にstatic変数により暗黙的にインスタンスを構築するタイプのシングルトンです。 ...
static T & Instance()
T のシングルトンインスタンスを取得します。
開発環境別の設定が書かれるファイルです。
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
Definition: Config.h:224