// Generation.cpp: implementation of the Generation class. // ////////////////////////////////////////////////////////////////////// #include "Generation.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// int Generation::instCount = 0; Generation::Generation(int size) { this->size = size; pArray = (CELL *) malloc(size * sizeof(CELL)); instCount++; } Generation::Generation(Generation& master) { size = master.size; pArray = (CELL *) malloc(size * sizeof(CELL)); memcpy(pArray, master.pArray, size * sizeof(CELL)); instCount++; } Generation::~Generation() { free(pArray); instCount--; } Generation& Generation::operator=(Generation& master) { free(pArray); size = master.size; pArray = (CELL *) malloc(size * sizeof(CELL)); memcpy(pArray, master.pArray, size * sizeof(CELL)); return *this; } int Generation::operator==(Generation& right) { int i; if(size == right.size) { for(i = 0; i < size; i++) { if(*(pArray + i) != *(right.pArray + i)) { return 0; } } return 1; } return 0; } int Generation::operator<(Generation& right) { int i; if(size < right.size) return 1; else if(size == right.size) { for(i = 0; i < size; i++) { if(*(pArray + i) < *(right.pArray + i)) return 1; else if(*(pArray + i) > *(right.pArray + i)) return 0; } } return 0; } void Generation::print(FILE* f) { int i; char buff[1024]; for(i = 0; i < size && i < 1024 - 1; i++) *(buff + i) = (*(pArray + i) > 0)? '1' : '0'; *(buff + i) = '\0'; fprintf(f, "%s", buff); } void Generation::rotateLeft() { int i; CELL temp = *pArray; for(i = 0; i < size - 1; i++) *(pArray + i) = *(pArray + i + 1); *(pArray + i) = temp; }