#ifndef __CELL_H
#define __CELL_H

////////////////////////////////////////////////////////////////////////
//
// Name:	BinaryCell.h
//
// Purpose:	Contains class definition for the cellular automata cell
//			having a binary state.
//
////////////////////////////////////////////////////////////////////////

#include <iostream.h>


class BinaryCell {

public:
	enum State_t	{ DEAD, ALIVE };

	BinaryCell() : state(DEAD) {}

	BinaryCell(const BinaryCell& C)	: state(C.state) {}

	BinaryCell(const State_t& s) : state(s) {}

	BinaryCell& operator=(const BinaryCell& C)
		{
			if (this != &C) {
				delete this;
				state = C.state;
			}
			return *this;
		}

	BinaryCell& operator=(const State_t& s)
		{
			state = s;
			return *this;
		}

	void SetState(const State_t& s)
		{ state = s; }

	void Toggle()
		{ state = (state==ALIVE) ? DEAD : ALIVE; }

	State_t State()	const
		{ return state==1 ? ALIVE : DEAD; }

	int isAlive() const
		{ return state==ALIVE; }

	int isDead() const
		{ return state==DEAD; }

private:
	// This declares a packed object, requiring only one bit!
	// Note that the use of these "bit fields" is not
	// considered portable because it makes assumptions
	// about how the machine organizes data.
	unsigned state : 1;	// "state" of the cell

	// Keep this around just in case for portability
//	State_t	state;	// "state" of the cell
};


#endif // __CELL_H
