コード例 #1
0
ファイル: TetGenInterface.cpp プロジェクト: wolf-pf/ogs_kb1
bool TetGenInterface::readElementsFromStream(std::ifstream &ins)
{
	std::string line;
	getline (ins, line);
	size_t pos_beg (line.find_first_not_of(" "));
	size_t n_tets, n_nodes_per_tet;
	bool region_attributes;
	bool not_read_header (true);

	while (!ins.fail() && not_read_header)
	{
		line = line.substr(pos_beg);
		if (line.compare(0,1,"#") == 0)
		{
			// this line is a comment - skip
			getline (ins, line);
			pos_beg = line.find_first_not_of(" ");
		}
		else
			// read header line
			not_read_header = !parseElementsFileHeader(line,
			                                           n_tets,
			                                           n_nodes_per_tet,
			                                           region_attributes);
	}
	if (not_read_header)
		return false;
	if (!parseElements(ins, n_tets, n_nodes_per_tet, region_attributes))
		return false;

	return true;
}
コード例 #2
0
Instruction::Instruction(string pos1, string pos2, string pos3, string pos4, string pos5)
{
	empty = pos1.empty();//if first string is empty, they all are
	if (!isEmpty())
	{
		parseElements(pos1, pos2, pos3, pos4, pos5);
	}
}
コード例 #3
0
void Instruction::parseLine(string line, bool hasAddress)
{
	const int NUM_ELEMENTS = 6;
	string elements[NUM_ELEMENTS]; // each important element of a line
	char linechars[512]; // maybe find a new way to work in a line size
	strcpy_s(linechars, line.c_str());

	int wordstart = 0;
	int currentword = 0;
	bool nextIsIndex = false; // to differentiate the index in the line
	bool nextIsParam2 = false;
	bool parsingWord = true; // to keep track if we are parsing through multiple spaces
	if (linechars[0] == ' ' || linechars[0] == ';') // special case when line starts with space/comment
	{
		parsingWord = false;
	}
	// remove comments and seperate words
	int numchars = line.length();
	for (int i = 0; i < numchars; i++)
	{
		// found a comment
		if (linechars[i] == ';')
		{
			break;
		}

		// found a delimeter
		if (linechars[i] == ' ' || linechars[i] == ',' || linechars[i] == '[' || linechars[i] == ']' || linechars[i] == '\t')
		{
			if (parsingWord)
			{
				elements[currentword] = line.substr(wordstart, (i)-wordstart);
				if (nextIsIndex)
				{
					elements[currentword] = "[" + elements[currentword];// append a [ to signify an index
					nextIsIndex = false;
				}
				else if (nextIsParam2)
				{
					elements[currentword] = "," + elements[currentword];// append a , to signify a second parameter
					nextIsParam2 = false;
				}
				parsingWord = false;
				++currentword;
				if (currentword > NUM_ELEMENTS - 1)
				{
					break;
				}
			}
			if (linechars[i] == '[')
			{
				nextIsIndex = true;
			}
			else if (linechars[i] == ',')
			{
				nextIsParam2 = true;
			}

		}
		else // found a character
		{
			line[i] = toupper(line[i]);//convert thi char in the command to uppercase
			if (!parsingWord)
			{
				parsingWord = true;
				wordstart = i;
			}
		}
	}

	// catches last word of a line
	if (parsingWord)
	{
		elements[currentword] = line.substr(wordstart, (numchars)-wordstart);
		if (nextIsIndex)
		{
			elements[currentword] = "[" + elements[currentword];// append a [ to signify an index
		}
		else if (nextIsParam2)
		{
			elements[currentword] = "," + elements[currentword];// append a , to signify a second parameter
		}
	}
	if (elements[0] == "")
	{
		empty = true;
	}
	else if (hasAddress)
	{
		loc = strToInt(elements[0]);
		parseElements(elements[1], elements[2], elements[3], elements[4], elements[5]);
	}
	else
	{
		parseElements(elements[0], elements[1], elements[2], elements[3], elements[4]);
	}
}
コード例 #4
-1
ファイル: parseur.c プロジェクト: PierrickJACQUETTE/CPROJ
Map* parseDoc(char* filename){

	xmlDocPtr doc;
	xmlNodePtr root_element;
	doc = xmlParseFile(filename);

	if (doc == NULL) {
		fprintf(stderr, "Failed to parse %s\n", filename);
		return NULL;
	}

	root_element = xmlDocGetRootElement(doc);

	if (root_element == NULL){
		fprintf(stderr, "empty document\n");
		xmlFreeDoc(doc);
		return NULL;
	}

	Map* map = malloc(sizeof(Map));
	map = parseElements(doc, root_element);
	xmlFreeDoc(doc);
	return map;
}