Exemplo n.º 1
0
/*
 * Sets the colors used to represent alive and dead cells.
 *
 * INPUT: &cnfg Config file to store characters
 */
void reader::set_colors(config &cnfg)
{
	// Check for the Colors keyword
	int indx1 = data.find("Colors");
	if (indx1 == string::npos) return;
	
	// Find dead RGB
	indx1 = data.find("(", indx1+1);
	int indx2 = data.find(")", indx1+1);
	string str1(data.substr(indx1+1, indx2-indx1-1));
	str1.replace(str1.find(","),1," ");
	str1.replace(str1.find(","),1," ");

	// Parse dead RGB
	int dr, dg, db;
	istringstream stream(str1);
	stream >> dr >> dg >> db;

	// Find alive RGB
	indx1 = data.find("(",indx1+1);
	indx2 = data.find(")",indx1+1);
	string str2(data.substr(indx1+1, indx2-indx1-1));
	str2.replace(str2.find(","),1," ");
	str2.replace(str2.find(","),1," ");

	// Parse alive RGB
	int ar, ag, ab;
	istringstream stream2(str2);
	stream2 >> ar >> ag >> ab;

	// Save to config
	cnfg.set_colors(dr, dg, db, ar, ag, ab);
}