Bläddra i källkod

More new changes by removing old object_operations

Yentl Van Tendeloo 9 år sedan
förälder
incheckning
978793cf38

+ 16 - 0
bootstrap/modelling.alc

@@ -201,6 +201,22 @@ Void function model_delete_link(model : Element, name : String):
 
 	return
 
+Element function read_attribute(model : Element, element : String, attribute : String):
+	// Read out the value of an attribute
+	Element attr_type
+	Element attr_links
+	Element attr_link
+
+	attr_type = find_attribute_type(model, element, attribute)
+	attr_links = allOutgoingAssociationInstances(model, model["model"][element], model["metamodel"]["model"][attr_type])
+
+	while (list_len(attr_links) > 0):
+		attr_link = set_pop(attr_links)
+		return read_edge_dst(attr_link)
+
+	log("Could not find attribute!")
+	return read_root()
+
 Void function unset_attribute(model : Element, element : String, attribute : String):
 	// Removes an attribute if it exists
 	Element attr_type

+ 0 - 39
bootstrap/object_operations.alc

@@ -62,45 +62,6 @@ Element function allIncomingAssociationInstances(model : Element, source : Eleme
 Element function readElementByName(model : Element, name : String):
 	return model["model"][name]
 
-Element function findAttribute(source : Element, attr_name : Element, types : Element, inheritance_link : Element):
-	if (dict_in(source, attr_name)):
-		return dict_read_edge(source, attr_name)
-	else:
-		Integer counter
-		Integer i
-		Element edge
-		counter = read_nr_out(source)
-		i = 0
-		while (i < counter):
-			edge = read_out(source, i)
-			if (element_eq(dict_read_node(types, edge), inheritance_link)):
-				return findAttribute(read_edge_dst(edge), attr_name, types, inheritance_link)
-			i = i + 1
-		// No return at the moment, as this crashes the MvK
-		log("ERROR: could not find attribute")
-
-Element function readAttribute(model : Element, source : Element, attr_name : String):
-	// Read out the edge we are talking about
-	Element edge
-	edge = findAttribute(dict_read_node(model["type_mapping"], source), attr_name, model["type_mapping"], model["inheritance"])
-
-	return read_edge_dst(set_pop(allOutgoingAssociationInstances(model, source, edge)))
-
-Element function deleteAttribute(model : Element, source : Element, attr_name : Element):
-	Element edge
-	edge = findAttribute(dict_read_node(model["type_mapping"], source), attr_name, model["type_mapping"], model["inheritance"])
-
-	Element found_elements
-	found_elements = allOutgoingAssociationInstances(model, source, edge)
-
-	Element rm_element
-	if (list_len(found_elements) > 0):
-		rm_element = read_edge_dst(set_pop(found_elements))
-		dict_delete(model["type_mapping"], rm_element)
-		delete_element(rm_element)
-
-	return edge
-
 Element function getAttributeList(model : Element, element : String):
 	Element result
 	Element keys

+ 13 - 13
integration/code/pn_interface.alc

@@ -45,8 +45,8 @@ Element function petrinet_enabled_set(model : Element):
 
 			Integer present_tokens
 			Integer required_tokens
-			required_tokens = readAttribute(model, arc_under_study, "weight")
-			present_tokens = readAttribute(model, read_edge_src(arc_under_study), "tokens")
+			required_tokens = read_attribute(model, getName(model, arc_under_study), "weight")
+			present_tokens = read_attribute(model, getName(model, read_edge_src(arc_under_study)), "tokens")
 			if (present_tokens < required_tokens):
 				// Less tokens than required, so disable the transition completely
 				enabled = False
@@ -73,20 +73,20 @@ Element function petrinet_fire(model : Element):
 			while (0 < read_nr_out(workset)):
 				working_arc = set_pop(workset)
 				working_place = read_edge_src(working_arc)
-				new_value = integer_subtraction(readAttribute(model, working_place, "tokens"), readAttribute(model, working_arc, "weight"))
+				new_value = integer_subtraction(read_attribute(model, getName(model, working_place), "tokens"), read_attribute(model, getName(model, working_arc), "weight"))
 				unset_attribute(model, getName(model, working_place), "tokens")
 				instantiate_attribute(model, getName(model, working_place), "tokens", new_value)
-				output((("  " + getName(model, working_place)) + ": ") + cast_i2s(readAttribute(model, working_place, "tokens")))
+				output((("  " + getName(model, working_place)) + ": ") + cast_i2s(read_attribute(model, getName(model, working_place), "tokens")))
 
 			// Add tokens
 			workset = allOutgoingAssociationInstances(model, transition, model["metamodel"]["model"]["T2P"])
 			while (0 < read_nr_out(workset)):
 				working_arc = set_pop(workset)
 				working_place = read_edge_dst(working_arc)
-				new_value = integer_addition(readAttribute(model, working_place, "tokens"), readAttribute(model, working_arc, "weight"))
+				new_value = integer_addition(read_attribute(model, getName(model, working_place), "tokens"), read_attribute(model, getName(model, working_arc), "weight"))
 				unset_attribute(model, getName(model, working_place), "tokens")
 				instantiate_attribute(model, getName(model, working_place), "tokens", new_value)
-				output((("  " + getName(model, working_place)) + ": ") + cast_i2s(readAttribute(model, working_place, "tokens")))
+				output((("  " + getName(model, working_place)) + ": ") + cast_i2s(read_attribute(model, getName(model, working_place), "tokens")))
 			output("Transition fired!")
 		else:
 			output("Cannot fire if not enabled; aborting")
@@ -249,17 +249,17 @@ Element function petrinet_loaded(model : Element):
 				if (cast_v2s(read_elem) != "None"):
 					output("Value: " + cast_v2s(read_elem))
 				output("Defines attributes:")
-				attr_list_pn = getInstantiatableAttributes(model, read_elem)
-				attr_keys_pn = dict_keys(attr_list_pn)
-				while (0 < read_nr_out(attr_keys_pn)):
-					attr_key_pn = set_pop(attr_keys_pn)
-					output(((("   " + attr_key_pn) + " : ") + cast_e2s(attr_list_pn[attr_key_pn])))
+				//attr_list_pn = getInstantiatableAttributes(model, read_elem)
+				//attr_keys_pn = dict_keys(attr_list_pn)
+				//while (0 < read_nr_out(attr_keys_pn)):
+				//	attr_key_pn = set_pop(attr_keys_pn)
+				//	output(((("   " + attr_key_pn) + " : ") + cast_e2s(attr_list_pn[attr_key_pn])))
 				output("Attributes:")
-				attr_list_pn = getAttributeList(model, read_elem)
+				attr_list_pn = getAttributeList(model, cmd)
 				attr_keys_pn = dict_keys(attr_list_pn)
 				while (0 < read_nr_out(attr_keys_pn)):
 					attr_key_pn = set_pop(attr_keys_pn)
-					output((((("   " + attr_key_pn) + " : ") + cast_e2s(attr_list_pn[attr_key_pn])) + " = ") + cast_v2s(readAttribute(model, read_elem, attr_key_pn)))
+					output((((("   " + cast_v2s(attr_key_pn)) + " : ") + cast_v2s(attr_list_pn[attr_key_pn])) + " = ") + cast_v2s(read_attribute(model, getName(model, read_elem), attr_key_pn)))
 			else:
 				output("Unknown element; aborting")
 		elif (cmd == "verify"):

+ 1 - 0
interface/HUTN/includes/modelling.alh

@@ -16,3 +16,4 @@ Void function instantiate_named(model : Element, type : String, name : String, s
 Void function define_inheritance(model : Element, inheritance_name : String)
 Void function unset_attribute(model : Element, elem : String, name : String)
 Void function construct_model()
+Element function read_attribute(model : Element, elem : String, name : String)