Browse Source

Add new function to get a list of all attributes

Yentl Van Tendeloo 7 years ago
parent
commit
b34cff799a
2 changed files with 26 additions and 0 deletions
  1. 25 0
      bootstrap/object_operations.alc
  2. 1 0
      interface/HUTN/includes/object_operations.alh

+ 25 - 0
bootstrap/object_operations.alc

@@ -136,6 +136,31 @@ Element function getAttributeList(model : Element, element : String):
 
 
 	return result!
 	return result!
 
 
+Element function getAttributes(model : Element, element : String):
+	Element result
+	Element keys
+	Element type
+	Element attr_name
+	Element types
+	Element mm
+
+	result = dict_create()
+	mm = model["metamodel"]["model"]
+	types = get_superclasses(model["metamodel"], read_type(model, element))
+
+	while (set_len(types) > 0):
+		type = set_pop(types)
+
+		// Add our own attributes
+		keys = dict_keys(mm[type])
+		while (set_len(keys) > 0):
+			attr_name = set_pop(keys)
+			if (is_physical_string(attr_name)):
+				// WARNING: do not change this to dict_add_fast, as this crashes random code...
+				dict_add(result, attr_name, read_attribute(model, element, attr_name))
+
+	return result!
+
 Element function getInstantiatableAttributes(model : Element, element : String, type : String):
 Element function getInstantiatableAttributes(model : Element, element : String, type : String):
 	Element all_links
 	Element all_links
 	Element result
 	Element result

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

@@ -4,6 +4,7 @@ Element function selectPossibleOutgoing(model : Element, source : String, limit_
 Element function allOutgoingAssociationInstances(model: Element, source_name : String, assoc_name: String)
 Element function allOutgoingAssociationInstances(model: Element, source_name : String, assoc_name: String)
 Element function allIncomingAssociationInstances(model: Element, target_name : String, assoc_name: String)
 Element function allIncomingAssociationInstances(model: Element, target_name : String, assoc_name: String)
 Element function getAttributeList(model: Element, element: String)
 Element function getAttributeList(model: Element, element: String)
+Element function getAttributes(model: Element, element: String)
 Element function getInstantiatableAttributes(model: Element, element: String, type: String)
 Element function getInstantiatableAttributes(model: Element, element: String, type: String)
 String function print_dict(dict : Element)
 String function print_dict(dict : Element)
 String function readAssociationSource(model : Element, name : String)
 String function readAssociationSource(model : Element, name : String)