Esempio n. 1
0
Mtbdd
SystemParser::nodeToMtbdd(const TiXmlNode* node)
{
    // Have we reached a leaf of the (MT)BDD?
    if (hasAttribute(node, "const_value")) {
        if (leaf_type == float_type) {
            return readDoubleAttribute(node, "const_value");
        } else if (leaf_type == simple_fraction_type) {
            return readSimpleFractionAttribute(node, "const_value");
        } else if (leaf_type == mpq_type) {
            return readMPQAttribute(node, "const_value");
        }
    }

    // The node references another node
    if (hasAttribute(node, "node_ref")) {
        const std::map<std::string, Mtbdd>::const_iterator it =
                build_table.find(readStringAttribute(node, "node_ref"));
        assert(it != build_table.end());
        return it->second;
    }

    // Proper internal node
    const TiXmlNode* child = node->FirstChild();

    // Must have internal id and a variable index
    assert(strcmp(child->Value(), "dd_node")==0);
    assert(hasAttribute(child, "id"));
    assert(hasAttribute(child, "index"));

    // Read the attributes of the node
    const std::string id = readStringAttribute(child, "id");
    const unsigned int index = readIntAttribute(child, "index");

    // Get the then-child of the node
    const TiXmlNode* then_node = child->FirstChild();
    assert(then_node != NULL);
    assert(strcmp(then_node->Value(), "dd_then") == 0);
    Mtbdd then_result = nodeToMtbdd(then_node);

    // Get the else-child of the node
    const TiXmlNode* else_node = then_node->NextSibling();
    assert(else_node != NULL);
    assert(strcmp(else_node->Value(), "dd_else") == 0);
    Mtbdd else_result = nodeToMtbdd(else_node);

    const Mtbdd result = var_to_mtbdd[index].Ite(then_result, else_result);

    if (build_table.find(id) != build_table.end()) {
        assert(build_table[id] == result);
    } else {
        build_table[id] = result;
    }

    return result;
}
//---------------------------------------------------------
double ofxXmlSettings::getAttribute(const string& tag, const string& attribute, double defaultValue, int which){
    double value = defaultValue;
	readDoubleAttribute(tag, attribute, value, which);
	return value;
}