hello StartupCommand PureMVC cpp with CMake

hello StartupCommand PureMVC cpp with CMake

本文关键字:with CMake cpp PureMVC StartupCommand hello      更新时间:2023-10-16

CMakeLists.txt, main.cppPureMVC sources从execute() Startup SimpleCommand显示"Hello Startup"的最简单示例是什么?

PureMVC源代码在这里

理想的解决方案可以是链接到github项目。

你应该编译相应的dll和lib (Debug或Release [static|shared]),包括PureMVC文件。也许您可以从PureMVC::Patterns:: facade派生一个facade,覆盖基本的虚函数。因为它在c++和类java编程语言之间是不同的,重写的initializeController()不会在基类的构造函数中被调用!下面是一个派生示例:

class ApplicationFacade
    : public virtual IFacade
    , public Facade
{
    friend class Facade;
public:
    static const string STARTUP;
    static const string EXIT;
protected:
    ApplicationFacade(void)
        : Facade(this, "ApplicationFacade")
    {
        initializeController();
    }
public:
    static ApplicationFacade& getInstance(void)
    {
        if (Facade::hasCore("ApplicationFacade"))
            return *(dynamic_cast<ApplicationFacade*>(&Facade::getInstance("ApplicationFacade")));
        return *(new ApplicationFacade());
    }
protected:
    virtual void initializeNotifier(string const& key)
    {
        Facade::initializeNotifier(key);
    }
    virtual void initializeFacade()
    {
        Facade::initializeFacade();
    }
    virtual void initializeController(void)
    {
        Facade::initializeController();
        StartupCommand* startupCommand = new StartupCommand();
        registerCommand(STARTUP, startupCommand);
        ExitCommand* exitCommand = new ExitCommand();
        registerCommand(EXIT, exitCommand);
    }
    ~ApplicationFacade()
    {
    }
};
const string ApplicationFacade::STARTUP = "startup";
const string ApplicationFacade::EXIT = "exit";

StartupCommand和ExitCommand来源于PureMVC::Patterns::SimpleCommand然后在main.cpp中,你可以通过以下命令启动程序:

ApplicationFacade& facade = ApplicationFacade::getInstance();
facade.sendNotification(ApplicationFacade::STARTUP);

和退出:

facade.sendNotification(ApplicationFacade::EXIT);