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>
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:158
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:224
© 2012-2016 Nintendo Co., Ltd. All rights reserved.