Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

COMMAND Class Reference

Base class for "commands" that can be executed (COMMAND::doit()) and undone (COMMAND::undoit()). More...

#include <command.H>

Inheritance diagram for COMMAND:

Inheritance graph
[legend]
Collaboration diagram for COMMAND:

Collaboration graph
[legend]
List of all members.

Command Virtual Methods

virtual bool doit ()
 Execute the command.
virtual bool undoit ()
 Undo the command.
virtual bool clear ()
 After doit() and undoit() were called, restore things to the way they were before (may be a no-op for most derived classes).

Public Member Functions

void Own () const
void Free () const
int Lock ()
void Unlock ()
int Unique () const
Constructors
 COMMAND (bool done=false)

Protected Attributes

bool _is_done
 true if doit() was executed most recently.
bool _is_undone
 true if undoit() was executed most recently.

Detailed Description

Base class for "commands" that can be executed (COMMAND::doit()) and undone (COMMAND::undoit()).

A COMMAND can be in one of 3 possible states:

For many types of commands, there is no difference between 'undone' and 'clear'. An example of where the two WOULD be different is a command that generates a portion of mesh in doit(), but in undoit() simply hides the portion of mesh instead of destroying it. That way, redoing the command by calling doit() after undoit() would be relatively lightweight: the portion of mesh would be unhidden rather than regenerated.

The virtual method COMMAND::clear() is used to transition from state 'undone' to state 'clear'; e.g. the mesh generation command in the example above would delete the region of mesh in clear(), returning the command (and the mesh) to its initial state before the first doit() was executed. Most derived classes will not need to override COMMAND::clear().

The following are the actions that can be taken from each state:

state: 'clear' doit() changes state to 'done' undoit() is a no-op clear() is a no-op

state: 'done' doit() is a no-op undoit() changes state to 'undone' clear() is an invalid action

state: 'undone' doit() changes state to 'done' undoit() is a no-op clear() changes state to 'clear'

Definition at line 69 of file command.H.


Constructor & Destructor Documentation

COMMAND::COMMAND bool  done = false  )  [inline]
 

Definition at line 83 of file command.H.


Member Function Documentation

bool COMMAND::clear  )  [virtual]
 

After doit() and undoit() were called, restore things to the way they were before (may be a no-op for most derived classes).

Reimplemented in UNDO_CMD, and MULTI_CMD.

Definition at line 24 of file command.C.

References _is_done, _is_undone, and is_done().

Referenced by MULTI_CMD::clear(), and UNDO_CMD::clear().

COMMAND::DEFINE_RTTI_METHODS_BASE "COMMAND"  ,
CCOMMAND
 

bool COMMAND::doit  )  [virtual]
 

Execute the command.

Returns:
true on success. If the command is already done, this is a no-op and still returns true.

Reimplemented in UNDO_CMD, DISPLAY_CMD, MULTI_CMD, and MESH_SELECT_CMD.

Definition at line 8 of file command.C.

References _is_done, and _is_undone.

Referenced by MESH_SELECT_CMD::doit(), MULTI_CMD::doit(), DISPLAY_CMD::doit(), and UNDO_CMD::doit().

void REFcounter::Free  )  const [inline, inherited]
 

Definition at line 76 of file ref.H.

References REFcounter::_mutex, REFcounter::_u, and REF_ME.

bool COMMAND::is_clear  )  const [inline]
 

Neither doit() nor undoit() have been called.

Definition at line 91 of file command.H.

References _is_done, and _is_undone.

bool COMMAND::is_done  )  const [inline]
 

doit() was called most recently.

Definition at line 94 of file command.H.

References _is_done.

Referenced by clear().

bool COMMAND::is_undone  )  const [inline]
 

undoit() was called most recently, after doit().

Definition at line 97 of file command.H.

References _is_undone.

int REFcounter::Lock  )  [inline, inherited]
 

Definition at line 105 of file ref.H.

References REFcounter::_mutex, and REFcounter::_u.

Referenced by REFlock::REFlock().

void REFcounter::Own  )  const [inline, inherited]
 

Definition at line 59 of file ref.H.

References REFcounter::_mutex, REFcounter::_u, and REF_ME.

virtual void COMMAND::print  )  const [inline, virtual]
 

Reimplemented in UNDO_CMD, DISPLAY_CMD, and MULTI_CMD.

Definition at line 123 of file command.H.

bool COMMAND::undoit  )  [virtual]
 

Undo the command.

Returns:
true on success. If the command is already undone, this is a no-op and still returns true.

Reimplemented in UNDO_CMD, DISPLAY_CMD, MULTI_CMD, and MESH_SELECT_CMD.

Definition at line 16 of file command.C.

References _is_done, and _is_undone.

Referenced by MESH_SELECT_CMD::undoit(), MULTI_CMD::undoit(), DISPLAY_CMD::undoit(), and UNDO_CMD::undoit().

int REFcounter::Unique  )  const [inline, inherited]
 

Definition at line 115 of file ref.H.

References REFcounter::_mutex, and REFcounter::_u.

void REFcounter::Unlock  )  [inline, inherited]
 

Definition at line 111 of file ref.H.

References REFcounter::_mutex, and REFcounter::_u.

Referenced by REFlock::~REFlock().


Member Data Documentation

bool COMMAND::_is_done [protected]
 

true if doit() was executed most recently.

Definition at line 129 of file command.H.

Referenced by clear(), doit(), is_clear(), is_done(), and undoit().

bool COMMAND::_is_undone [protected]
 

true if undoit() was executed most recently.

Definition at line 130 of file command.H.

Referenced by clear(), doit(), is_clear(), is_undone(), and undoit().


The documentation for this class was generated from the following files:
Generated on Mon Sep 18 11:44:53 2006 for jot by  doxygen 1.4.4