nlib
SimpleSingleton.h
Go to the documentation of this file.
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)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
Definition: Config.h:158
Singleton of the type for implicitly constructing an instance based on a static variable before calli...
static T & Instance()
Gets the singleton instance of T.
A file that contains the configuration information for each development environment.
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:224