bool parse_dom(MythSettingList &settings, const QDomElement &element, const QString &filename, const QString &group, bool includeAllChildren, bool &foundGroup) { #define LOC QString("parse_dom(%1@~%2), error: ") \ .arg(filename).arg(e.lineNumber()) bool mFoundGroup = false; QDomNode n = element.firstChild(); while (!n.isNull()) { const QDomElement e = n.toElement(); if (e.isNull()) { n = n.nextSibling(); continue; } if (e.tagName() == "group") { QString m_human_label = e.attribute("human_label"); QString m_unique_label = e.attribute("unique_label"); QString m_ecma_script = e.attribute("ecma_script"); bool tmpFoundGroup = false; bool tmpIncludeAllChildren = false || includeAllChildren; if (group.isEmpty() || m_unique_label == group) { mFoundGroup = true; tmpIncludeAllChildren = true; } MythSettingGroup *g = new MythSettingGroup( m_human_label, m_unique_label, m_ecma_script); if ((e.hasChildNodes()) && (!parse_dom(g->m_settings, e, filename, group, tmpIncludeAllChildren, tmpFoundGroup))) { delete g; return false; } if (tmpFoundGroup || tmpIncludeAllChildren) { settings.push_back(g); mFoundGroup = true; } else delete g; } else if (e.tagName() == "setting" && includeAllChildren) { QMap<QString,QString> m; m["value"] = e.attribute("value"); m["setting_type"] = e.attribute("setting_type"); m["label"] = e.attribute("label"); m["help_text"] = e.attribute("help_text"); m["data_type"] = e.attribute("data_type"); MythSetting::DataType dtype = parse_data_type(m["data_type"]); if (MythSetting::kInvalidDataType == dtype) { LOG(VB_GENERAL, LOG_ERR, LOC + "Setting has invalid or missing data_type attribute."); return false; } QStringList data_list; QStringList display_list; if ((MythSetting::kComboBox == dtype) || (MythSetting::kSelect == dtype)) { if (!e.hasChildNodes()) { LOG(VB_GENERAL, LOG_ERR, LOC + "Setting missing selection items."); return false; } QDomNode n2 = e.firstChild(); while (!n2.isNull()) { const QDomElement e2 = n2.toElement(); if (e2.tagName() != "option") { LOG(VB_GENERAL, LOG_ERR, LOC + "Setting selection contains invalid tags."); return false; } QString display = e2.attribute("display"); QString data = e2.attribute("data"); if (data.isEmpty()) { LOG(VB_GENERAL, LOG_ERR, LOC + "Setting selection item missing data."); return false; } display = (display.isEmpty()) ? data : display; data_list.push_back(data); display_list.push_back(display); n2 = n2.nextSibling(); } } if (MythSetting::kIntegerRange == dtype) { m["range_min"] = e.attribute("range_min"); m["range_max"] = e.attribute("range_max"); } QMap<QString,QString>::const_iterator it = m.begin(); for (; it != m.end(); ++it) { if ((*it).isEmpty()) { LOG(VB_GENERAL, LOG_ERR, LOC + QString("Setting has invalid or missing %1 attribute") .arg(it.key())); return false; } } m["default_data"] = e.attribute("default_data"); m["placeholder_text"] = e.attribute("placeholder_text"); MythSetting::SettingType stype = parse_setting_type(m["setting_type"]); if (MythSetting::kInvalidSettingType == stype) { LOG(VB_GENERAL, LOG_ERR, LOC + "Setting has invalid setting_type attribute."); return false; } long long range_min = m["range_min"].toLongLong(); long long range_max = m["range_max"].toLongLong(); if (range_max < range_min) { LOG(VB_GENERAL, LOG_ERR, LOC + "Setting has invalid range attributes"); return false; } MythSetting *s = new MythSetting( m["value"], m["default_data"], stype, m["label"], m["help_text"], dtype, data_list, display_list, range_min, range_max, m["placeholder_text"]); settings.push_back(s); } else if (group.isEmpty()) { LOG(VB_GENERAL, LOG_ERR, LOC + QString("Unknown element: %1").arg(e.tagName())); return false; } n = n.nextSibling(); } if (mFoundGroup) foundGroup = true; return true; #undef LOC }
spell_data_expr_t* spell_data_expr_t::create_spell_expression( sim_t* sim, const std::string& name_str ) { std::vector<std::string> splits = util::string_split( name_str, "." ); if ( splits.empty() || splits.size() > 3 ) return 0; expr_data_e data_type = parse_data_type( splits[ 0 ] ); if ( splits.size() == 1 ) { // No split, access raw list or create a normal expression if ( data_type == ( expr_data_e ) - 1 ) return new spell_data_expr_t( sim, name_str, name_str ); else return new spell_list_expr_t( sim, splits[ 0 ], data_type ); } if ( data_type == ( expr_data_e ) - 1 ) return 0; // Effect handling, set flag and remove effect keyword from tokens bool effect_query = false; if ( util::str_compare_ci( splits[ 1 ], "effect" ) ) { if ( data_type == DATA_EFFECT ) { // "effect.effect"?!? return 0; } effect_query = true; splits.erase( splits.begin() + 1 ); } else if ( util::str_compare_ci( splits[ 1 ], "class" ) ) return new spell_class_expr_t( sim, data_type ); else if ( util::str_compare_ci( splits[ 1 ], "race" ) ) return new spell_race_expr_t( sim, data_type ); else if ( util::str_compare_ci( splits[ 1 ], "attribute" ) ) return new spell_attribute_expr_t( sim, data_type ); else if ( data_type != DATA_TALENT && util::str_compare_ci( splits[ 1 ], "school" ) ) return new spell_school_expr_t( sim, data_type ); else if ( data_type != DATA_TALENT && util::str_compare_ci( splits[ 1 ], "rune" ) ) return new spell_rune_expr_t( sim, data_type ); const sdata_field_t* fields; unsigned fsize; if ( data_type == DATA_TALENT ) { fields = _talent_data_fields; fsize = sizeof( _talent_data_fields ); } else if ( data_type == DATA_SET_BONUS ) { fields = _set_bonus_data_fields; fsize = sizeof( _set_bonus_data_fields ); } else if ( effect_query || data_type == DATA_EFFECT ) { fields = _effect_data_fields; fsize = sizeof( _effect_data_fields ); } else { fields = _spell_data_fields; fsize = sizeof( _spell_data_fields ); } for ( unsigned int i = 0; i < fsize / sizeof( sdata_field_t ); i++ ) { if ( ! fields[ i ].name.empty() && util::str_compare_ci( splits[ 1 ], fields[ i ].name ) ) { return new spell_data_filter_expr_t( sim, data_type, fields[ i ].name, effect_query ); } } return 0; }