]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/lldb/tools/lldb-mi/MICmdFactory.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm-project / lldb / tools / lldb-mi / MICmdFactory.h
1 //===-- MICmdFactory.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 // Third party headers
12 #include <map>
13
14 // In-house headers:
15 #include "MICmnBase.h"
16 #include "MIUtilSingletonBase.h"
17
18 // Declarations:
19 class CMICmdBase;
20 struct SMICmdData;
21
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 //--
29 class CMICmdFactory : public CMICmnBase, public MI::ISingleton<CMICmdFactory> {
30   friend class MI::ISingleton<CMICmdFactory>;
31
32   // Typedefs:
33 public:
34   typedef CMICmdBase *(*CmdCreatorFnPtr)();
35
36   // Class:
37 public:
38   //++
39   // Description: Command's factory's interface for commands to implement.
40   //--
41   class ICmd {
42   public:
43     virtual const CMIUtilString &GetMiCmd() const = 0;
44     virtual CmdCreatorFnPtr GetCmdCreatorFn() const = 0;
45     // virtual CMICmdBase *         CreateSelf( void ) = 0;             // Not
46     // possible as require a static creator
47     // function in the command class, here for awareness
48
49     /* dtor */ virtual ~ICmd() {}
50   };
51
52   // Methods:
53 public:
54   bool Initialize() override;
55   bool Shutdown() override;
56   bool CmdRegister(const CMIUtilString &vMiCmd, CmdCreatorFnPtr vCmdCreateFn);
57   bool CmdCreate(const CMIUtilString &vMiCmd, const SMICmdData &vCmdData,
58                  CMICmdBase *&vpNewCmd);
59   bool CmdExist(const CMIUtilString &vMiCmd) const;
60
61   // Methods:
62 private:
63   /* ctor */ CMICmdFactory();
64   /* ctor */ CMICmdFactory(const CMICmdFactory &);
65   void operator=(const CMICmdFactory &);
66
67   bool HaveAlready(const CMIUtilString &vMiCmd) const;
68   bool IsValid(const CMIUtilString &vMiCmd) const;
69
70   // Overridden:
71 private:
72   // From CMICmnBase
73   /* dtor */ ~CMICmdFactory() override;
74
75   // Typedefs:
76 private:
77   typedef std::map<CMIUtilString, CmdCreatorFnPtr> MapMiCmdToCmdCreatorFn_t;
78   typedef std::pair<CMIUtilString, CmdCreatorFnPtr>
79       MapPairMiCmdToCmdCreatorFn_t;
80
81   // Attributes:
82 private:
83   MapMiCmdToCmdCreatorFn_t m_mapMiCmdToCmdCreatorFn;
84 };