1 //===-- MIUtilSingletonBase.h -----------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
14 // MI::ISingleton base class usage:
16 // class CMIDerivedClass
17 // : public MI::ISingleton< CMIDerivedClass >
19 // friend MI::ISingleton< CMIDerivedClass >;
23 // // From MI::ISingleton
24 // bool Initialize() override;
25 // bool Shutdown() override;
29 //============================================================================
30 // Details: Base class for the singleton pattern.
31 // Gotchas: Derived class must specify MI::ISingleton<> as a friend class.
33 template <typename T> class ISingleton {
36 // Return an instance of the derived class
37 static T &Instance() {
38 // This will fail if the derived class has not
39 // declared itself to be a friend of MI::ISingleton
47 virtual bool Initialize() = 0;
48 virtual bool Shutdown() = 0;
50 /* dtor */ virtual ~ISingleton() {}