예제 #1
0
/*
 * Set the initial 'alive' cells.
 * 
 * INPUT: &cnfg Config file to store initial 'alive' cells
 */
void reader::set_living(config &cnfg)
{
	int start, end;

	// Check if the keyword exists
	start = data.find("Initial");
	if (start == string::npos || start >= data.size()) return; 

	// Find the start and end index of the "Initial" statement
	start = data.find("{", start+7);
	end = data.find("}", start+1);
	// Make sure a complete statement exists
	if (start == string::npos || start >= data.size() || end == string::npos || end >= data.size()) return;	

	int x, y;
	bool done = false;
	istringstream stream(data.substr(start, end-start+1));
	
	while (stream.good()) {
		// Find the next 'Y' char
		if (stream.peek() == 'Y') {
			done = false;

			// Process the column of alive cells (current row in .aut file)
			while (!done) {
				// Grab the y coordinate
				if (isdigit(stream.peek()) || stream.peek() == '-') {
					stream >> y;

					// Grab the x coordinates
					while (1) {
						if (isdigit(stream.peek()) || stream.peek() == '-') {
							stream >> x;	
							cnfg.add(x, y);
						}
						else if (stream.peek() == ';') break;
						else stream.get();
					} // End x coordinates

					done = true;
				}