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 //============================================================================ 25 // Details: MI Command Factory. Holds a list of registered MI commands that 26 // MI application understands to interpret. Creates commands objects. 27 // The Command Factory is carried out in the main thread. 28 // A singleton class. 29 //-- 30 class CMICmdFactory : public CMICmnBase, public MI::ISingleton<CMICmdFactory> { 31 friend class MI::ISingleton<CMICmdFactory>; 32 33 // Typedefs: 34 public: 35 typedef CMICmdBase *(*CmdCreatorFnPtr)(); 36 37 // Class: 38 public: 39 //++ 40 // Description: Command's factory's interface for commands to implement. 41 //-- 42 class ICmd { 43 public: 44 virtual const CMIUtilString &GetMiCmd() const = 0; 45 virtual CmdCreatorFnPtr GetCmdCreatorFn() const = 0; 46 // virtual CMICmdBase * CreateSelf( void ) = 0; // Not 47 // possible as require a static creator 48 // function in the command class, here for awareness 49 ~ICmd()50 /* dtor */ virtual ~ICmd() {} 51 }; 52 53 // Methods: 54 public: 55 bool Initialize() override; 56 bool Shutdown() override; 57 bool CmdRegister(const CMIUtilString &vMiCmd, CmdCreatorFnPtr vCmdCreateFn); 58 bool CmdCreate(const CMIUtilString &vMiCmd, const SMICmdData &vCmdData, 59 CMICmdBase *&vpNewCmd); 60 bool CmdExist(const CMIUtilString &vMiCmd) const; 61 62 // Methods: 63 private: 64 /* ctor */ CMICmdFactory(); 65 /* ctor */ CMICmdFactory(const CMICmdFactory &); 66 void operator=(const CMICmdFactory &); 67 68 bool HaveAlready(const CMIUtilString &vMiCmd) const; 69 bool IsValid(const CMIUtilString &vMiCmd) const; 70 71 // Overridden: 72 private: 73 // From CMICmnBase 74 /* dtor */ ~CMICmdFactory() override; 75 76 // Typedefs: 77 private: 78 typedef std::map<CMIUtilString, CmdCreatorFnPtr> MapMiCmdToCmdCreatorFn_t; 79 typedef std::pair<CMIUtilString, CmdCreatorFnPtr> 80 MapPairMiCmdToCmdCreatorFn_t; 81 82 // Attributes: 83 private: 84 MapMiCmdToCmdCreatorFn_t m_mapMiCmdToCmdCreatorFn; 85 }; 86