![]() |
Shadowrun: Awakened 29 September 2011 - Build 871
|
#include <Command.h>
Inheritance diagram for CompositeCommand:Public Member Functions | |
| void | addCommand (ICommand *command) |
| virtual void | execute () |
| virtual void | executeCumulative (ICommand *command) |
| virtual bool | isCumulative (ICommand *command) |
| virtual void | undo () |
| virtual | ~CompositeCommand () |
Protected Attributes | |
| std::list< ICommand * > | _commands |
This class implement ICommand on a list of child commands When executing this command, all children are executed in the order they were added When undoing this command, all children are undone in the order they were added
| CompositeCommand::~CompositeCommand | ( | ) | [virtual] |
| void CompositeCommand::addCommand | ( | ICommand * | command | ) |
Adds a command to the collection
Definition at line 19 of file Command.cpp.
References _commands.
{
_commands.push_back(command);
}
| void CompositeCommand::execute | ( | ) | [virtual] |
| void CompositeCommand::executeCumulative | ( | ICommand * | command | ) | [virtual] |
Applies cumulative changes in this object to the given object
Reimplemented from ICommand.
Definition at line 58 of file Command.cpp.
References _commands.
{
CompositeCommand* cmd = dynamic_cast<CompositeCommand*>(command);
//go through all the commands between each composite
std::list<ICommand*>::const_iterator myIter = _commands.begin();
std::list<ICommand*>::const_iterator theirIter = cmd->_commands.begin();
while(myIter != _commands.end())
{
//apply from this object to the given objects
(*myIter)->executeCumulative(*theirIter);
++myIter;
++theirIter;
}
}
Checks if all commands in this object are cumulative
Reimplemented from ICommand.
Definition at line 27 of file Command.cpp.
References _commands.
{
//the command must be a composite
CompositeCommand* cmd = dynamic_cast<CompositeCommand*>(command);
if(cmd == NULL)
return false;
//it must contain the same number of commands
if(cmd->_commands.size() != _commands.size())
return false;
//each command must be equivalent to its matching command
std::list<ICommand*>::const_iterator myIter = _commands.begin();
std::list<ICommand*>::const_iterator theirIter = cmd->_commands.begin();
while(myIter != _commands.end())
{
//if they do not match, reject
if(!((*myIter)->isCumulative(*theirIter)))
return false;
//otherwise move on
++myIter;
++theirIter;
}
//if all of the above is met, they must be cumulative
return true;
}
| void CompositeCommand::undo | ( | ) | [virtual] |
std::list<ICommand*> CompositeCommand::_commands [protected] |
The list of child commands
Definition at line 64 of file Command.h.
Referenced by addCommand(), execute(), executeCumulative(), isCumulative(), undo(), and ~CompositeCommand().
Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.