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