nlib
SimpleSingleton.h
[詳解]
1
2
/*--------------------------------------------------------------------------------*
3
Project: CrossRoad
4
Copyright (C)Nintendo All rights reserved.
5
6
These coded instructions, statements, and computer programs contain proprietary
7
information of Nintendo and/or its licensed developers and are protected by
8
national and international copyright laws. They may not be disclosed to third
9
parties or copied or duplicated in any form, in whole or in part, without the
10
prior written consent of Nintendo.
11
12
The content herein is highly confidential and should be handled accordingly.
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>
24
class
SimpleSingleton
NLIB_FINAL
{
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
:
45
SimpleSingleton
();
46
NLIB_DISALLOW_COPY_AND_ASSIGN
(
SimpleSingleton
);
47
};
48
49
template
<
class
T>
50
typename
SimpleSingleton<T>::Creator
SimpleSingleton<T>::creator
;
51
52
NLIB_NAMESPACE_END
53
54
#endif // INCLUDE_NN_NLIB_SIMPLESINGLETON_H_
NLIB_DISALLOW_COPY_AND_ASSIGN
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName で指定されたクラスのコピーコンストラクタと代入演算子を禁止します。
Definition:
Config.h:179
nn::nlib::SimpleSingleton
main関数の実行前にstatic変数により暗黙的にインスタンスを構築するタイプのシングルトンです。 ...
Definition:
SimpleSingleton.h:24
nn::nlib::SimpleSingleton::Instance
static T & Instance()
T のシングルトンインスタンスを取得します。
Definition:
SimpleSingleton.h:34
Config.h
開発環境別の設定が書かれるファイルです。
NLIB_FINAL
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
Definition:
Config.h:245
© 2012-2017 Nintendo Co., Ltd. All rights reserved.