コード例 #1
0
ファイル: Command.cpp プロジェクト: wangyanxing/Demi3D
    bool DiCommandManager::ExecuteCommand(const DiString& cmd)
    {
        if (cmd.size() < 1)
            return false;
        
        // this is a comment
        if (cmd[0] == '#')
            return true;

        DiCmdArgs argus;

        DiString& command = argus.GetCommand();
        DiKeyList& splitList = argus.GetKeyList();

        DiString cmds = cmd;
        cmds.Tokenize(" ", splitList);

        if (splitList.empty())
            return true;

        command = cmd;

        DiString& kName = splitList.at(0);

        kName.ToLower();

        DiStringCmdInfoMap::iterator it = mCmdInfos.find(kName);
        if (it == mCmdInfos.end())
        {
            DI_WARNING( "can't find command. [%s]", kName.c_str());
            return false;
        }

        DiCmdInfo kCmdInfo = it->second;

        bool iRlt = kCmdInfo.mFunc(&argus);
        if (!iRlt)
        {
            DI_WARNING( "execute failed. [%s]", command.c_str());
            return false;
        }

        return true;
    }
コード例 #2
0
ファイル: Command.cpp プロジェクト: wangyanxing/Demi3D
    bool DiCommandManager::AddCommand(const DiString& cmd, DiCmdFuntion function, const DiString& help)
    {
        DI_ASSERT(function);

        if (!function)
            return false;

        DiVector<DiString> splitList = cmd.Tokenize(" ");

        if (splitList.empty())
            return false;

        DiCmdInfo kCmdInfo;

        kCmdInfo.mName = splitList[0];
        kCmdInfo.mDesc = help;
        kCmdInfo.mFunc = function;

        kCmdInfo.mName.ToLower();

        mCmdInfos[kCmdInfo.mName] = kCmdInfo;

        return true;
    }