]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MIUtilSingletonBase.h
Merge ^/head r274961 through r275261.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / tools / lldb-mi / MIUtilSingletonBase.h
1 //===-- MIUtilSingletonBase.h -----------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 //++
11 // File:                MIUtilSingletonBase.h
12 //
13 // Overview:    MI::ISingleton interface.
14 //
15 // Environment: Compilers:      Visual C++ 12.
16 //                                                      gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
17 //                              Libraries:      See MIReadmetxt. 
18 //
19 // Copyright:   None.
20 //--
21
22 #pragma once
23
24 namespace MI
25 {
26
27 //      MI::ISingleton base class usage:
28 //
29 //      class CMIDerivedClass
30 //              : public MI::ISingleton< CMIDerivedClass >
31 //      {
32 //              friend MI::ISingleton< CMIDerivedClass >;
33 //
34 //      // Overridden:          
35 //      public:
36 //              // From MI::ISingleton
37 //              virtual bool Initialize( void );
38 //              virtual bool Shutdown( void );
39 //      };
40
41 //++ ============================================================================
42 // Details:     Base class for the singleton pattern.
43 // Gotchas:     Derived class must specify MI::ISingleton<> as a friend class.
44 // Authors:     Aidan Dodds 17/03/2014.
45 // Changes:     None.
46 //--
47 template< typename T >
48 class ISingleton
49 {
50 // Statics:
51 public:
52         // Return an instance of the derived class
53         static T & Instance( void )
54         {
55                 // This will fail if the derived class has not
56                 // declared itself to be a friend of MI::ISingleton
57                 static T instance;
58
59                 return instance;
60         }
61
62 // Overrideable:
63 public:
64         virtual bool Initialize( void ) = 0;
65         virtual bool Shutdown( void ) = 0;
66         //
67         /* dtor */ virtual ~ISingleton( void ) { };
68 };
69
70 } // namespace MI
71