Rule Class Reference

Model class for a rule. More...

#include <rule.hpp>

Collaboration diagram for Rule:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Rule (int width, int height)
 Constructor.
virtual ~Rule ()
 Destructor.
bool operator== (Rule rule)
 Compares two rules.
bool cellChanged (int x, int y, int status, GridType layout)
 Changes the status of a cell to status.
Grid getInitialGrid ()
 Member accessor.
void setInitialGrid (Grid newGrid)
 Sets the grid for the rule initial configuration.
Grid getFinalGrid ()
 Member accessor.
void setFinalGrid (Grid newGrid)
 Sets the grid for the rule final configuration.
bool cellChanged (int x, int y, GridType layout)
 Cell status change.
int getWidth ()
 Member accessor.
int getHeight ()
 Member accessor.
bool equals (Rule *rule)
 Tests two rules for equality.
bool sameInitialFinal ()
 Compares the initial and final configurations of a rule.
bool valid ()
 Checks if a rule is valid.
void print ()
matrix getInitialMatrix ()
 Member accessor.
matrix getFinalMatrix ()
 Member accessor.

Private Attributes

int width
 Rule width.
int height
 Rule height.
Grid initialGrid
 Rule initial configuration.
Grid finalGrid
 Rule final configuration.

Detailed Description

Model class for a rule.

This is a class representing a rule.

Author:
Bernat Ràfales Mulet <the_bell@users.sourceforge.net>
Version:
Revision
1.14

Definition at line 46 of file rule.hpp.


Constructor & Destructor Documentation

Rule::Rule int  width,
int  height
 

Constructor.

Parameters:
width the rule width.
height the rule height.

Definition at line 33 of file rule.cpp.

Rule::~Rule  )  [virtual]
 

Destructor.

Definition at line 42 of file rule.cpp.


Member Function Documentation

bool Rule::cellChanged int  x,
int  y,
GridType  layout
 

Cell status change.

This is called from the manager when a cell recieves a change status signal We must know the current status and try to set the new one. Cell status changes are "Don't care" -> "Enabled" -> "Disabled"

Parameters:
x x coordinate.
y y coordinate.
layout the grid, can be the initial configuration or the final one.
Returns:
True if the status change was made correctly.

Definition at line 97 of file rule.cpp.

References finalGrid, initialGrid, nDISABLED, nDONTCARE, nENABLED, nFINAL, and nINITIAL.

bool Rule::cellChanged int  x,
int  y,
int  status,
GridType  layout
 

Changes the status of a cell to status.

Parameters:
x the x coordinate.
y the y coordinate.
status the status to set.
layout the grid to change, can be the initial layout or the final layout.
Returns:
True if the change was made successfully.

Definition at line 169 of file rule.cpp.

References finalGrid, initialGrid, nFINAL, and nINITIAL.

Referenced by RuleDiskManager::readRule().

bool Rule::equals Rule rule  ) 
 

Tests two rules for equality.

Parameters:
rule the rule to be compared.
Returns:
True if the rules were equal. This is, have the same width and height and all the cells have the same status. False otherwise.

Definition at line 197 of file rule.cpp.

References getHeight(), and getWidth().

Here is the call graph for this function:

Grid Rule::getFinalGrid  ) 
 

Member accessor.

Returns:
The final grid of the rule.

Definition at line 81 of file rule.cpp.

References finalGrid.

Referenced by Simulation::applyRule(), operator==(), and RuleDiskManager::saveRule().

matrix Rule::getFinalMatrix  ) 
 

Member accessor.

Returns:
The initial grid as a matrix.

Definition at line 276 of file rule.cpp.

References finalGrid, and Grid::getCells().

Here is the call graph for this function:

int Rule::getHeight  ) 
 

Member accessor.

Returns:
The rule height.

Definition at line 61 of file rule.cpp.

References height.

Referenced by Simulation::applyRule(), equals(), operator==(), sameInitialFinal(), RuleDiskManager::saveRule(), and valid().

Grid Rule::getInitialGrid  ) 
 

Member accessor.

Returns:
The initial rule grid.

Definition at line 71 of file rule.cpp.

References initialGrid.

Referenced by Simulation::applyRule(), operator==(), and RuleDiskManager::saveRule().

matrix Rule::getInitialMatrix  ) 
 

Member accessor.

Returns:
The initial grid as a matrix.

Definition at line 266 of file rule.cpp.

References Grid::getCells(), and initialGrid.

Here is the call graph for this function:

int Rule::getWidth  ) 
 

Member accessor.

Returns:
The rule width.

Definition at line 51 of file rule.cpp.

References width.

Referenced by Simulation::applyRule(), equals(), operator==(), SimulationManager::printRule(), Simulation::printRule(), Simulation::ruleApplicable(), sameInitialFinal(), RuleDiskManager::saveRule(), and valid().

bool Rule::operator== Rule  rule  ) 
 

Compares two rules.

Parameters:
rule the rule to be compared.
Returns:
True if the two rules equal, false otherwise.
See also:
equals(Rule *rule).

Definition at line 288 of file rule.cpp.

References finalGrid, getFinalGrid(), getHeight(), getInitialGrid(), getWidth(), and initialGrid.

Here is the call graph for this function:

void Rule::print  ) 
 

bool Rule::sameInitialFinal  ) 
 

Compares the initial and final configurations of a rule.

Returns:
True if the initial and final configurations equal.

Definition at line 223 of file rule.cpp.

References finalGrid, getHeight(), getWidth(), and initialGrid.

Here is the call graph for this function:

void Rule::setFinalGrid Grid  newGrid  ) 
 

Sets the grid for the rule final configuration.

Parameters:
newGrid the grid.

Definition at line 155 of file rule.cpp.

References finalGrid, and Grid::init().

Here is the call graph for this function:

void Rule::setInitialGrid Grid  newGrid  ) 
 

Sets the grid for the rule initial configuration.

Parameters:
newGrid the grid.

Definition at line 145 of file rule.cpp.

References Grid::init(), and initialGrid.

Here is the call graph for this function:

bool Rule::valid  ) 
 

Checks if a rule is valid.

Returns:
True if the rule is valid. This is, if there's no cells on the final configurations in the nENABLED mode and the corresponding cell n the initial configuration on the nDONTCARE status. False otherwise.

Definition at line 246 of file rule.cpp.

References finalGrid, getHeight(), getWidth(), initialGrid, nDISABLED, nDONTCARE, and nENABLED.

Here is the call graph for this function:


Member Data Documentation

Grid Rule::finalGrid [private]
 

Rule final configuration.

Definition at line 75 of file rule.hpp.

Referenced by cellChanged(), getFinalGrid(), getFinalMatrix(), operator==(), sameInitialFinal(), setFinalGrid(), and valid().

int Rule::height [private]
 

Rule height.

Definition at line 71 of file rule.hpp.

Referenced by getHeight().

Grid Rule::initialGrid [private]
 

Rule initial configuration.

Definition at line 73 of file rule.hpp.

Referenced by cellChanged(), getInitialGrid(), getInitialMatrix(), operator==(), sameInitialFinal(), setInitialGrid(), and valid().

int Rule::width [private]
 

Rule width.

Definition at line 69 of file rule.hpp.

Referenced by getWidth().


The documentation for this class was generated from the following files:
Generated on Fri Sep 1 23:59:35 2006 for NanoComp by  doxygen 1.4.6