00001 00006 #ifndef __CELL_H__ 00007 #define __CELL_H__ 00008 00009 #include "../Lib/Observer.h" 00010 #include "../Lib/CellAttribute.h" 00011 00015 class Cell : public Subject, Observer 00016 { 00017 public: 00018 00022 Cell() 00023 { 00024 this->init(); 00025 } 00026 00030 virtual ~Cell() { } 00031 00037 void init() 00038 { 00039 this->m_lNeighborAliveNum = 0; 00040 this->m_cAttribute.setState(CellAttribute::DEAD); 00041 } 00042 00050 CellAttribute::CELL_STATE getState() const 00051 { 00052 return (this->m_cAttribute.getState()); 00053 } 00054 00060 void setState(CellAttribute::CELL_STATE i_eState) 00061 { 00062 this->m_cAttribute.setState(i_eState); 00063 } 00064 00070 void setNeighbor(Cell* i_pCell) 00071 { 00072 this->attach(i_pCell); 00073 } 00074 00082 bool sendState() 00083 { 00084 this->notify(&(this->m_cAttribute)); 00085 return true; 00086 } 00087 00097 bool decideState(); 00098 00105 bool update(Information* i_pcInformation) 00106 { 00107 this->receiveStateFromNeighborCell( static_cast<CellAttribute*>(i_pcInformation) ); 00108 return true; 00109 } 00110 00117 long getNeighborAliveNum() const 00118 { 00119 return this->m_lNeighborAliveNum; 00120 } 00121 00122 private: 00123 00128 CellAttribute m_cAttribute; 00129 00133 long m_lNeighborAliveNum; 00134 00142 bool receiveStateFromNeighborCell(CellAttribute* i_pcCellAttribute) 00143 { 00144 if(CellAttribute::ALIVE == i_pcCellAttribute->getState()) 00145 { 00146 this->m_lNeighborAliveNum++; 00147 } 00148 return true; 00149 } 00150 00159 bool isBorn(); 00160 00169 bool isSurvive(); 00170 00179 bool isUnderPopulation(); 00180 00189 bool isOverPopulation(); 00190 00191 }; 00192 00193 #endif //__CELL_H__