Exemple #1
0
void XmlParser::rootNode(TiXmlNode* pParent, const string& filename) {
	int t = pParent->Type();
	TiXmlNode* pChild;

	/* Loop over children */
	for (pChild = pParent->FirstChild(); pChild != 0; pChild = pChild->NextSibling()) {

		if (t == TiXmlNode::ELEMENT) {
			/* Element value */
			string element_value(pParent->Value());
			map<string,NodeParser>::const_iterator it_root = root_map.find(element_value);

			/* Check node parser map */
			if(it_root != root_map.end()) {
				/* File name */
				Log::msg() << " - Reading node ";
				Log::color<Log::COLOR_BOLDWHITE>() << setw(9) << element_value << Log::crst;
				Log::msg()  << " from file " + filename << Log::endl;
				/* Process node */
				NodeParser parser_function = (*it_root).second;
				(this->*parser_function)(pParent);
			}
			else {
				vector<string> keywords;
				keywords.push_back(element_value);
				throw KeywordParserError("Unrecognized root node <" + element_value + "> on file " + filename,keywords);
			}

			/* Done with this node */
			return;
		}

		rootNode(pChild,filename);
	}
}
Exemple #2
0
void XmlParser::XmlAttributes::checkAttributes(const XmlParser::AttribMap& attrib_map, const string& object) {
	/* Check for required parameters */
	vector<string>::iterator it_req;
	for(it_req = required.begin() ; it_req != required.end() ; ++it_req) {
		string req_attrib = *it_req;
		if(attrib_map.find(req_attrib) == attrib_map.end()) {
			/* We should construct the keywords to locate this line on the file */
			vector<string> keywords;
			AttribMap::const_iterator it_att = attrib_map.begin();
			for(; it_att != attrib_map.end() ; ++it_att) {
				keywords.push_back((*it_att).first);
				keywords.push_back((*it_att).second);
			}
			throw KeywordParserError("Missing <" + req_attrib + "> attribute in " + object + " definition",keywords);
		}
	}

	/* If all required attributes are there, we should check the optional attributes */
	AttribMap::const_iterator it_att = attrib_map.begin();

	for(; it_att != attrib_map.end() ; ++it_att) {
		/* User attribute on input */
		string user_attrib = (*it_att).first;
		vector<string>::iterator it_exp;

		/* Check on required container */
		it_exp = find(required.begin(), required.end(), user_attrib);
		if(it_exp == required.end()) {
			/* Check on optional container */
			it_exp = find(optional.begin(), optional.end(), user_attrib);
			if(it_exp == optional.end()) {
				/* We should construct the keywords to locate this line on the file */
				vector<string> keywords;
				AttribMap::const_iterator it_att = attrib_map.begin();
				for(; it_att != attrib_map.end() ; ++it_att) {
					keywords.push_back((*it_att).first);
					keywords.push_back((*it_att).second);
				}
				throw KeywordParserError("Bad attribute keyword <" + user_attrib + "> in " + object + " definition", keywords);
			}

		}
	}
}
Exemple #3
0
void XmlParser::srcNode(TiXmlNode* pParent) {

	TiXmlNode* pChild;
	for (pChild = pParent->FirstChild(); pChild != 0; pChild = pChild->NextSibling()) {
		int t = pChild->Type();
		if (t == TiXmlNode::ELEMENT) {
			string element_value(pChild->Value());
			if (element_value == "dist")
				objects.push_back(distAttrib(pChild->ToElement()));
			else if (element_value == "sampler")
				objects.push_back(samplerAttrib(pChild->ToElement()));
			else if (element_value == "source")
				objects.push_back(sourceAttrib(pChild->ToElement()));
			else {
				vector<string> keywords;
				keywords.push_back(element_value);
				throw KeywordParserError("Unrecognized source keyword <" + element_value + ">",keywords);
			}
		}
	}
}
void XmlParser::matNode(TiXmlNode* pParent) {

    TiXmlNode* pChild;
    for (pChild = pParent->FirstChild(); pChild != 0; pChild = pChild->NextSibling()) {
        int t = pChild->Type();
        if (t == TiXmlNode::ELEMENT) {
            string element_value(pChild->Value());
            if (element_value == "macro-xs")
                objects.push_back(macroAttrib(pChild->ToElement()));
            else if (element_value == "material") {
                vector<McObject*> ace_objects = aceAttrib(pChild->ToElement());
                objects.insert(objects.end(), ace_objects.begin(), ace_objects.end());
            } else {
                vector<string> keywords;
                keywords.push_back(element_value);
                throw KeywordParserError("Unrecognized material keyword <" + element_value + ">",keywords);
            }
        }
    }

}