//---------------------------------------------------------------------- // MTNew <(size_t numObjects)> [-Array (size_t arraySize)] //---------------------------------------------------------------------- CmdExecStatus MTNewCmd::exec(const string& option) { // TODO vector<string> tokens; int num, arrs; if(option == ""){ return errorOption(CMD_OPT_MISSING, ""); } if(!CmdExec::lexOptions(option, tokens)) return CMD_EXEC_ERROR; if(tokens.size() == 1){ if(myStr2Int(tokens[0], num)){ if(num > 0){ mtest.newObjs(num); } else return errorOption(CMD_OPT_ILLEGAL, tokens[0]); } else return errorOption(CMD_OPT_ILLEGAL, tokens[0]); } else if(tokens.size() == 3){ if(myStr2Int(tokens[0], num)){ if(num > 0){ if(myStrNCmp("-Array", tokens[1], 2) == 0){ if(myStr2Int(tokens[2], arrs)){ if(arrs > 0){ mtest.newArrs(num, arrs); } else return errorOption(CMD_OPT_ILLEGAL, tokens[2]); } else return errorOption(CMD_OPT_ILLEGAL, tokens[2]); } else return errorOption(CMD_OPT_ILLEGAL, tokens[1]); } else return errorOption(CMD_OPT_ILLEGAL, tokens[0]); } else if(myStrNCmp("-Array", tokens[0], 2) == 0){ if(myStr2Int(tokens[1], arrs)){ if(arrs > 0){ if(myStr2Int(tokens[2], num)){ if(num > 0){ mtest.newArrs(num, arrs); } else return errorOption(CMD_OPT_ILLEGAL, tokens[2]); } else return errorOption(CMD_OPT_ILLEGAL, tokens[2]); } else return errorOption(CMD_OPT_ILLEGAL, tokens[1]); } else return errorOption(CMD_OPT_ILLEGAL, tokens[1]); } else return errorOption(CMD_OPT_ILLEGAL, tokens[0]); } else return CmdExec::errorOption(CMD_OPT_EXTRA, tokens[tokens.size() - 1]); return CMD_EXEC_DONE; }
//---------------------------------------------------------------------- // MTNew <(size_t numObjects)> [-Array (size_t arraySize)] //---------------------------------------------------------------------- CmdExecStatus MTNewCmd::exec(const string& option) { // TODO // check option vector<string> options; if (!CmdExec::lexOptions(option, options)) return CMD_EXEC_ERROR; bool doArray = false; int nObjs = -1, aSize; for (size_t i = 0, n = options.size(); i < n; ++i) { if (myStrNCmp("-Array", options[i], 2) == 0) { if (doArray) return CmdExec::errorOption(CMD_OPT_EXTRA,options[i]); if (++i == n) return CmdExec::errorOption(CMD_OPT_MISSING, options[i - 1]); if (!myStr2Int(options[i], aSize) || (aSize <= 0)) return CmdExec::errorOption(CMD_OPT_ILLEGAL, options[i]); doArray = true; } else { if (nObjs > 0) return CmdExec::errorOption(CMD_OPT_EXTRA,options[i]); if (!myStr2Int(options[i], nObjs) || (nObjs <= 0)) return CmdExec::errorOption(CMD_OPT_ILLEGAL, options[i]); } } if (nObjs <= 0) return CmdExec::errorOption(CMD_OPT_MISSING, ""); try { if (doArray) mtest.newArrs(nObjs, aSize); else mtest.newObjs(nObjs); } catch (bad_alloc) { return CMD_EXEC_ERROR; } return CMD_EXEC_DONE; }