/* Parse cell attributes */ static vector<McObject*> aceAttrib(TiXmlElement* pElement) { /* Initialize XML attribute checker */ static const string required[4] = {"id","density","units","fraction"}; static XmlParser::XmlAttributes matAttrib(vector<string>(required, required + 4), vector<string>()); /* Check flags */ XmlParser::AttributeValue<string> units_flag("units","",initUnits()); XmlParser::AttributeValue<string> fraction_flag("fraction","",initFraction()); XmlParser::AttribMap mapAttrib = dump_attribs(pElement); /* Check user input */ matAttrib.checkAttributes(mapAttrib, "material"); /* Get attributes */ MaterialId id = fromString<MaterialId>(mapAttrib["id"]); double density = fromString<double>(mapAttrib["density"]); std::string units = units_flag.getValue(mapAttrib); std::string fraction = fraction_flag.getValue(mapAttrib); /* Push all the ACE objects (including the isotopes) */ vector<McObject*> ace_objects; /* Get isotopes */ TiXmlElement* pChild; map<string,double> isotopes; for (pChild = pElement->FirstChildElement(); pChild != 0; pChild = pChild->NextSiblingElement()) { string element_value(pChild->Value()); pair<string,double> pair_value = isoAttrib(pChild); string isotope = pair_value.first; /* Check if the user is not duplicating the isotope name */ map<string,double>::iterator it = isotopes.find(isotope); if(it == isotopes.end()) { /* Push isotope */ isotopes.insert(pair_value); ace_objects.push_back(new AceObject(pair_value.first)); } else { /* Duplicated name of isotope */ std::vector<std::string> keywords; XmlParser::AttribMap::const_iterator it_att = mapAttrib.begin(); for(; it_att != mapAttrib.end() ; ++it_att) { keywords.push_back((*it_att).first); keywords.push_back((*it_att).second); } throw Parser::KeywordParserError("Duplicated isotope with name " + isotope,keywords); } } /* Return surface definition */ ace_objects.push_back(new AceMaterialObject(id, density, units, fraction, isotopes)); return ace_objects; }
/* Parse cell attributes */ static McObject* macroAttrib(TiXmlElement* pElement) { /* Initialize XML attribute checker */ static const string required[6] = {"id","sigma_a","sigma_f","nu_sigma_f","chi","sigma_s"}; static XmlParser::XmlAttributes matAttrib(vector<string>(required, required + 6), vector<string>()); XmlParser::AttribMap mapAttrib = dump_attribs(pElement); /* Check user input */ matAttrib.checkAttributes(mapAttrib, "macro-xs"); /* Constants */ std::map<std::string,std::vector<double> > constant; for(XmlParser::AttribMap::const_iterator it = mapAttrib.begin() ; it != mapAttrib.end() ; ++it) { string attrib_name = (*it).first; if(attrib_name != "id") constant[attrib_name] = getContainer<double>((*it).second); } /* Get attributes */ MaterialId mat_id = fromString<MaterialId>(mapAttrib["id"]); /* Return surface definition */ return new MacroXsObject(mat_id,constant); }
/* Parse distribution attributes */ static SourceObject* distAttrib(TiXmlElement* pElement) { /* Initialize XML attribute checker */ static const string required[2] = {"id", "type"}; static XmlParser::XmlAttributes distAttrib(vector<string>(required, required + 2), vector<string>()); XmlParser::AttributeValue<string> typeDist("type","",initTypeDist()); XmlParser::AttribMap mapAttrib = dump_attribs(pElement); /* Get type (first check if the attribute is defined) */ XmlParser::AttribMap::const_iterator it_att = mapAttrib.find("type"); if(it_att == mapAttrib.end()) { /* Attribute is not defined, throw an exception */ std::vector<std::string> keywords; it_att = mapAttrib.begin(); for(; it_att != mapAttrib.end() ; ++it_att) { keywords.push_back((*it_att).first); keywords.push_back((*it_att).second); } throw Parser::KeywordParserError("Attribute <type> is not defined for a distribution",keywords); } string type = typeDist.getValue(mapAttrib); /* Return surface definition */ return mapParser[type](pElement); }
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); } } } }