1 //===-- MIUtilSingletonBase.h -----------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
13 // MI::ISingleton base class usage:
15 // class CMIDerivedClass
16 // : public MI::ISingleton< CMIDerivedClass >
18 // friend MI::ISingleton< CMIDerivedClass >;
22 // // From MI::ISingleton
23 // bool Initialize() override;
24 // bool Shutdown() override;
28 //============================================================================
29 // Details: Base class for the singleton pattern.
30 // Gotchas: Derived class must specify MI::ISingleton<> as a friend class.
32 template <typename T> class ISingleton {
35 // Return an instance of the derived class
36 static T &Instance() {
37 // This will fail if the derived class has not
38 // declared itself to be a friend of MI::ISingleton
46 virtual bool Initialize() = 0;
47 virtual bool Shutdown() = 0;
49 /* dtor */ virtual ~ISingleton() {}