]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/lldb/tools/lldb-mi/MIUtilSingletonBase.h
Fix a memory leak in if_delgroups() introduced in r334118.
[FreeBSD/FreeBSD.git] / contrib / llvm-project / lldb / tools / lldb-mi / MIUtilSingletonBase.h
1 //===-- MIUtilSingletonBase.h -----------------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8
9 #pragma once
10
11 namespace MI {
12
13 //   MI::ISingleton base class usage:
14 //
15 //   class CMIDerivedClass
16 //       : public MI::ISingleton< CMIDerivedClass >
17 //   {
18 //       friend MI::ISingleton< CMIDerivedClass >;
19 //
20 //   // Overridden:
21 //   public:
22 //       // From MI::ISingleton
23 //       bool Initialize() override;
24 //       bool Shutdown() override;
25 //   };
26
27 //++
28 //============================================================================
29 // Details: Base class for the singleton pattern.
30 // Gotchas: Derived class must specify MI::ISingleton<> as a friend class.
31 //--
32 template <typename T> class ISingleton {
33   // Statics:
34 public:
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
39     static T instance;
40
41     return instance;
42   }
43
44   // Overrideable:
45 public:
46   virtual bool Initialize() = 0;
47   virtual bool Shutdown() = 0;
48   //
49   /* dtor */ virtual ~ISingleton() {}
50 };
51
52 } // namespace MI