Richard Ellingworth / Mbed 2 deprecated RobotRic

Dependencies:   25LCxxx_SPI CommonTypes Gameduino mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers FieldRow.h Source File

FieldRow.h

00001 /*
00002  * SOURCE FILE : FieldRow.h
00003  *
00004  * Definition of class FieldRow.
00005  *
00006  */
00007 
00008 #ifndef FieldRowDefined
00009 
00010   #define FieldRowDefined
00011 
00012   #include "FieldCell.h"
00013   
00014   class FieldRow {
00015 
00016   public :
00017 
00018     /***************/
00019     /* CONSTRUCTOR */
00020     /***************/
00021     FieldRow();
00022 
00023     /**************/
00024     /* DESTRUCTOR */
00025     /**************/
00026     virtual ~FieldRow();
00027 
00028     /*************************/
00029     /* ADD A CELL TO THE ROW */
00030     /*************************/
00031     // Pass cell to add in cell.
00032     // The cell being added must have been dynamically allocated!
00033     void AddCell( FieldCell *cell );
00034 
00035     /*************************/
00036     /* GET FIRST CELL IN ROW */
00037     /*************************/
00038     // Returns pointer to first cell or NULL if no cells in row.
00039     FieldCell *GetFirstCell( void ) {
00040         FieldCell *result = root.GetNext();
00041         if( result == (FieldCell*)NULL ) {
00042             nextCell = (FieldCell*)NULL;
00043         }
00044         else {
00045             nextCell = result->GetNext();
00046         }
00047         return result;
00048     }
00049     
00050     /************************/
00051     /* GET NEXT CELL IN ROW */
00052     /************************/
00053     // Returns pointer to NEXT cell or NULL if no MORE cells in row.
00054     FieldCell *GetNextCell( void ) {
00055         FieldCell *result = nextCell;
00056         if( result != (FieldCell*)NULL ) {
00057             nextCell = result->GetNext();
00058         }
00059         return result;
00060     }
00061     
00062     /**********************************************/
00063     /* GET CELL AT PARTICULAR POSITION IN THE ROW */
00064     /**********************************************/
00065     // Pass index of cell in pos.
00066     // Returns pointer to cell or NULL if no cell at given index.
00067     FieldCell *GetCellAt( UInt8 pos ) {
00068         FieldCell *result = GetFirstCell();
00069         while( ( pos > 0 ) && ( result != (FieldCell*)NULL ) ) {
00070             result = GetNextCell();
00071             pos--;
00072         }
00073         return result;
00074     }
00075 
00076     /********************************/
00077     /* GET NUMBER OF COLUMNS IN ROW */
00078     /********************************/
00079     // Returns number of columns in row.
00080     UInt8 GetColumnCount( void ) {
00081         UInt8 count = 0;
00082         FieldCell *cell = GetFirstCell();
00083         while( cell != (FieldCell*)NULL ) {
00084             count++;
00085             cell = GetNextCell();
00086         }
00087         return count;
00088     }
00089         
00090   private :
00091   
00092     // The root cell of the row.
00093     // Does not contain any useful data and never gets deleted.
00094     FieldCell root;
00095     
00096     // Pointer used when scanning through row cells.
00097     FieldCell *nextCell;
00098             
00099   };
00100 
00101 #endif
00102 
00103 /* END of FieldRow.h */
00104 
00105