nlib
SimpleSingleton.h
Go to the documentation of this file.
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>
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:179
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:245