本文整理汇总了C++中Command::Execute方法的典型用法代码示例。如果您正苦于以下问题:C++ Command::Execute方法的具体用法?C++ Command::Execute怎么用?C++ Command::Execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Command
的用法示例。
在下文中一共展示了Command::Execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: threadNewConnection
// Gets Called in a thread
void ServerManager::threadNewConnection(int clientID) {
string initMsgBuff;
string cmdName;
Command* tempCmd;
Client * newClient = cm->findClientByID(clientID);
bool success = false;
cout << " and new connection thread found " << newClient->getSocketID() << endl;
while ( !mtx.try_lock() ){
// Keep Trying!
}
// Mutex is Locked
// Receive Login or NewAccount
initMsgBuff = newClient->getSocket().Receive();
// initMsgBuff = "Login Todd Password 127.0.0.1";
// Build Command for either
if (initMsgBuff.find("Login") != std::string::npos) {
tempCmd = (*cmdMap)["Login"]->Clone();
}
//else if (initMsgBuff.find("NewAccount") != std::string::npos) {
// tempCmd = (*cmdMap)["NewAccount"]->Clone();
//}
else {
tempCmd = (*cmdMap)["NewAccount"]->Clone();
}
tempCmd->Initialize(initMsgBuff);
success = tempCmd->Execute();
// Send Result? Or have the Command return the result
delete tempCmd;
// LoginCheck::Execute() will find initMsgType from initMsgBuff
tempCmd = (*cmdMap)["LoginCheck"]->Clone();
tempCmd->GetClient(newClient);
if (success) {
tempCmd->Initialize(initMsgBuff + " 1");
// Acquire the Client
acquireClient(*newClient);
}
else {
tempCmd->Initialize(initMsgBuff + " 0");
}
tempCmd->Execute();
// Unlock ServerManager Data
cout << "Finished handling new Connection!" << endl;
mtx.unlock();
}
示例2: cancelEverything
void LoadCommand::cancelEverything ( bool undo )
{
// We were Executing commands but something failed,
// so now we undo everything.
if ( undo )
{
while ( commandsDone.size( ) > 0 )
{
Command * currentCommand = commandsDone.top( );
if ( currentCommand->IsHistorizable( ) )
{
( (HistorizableCommand *) currentCommand )->Undo( );
}
commandsDone.pop( );
commandsToDo.push( currentCommand );
}
}
// We were Undoing commands but something failed,
// so now we redo everything we had undone
else
{
while ( commandsToDo.size( ) > 0 )
{
Command * currentCommand = commandsToDo.top( );
currentCommand->Execute( );
commandsToDo.pop( );
commandsDone.push( currentCommand );
}
}
}
示例3: Run
virtual void Run() {
CmdBufferReader reader(buffer);
Command *cmd;
while((cmd = reader.NextCommand()) != NULL){
cmd->Execute(renderer->base);
}
}
示例4: ProcessOptions
HRESULT CLR_RT_ParseOptions::ProcessOptions( CLR_RT_StringVector& argv )
{
TINYCLR_HEADER();
if(CommandLineArgs.size() == 0)
{
CommandLineArgs = CLR_RT_StringVector(argv);
}
size_t argc = argv.size();
for(size_t i=0; i<argc; )
{
CommandListIter it;
LPCWSTR arg = argv[ i ].c_str();
for(it = m_commands.begin(); it != m_commands.end(); it++)
{
Command* cmd = *it;
if(!_wcsicmp( arg, cmd->m_szName ))
{
if(m_fVerbose)
{
size_t len = cmd->m_params.size();
size_t pos = i;
wprintf( L"Processing" );
wprintf( L" %s", arg );
while(len-- > 0 && pos < argc) wprintf( L" %s", argv[ ++pos ].c_str() );
wprintf( L"\n" );
}
i++;
if(cmd->Parse( argv, i, *this ) == false)
{
Usage();
TINYCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER);
}
TINYCLR_CHECK_HRESULT(cmd->Execute());
break;
}
}
if(it == m_commands.end())
{
wprintf( L"Unknown option '%s'\n\n", arg );
Usage();
TINYCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER);
}
}
TINYCLR_NOCLEANUP();
}
示例5: main
int main() {
Receiver* receiver = new Receiver;
Command* command = new SimpleCommand<Receiver>(receiver,
&Receiver::DoSomething);
command->Execute();
return 0;
}
开发者ID:ordinary-developer,项目名称:book_design_patterns_4_d_e_gamma_r_helm_r_johnson_j_vlissides,代码行数:8,代码来源:main.cpp
示例6: main
int main(int argc, char* argv[]) {
cout << argc << endl;
for (int h = 0; h<argc; h++)
cout << argv[h] << endl;
cout << endl;
Recorder* rec = Recorder::GetInstance();
//One of each device
TestDevice* dev = new TestDevice("dev");
Relay* rel = new Relay();
SpeedController* ctrl = new SpeedController();
Servo* serv = new Servo();
DoubleSolenoid* ds = new DoubleSolenoid();
Solenoid* sol = new Solenoid();
//Add all devices to recorder
rec->AddDevice("Relay",rel);
rec->AddDevice("Speed Controller",ctrl);
rec->AddDevice("Servo",serv);
rec->AddDevice("Double Solenoid",ds);
rec->AddDevice("Solenoid",sol);
rec->AddDevice(dev);
//Creates macro
cout << dev->GetName() << endl;
Macro* mac = rec -> macro();
int iterations = 5;
for (int i = 0; i<iterations; i++) {
mac->Record();
}
mac->WriteFile("auto.csv");
mac->Reset();
mac->ReadFile("auto.csv");
while (!mac->IsFinished())
{
mac->PlayBack();
}
cout << "plz work" << endl;
mac->Reset();
Command* recCom = mac->NewRecordFileCommand("auto2.csv");
recCom->Initialize();
for (int i = 0; i < 30; i ++) recCom->Execute();
recCom->End();
return 0;
}
示例7: Invoke
void Invoke()
{
// yoda notation
if (0 != m_command)
{
m_command->Execute();
}
}
示例8: Undo
void DeleteEntryCommand::Undo()
{
CUUID uuid = m_ci.GetUUID();
if (m_ci.IsDependent()) {
// Check if dep entry hasn't alredy been added - can happen if
// base and dep in group that's being undeleted.
if (m_pcomInt->Find(m_ci.GetUUID()) == m_pcomInt->GetEntryEndIter()) {
Command *pcmd = AddEntryCommand::Create(m_pcomInt, m_ci, m_base_uuid, this);
pcmd->Execute();
delete pcmd;
}
} else {
AddEntryCommand undo(m_pcomInt, m_ci, this);
undo.Execute();
if (m_ci.IsShortcutBase()) { // restore dependents
for (std::vector<CItemData>::iterator iter = m_dependents.begin();
iter != m_dependents.end(); iter++) {
Command *pcmd = AddEntryCommand::Create(m_pcomInt, *iter, uuid);
pcmd->Execute();
delete pcmd;
}
} else if (m_ci.IsAliasBase()) {
// Undeleting an alias base means making all the dependents refer to the alias
// again. Perhaps the easiest approach is to delete the existing entries
// and create new aliases.
for (std::vector<CItemData>::iterator iter = m_dependents.begin();
iter != m_dependents.end(); iter++) {
// Need to check that alias still exists - could have been deleted in group along with item
// being undone, in which case it will be added separately
if (m_pcomInt->Find(iter->GetUUID()) == m_pcomInt->GetEntryEndIter())
continue;
DeleteEntryCommand delExAlias(m_pcomInt, *iter, this);
delExAlias.Execute(); // out with the old...
Command *pcmd = AddEntryCommand::Create(m_pcomInt, *iter, uuid, this);
pcmd->Execute(); // in with the new!
delete pcmd;
}
}
}
RestoreState();
m_bState = false;
}
示例9: Execute
void MacroCommand::Execute()
{
ListIterator<Command*> i(_cmds);
for (i.First(); !i.IsDone(); i.Next())
{
Command* c = i.CurrentItem();
c->Execute();
}
}
示例10: ExecuteCommand
int Compilation::ExecuteCommand(const Command &C,
const Command *&FailingCommand) const {
if ((getDriver().CCPrintOptions ||
getArgs().hasArg(options::OPT_v)) && !getDriver().CCGenDiagnostics) {
raw_ostream *OS = &llvm::errs();
// Follow gcc implementation of CC_PRINT_OPTIONS; we could also cache the
// output stream.
if (getDriver().CCPrintOptions && getDriver().CCPrintOptionsFilename) {
std::error_code EC;
OS = new llvm::raw_fd_ostream(getDriver().CCPrintOptionsFilename, EC,
llvm::sys::fs::F_Append |
llvm::sys::fs::F_Text);
if (EC) {
getDriver().Diag(clang::diag::err_drv_cc_print_options_failure)
<< EC.message();
FailingCommand = &C;
delete OS;
return 1;
}
}
if (getDriver().CCPrintOptions)
*OS << "[Logging clang options]";
C.Print(*OS, "\n", /*Quote=*/getDriver().CCPrintOptions);
if (OS != &llvm::errs())
delete OS;
}
std::string Error;
bool ExecutionFailed;
int Res = C.Execute(Redirects, &Error, &ExecutionFailed);
if (!Error.empty()) {
assert(Res && "Error string set with 0 result code!");
getDriver().Diag(clang::diag::err_drv_command_failure) << Error;
}
if (Res)
FailingCommand = &C;
return ExecutionFailed ? 1 : Res;
}
示例11: Execute
string LoadCommand::Execute ( )
{
string status;
if ( !loadPerformed )
{
// First run of Execute: we load the commands from the input stream
input = new ifstream( path.c_str( ) );
status = loadAndExecute( input );
input->close( );
if ( status == STATUS_OK )
{
loadPerformed = true;
}
}
else
{
// We must execute succesfully *all* commands, otherwise we just
// cancel the whole thing
string status = STATUS_OK;
while ( commandsToDo.size( ) > 0 && status == STATUS_OK )
{
Command * currentCommand = commandsToDo.top( );
status = currentCommand->Execute( );
// We consider all OK statuses to be equivalent
if ( status == STATUS_OK_SILENT || status == STATUS_OK )
{
status = STATUS_OK;
commandsToDo.pop( );
commandsDone.push( currentCommand );
}
}
// If we see as much as one error, we need to undo everything
if ( status == STATUS_ERROR )
{
cancelEverything( true );
}
}
return status;
}
示例12: Play
void Game::Play()
{
LoadMap("res/dungeon0.xml");
CommandUtils::Load("res/commands.xml");
for( auto a : m_Rooms )
{
if ( a.second == NULL )
{
ostringstream ss;
ss << "Whoops, " << a.first << " is NULL";
throw NullKeyException(ss.str());
}
}
cout << m_Story << "\n";
while ( GetProperty("running") )
{
Room & room = *GetCurrentRoom();
bool visited;
if ( (room.HasProperty("visited") == false) ||
((visited = room.GetProperty("visited")) == false) )
{
room.SetProperty("visited", true);
}
cout << "> ";
string tmp;
getline(cin,tmp);
Command *pCmd = CommandUtils::Parse(tmp);
pCmd->Execute(*this);
delete pCmd;
}
Save("res/dungeon0.xml");
}
示例13: UseTool
void Viewer::UseTool (Tool* t, Event& e) {
Transformer* relative = ComputeRel(this, _graphic->GetTransformer());
Manipulator* m = t->CreateManipulator(this, e, relative);
if (m != nil) {
Manipulate(m, e);
Command* cmd = t->InterpretManipulator(m);
if (cmd != nil) {
cmd->Execute();
if (cmd->Reversible()) {
cmd->Log();
} else {
delete cmd;
}
}
delete m;
}
Unref(relative);
}
示例14: loadAndExecute
//----------------------------------------------------- Méthodes protégées
string LoadCommand::loadAndExecute ( istream * input )
{
if ( !input->good() )
{
return STATUS_ERROR;
}
string status = STATUS_OK;
while ( status != STATUS_ERROR && input->good( ) )
{
Command * loadedCommand = CommandInterpreter::InterpretCommand(
*input );
if ( loadedCommand == NULL )
{
status = STATUS_ERROR;
}
else
{
status = loadedCommand->Execute( );
// We consider all OK statuses to be equivalent
if ( status == STATUS_OK_SILENT || status == STATUS_OK )
{
status = STATUS_OK;
commandsDone.push( loadedCommand );
}
else
{
delete loadedCommand;
}
}
}
// If anything went wrong, we must rewind
if ( status == STATUS_ERROR )
{
cancelEverything( true );
}
return status;
}
示例15: RegisterCommand
int
main()
{
string input;
RequestParser parser;
RegisterCommand();
while (1) {
cin >> input;
Request req;
parser.GetRequest(input, req);
string cmd = req.GetValue(CMD_NAME);
Command *pCmd = _req2cmd[cmd];
if (pCmd != NULL)
pCmd->Execute(req);
else
cout << "Not Available Command : " << cmd << endl;
}
return true;
}