Espotel / Mbed 2 deprecated Elmo-Terminal-App

Dependencies:   SX1272lib mbed

Fork of Elmo-Terminal by Michal Leksinski

Commands/CmdFactory.cpp

Committer:
WGorniak
Date:
2015-10-01
Revision:
2:8d8295a51f68

File content as of revision 2:8d8295a51f68:

#include "mbed.h"
#include "Serial.h"

#include "CmdFactory.h"
#include "CmdList.h"

CmdFactory::CmdFactory(Settings* settings, Serial *serial)
    : settings_(settings), serial_(serial)
{
}

CmdFactory::~CmdFactory()
{
}


template <>
Cmd* CmdFactory::create<int>(const std::string& cmd) const
{
    return NULL;
}

template <typename cmds>
Cmd* CmdFactory::create(const std::string& cmd) const
{
    typedef typename cmds::t T;

    if (0 == cmd.compare(T::cmd()))
    {
        return new T(settings_);
    }

    return create<typename cmds::tn>(cmd); // tail call recursion - optimized out (-O2)
}

Cmd* CmdFactory::createCmd(std::string cmd) const
{
    Cmd* command  = create<CmdList>(cmd);
    if (!command)
    {
        serial_->printf("No such command %s\r\n", cmd.c_str());
    }

    return command;
}