]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MICmdFactory.h
Merge ^/head r275749 through r275758.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / tools / lldb-mi / MICmdFactory.h
1 //===-- MICmdFactory.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:                MICmdFactory.h
12 //
13 // Overview:    CMICmdFactory 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 // Third party headers
25 #include <map>
26
27 // In-house headers:
28 #include "MICmnBase.h"
29 #include "MIUtilSingletonBase.h"
30
31 // Declarations:
32 class CMICmdBase;
33 struct SMICmdData;
34
35 //++ ============================================================================
36 // Details:     MI Command Factory. Holds a list of registered MI commands that 
37 //                      MI application understands to interpret. Creates commands objects.
38 //                      The Command Factory is carried out in the main thread.
39 //                      A singleton class.
40 // Gotchas:     None.
41 // Authors:     Illya Rudkin 19/02/2014.
42 // Changes:     None.
43 //--
44 class CMICmdFactory
45 :       public CMICmnBase
46 ,       public MI::ISingleton< CMICmdFactory >
47 {
48         friend class MI::ISingleton< CMICmdFactory >;
49
50 // Typedefs:
51 public:
52         typedef CMICmdBase * (*CmdCreatorFnPtr)( void );
53
54 // Class:
55 public:
56         //++
57         // Description: Command's factory's interface for commands to implement.
58         //--
59         class ICmd
60         {
61         public:
62                 virtual const CMIUtilString &   GetMiCmd( void ) const = 0;
63                 virtual CmdCreatorFnPtr                 GetCmdCreatorFn( void ) const = 0;
64                 //virtual CMICmdBase *                  CreateSelf( void ) = 0;                         // Not possible as require a static creator function in the command class, here for awareness
65
66                 /* dtor */ virtual ~ICmd( void ) {};
67         };
68
69 // Methods:
70 public:
71         bool    Initialize( void );
72         bool    Shutdown( void );
73         bool    CmdRegister( const CMIUtilString & vMiCmd, CmdCreatorFnPtr vCmdCreateFn );
74         bool    CmdCreate( const CMIUtilString & vMiCmd, const SMICmdData & vCmdData, CMICmdBase *& vpNewCmd );
75         bool    CmdExist( const CMIUtilString & vMiCmd ) const;
76
77 // Methods:
78 private:
79         /* ctor */      CMICmdFactory( void );
80         /* ctor */      CMICmdFactory( const CMICmdFactory & );
81         void            operator=( const CMICmdFactory & );
82         
83         bool    HaveAlready( const CMIUtilString & vMiCmd ) const;
84         bool    IsValid( const CMIUtilString & vMiCmd ) const;
85
86 // Overridden:
87 private:
88         // From CMICmnBase
89         /* dtor */ virtual ~CMICmdFactory( void );
90
91 // Typedefs:
92 private:
93         typedef std::map< CMIUtilString, CmdCreatorFnPtr >      MapMiCmdToCmdCreatorFn_t;
94         typedef std::pair< CMIUtilString, CmdCreatorFnPtr >     MapPairMiCmdToCmdCreatorFn_t;
95
96 // Attributes:
97 private:
98         MapMiCmdToCmdCreatorFn_t        m_mapMiCmdToCmdCreatorFn;
99 };