123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- include "primitives.alh"
- include "conformance_scd.alh"
- include "constructors.alh"
- Element function allInstances(model_ai : Element, type_ai : Element):
- Element type_mapping_ai
- Element result_ai
- type_mapping_ai = dict_read(model_ai, "type_mapping")
- result_ai = create_node()
- Integer counter_ai
- counter_ai = 0
- Integer length_ai
- length_ai = read_nr_out(type_mapping_ai)
- Element edge_ai
- while (integer_lt(counter_ai, length_ai)):
- edge_ai = read_out(type_mapping_ai, counter_ai)
- if (element_eq(read_edge_dst(edge_ai), type_ai)):
- // Found an element of the specified type
- set_add(result_ai, read_edge_dst(read_out(edge_ai, 0)))
- counter_ai = integer_addition(counter_ai, 1)
-
- return result_ai
- Element function allOutgoingAssociationInstances(model_aoai : Element, source_aoai : Element, assoc_aoai : Element):
- // Read out all outgoing edges of the model and select those that are typed by the specified association
- // TODO for some reason this crashes if allInstances is used!
- Integer length_aoai
- length_aoai = read_nr_out(source_aoai)
- Integer counter_aoai
- counter_aoai = 0
- Element result_aoai
- result_aoai = create_node()
- Element edge_aoai
- while (integer_lt(counter_aoai, length_aoai)):
- edge_aoai = read_out(source_aoai, counter_aoai)
- if (element_eq(dict_read_node(dict_read(model_aoai, "type_mapping"), edge_aoai), assoc_aoai)):
- set_add(result_aoai, edge_aoai)
- counter_aoai = integer_addition(counter_aoai, 1)
- return result_aoai
- Element function allIncomingAssociationInstances(model_aiai : Element, source_aiai : Element, assoc_aiai : Element):
- // Read out all outgoing edges of the model and select those that are typed by the specified association
- Element result_aiai
- result_aiai = create_node()
- Element allinsts_aiai
- allinsts_aiai = allInstances(model_aiai, assoc_aiai)
- Element understudy_aiai
- while (integer_lt(0, read_nr_out(allinsts_aiai))):
- understudy_aiai = set_pop(allinsts_aiai)
- if (element_eq(read_edge_dst(understudy_aiai), source_aiai)):
- set_add(result_aiai, understudy_aiai)
- return result_aiai
- Element function readElementByName(model_rebn : Element, name_rebn : String):
- return dict_read(dict_read(model_rebn, "model"), name_rebn)
- Element function findAttribute(source_fa : Element, attr_name_fa : Element, types_fa : Element, inheritance_link_fa : Element):
- if (dict_in(source_fa, attr_name_fa)):
- return dict_read_edge(source_fa, attr_name_fa)
- else:
- Integer counter_fa
- Integer i_fa
- Element edge_fa
- counter_fa = read_nr_out(source_fa)
- i_fa = 0
- while (integer_lt(i_fa, counter_fa)):
- edge_fa = read_out(source_fa, i_fa)
- if (element_eq(dict_read_node(types_fa, edge_fa), inheritance_link_fa)):
- return find_attribute(read_edge_dst(edge_fa), attr_name_fa, types_fa, inheritance_link_fa)
- i_fa = integer_addition(i_fa, 1)
- // No return at the moment, as this crashes the MvK
- log("ERROR: could not find attribute")
- Element function readAttribute(model_ra : Element, source_ra : Element, attr_name_ra : String):
- // Read out the edge we are talking about
- Element edge_ra
- edge_ra = findAttribute(dict_read_node(dict_read(model_ra, "type_mapping"), source_ra), attr_name_ra, dict_read(model_ra, "type_mapping"), dict_read(model_ra, "inheritance"))
- return read_edge_dst(set_pop(allOutgoingAssociationInstances(model_ra, source_ra, edge_ra)))
- Element function setAttribute(model_sa : Element, source_sa : Element, attr_name_sa : String, value_sa : Element):
- // Read out which edge we are talking about
- Element edge_sa
- edge_sa = deleteAttribute(model_sa, source_sa, attr_name_sa)
- // Now make the element
- Element created_edge_sa
- created_edge_sa = create_edge(source_sa, value_sa)
- dict_add(dict_read(model_sa, "type_mapping"), created_edge_sa, edge_sa)
- dict_add(dict_read(model_sa, "type_mapping"), value_sa, read_edge_dst(edge_sa))
- add_to_model(model_sa, "", value_sa)
- add_to_model(model_sa, "", created_edge_sa)
- return True
- Element function deleteAttribute(model_da : Element, source_da : Element, attr_name_da : Element):
- Element edge_da
- edge_da = findAttribute(dict_read_node(dict_read(model_da, "type_mapping"), source_da), attr_name_da, dict_read(model_da, "type_mapping"), dict_read(model_da, "inheritance"))
- Element found_elements_da
- found_elements_da = allOutgoingAssociationInstances(model_da, source_da, edge_da)
- Element rm_element_da
- if (integer_gt(list_len(found_elements_da), 0)):
- rm_element_da = read_edge_dst(set_pop(found_elements_da))
- dict_delete(dict_read(model_da, "type_mapping"), rm_element_da)
- delete_element(rm_element_da)
- return edge_da
- Element function getAttributeList(model_gali : Element, mm_gali : Element):
- Element result_gali
- result_gali = create_node()
- // Get all outgoing "dictionary" links
- Element set_gali_own
- set_gali_own = dict_keys(mm_gali)
- // Filter them
- Element e_gali
- while (integer_lt(0, read_nr_out(set_gali_own))):
- e_gali = set_pop(set_gali_own)
- if (type_eq(typeof(e_gali), String)):
- if (type_eq(typeof(dict_read(mm_gali, e_gali)), Type)):
- // This is a primitive type, so add to the list
- dict_add(result_gali, e_gali, dict_read(mm_gali, e_gali))
- // And go up to the possible supertypes
- Element found_elements_gali
- found_elements_gali = allOutgoingAssociationInstances(model_gali, mm_gali, dict_read(model_gali, "inheritance"))
- Element dict_gali_super
- Integer i_gali
- Integer max_gali
- Element set_gali_super
- Element found_key_gali
- while (integer_lt(0, read_nr_out(found_elements_gali))):
- // Now find the destination of these associations, which are the superclasses of this model
- dict_gali_super = getAttributeList(model_gali, read_edge_dst(set_pop(found_elements_gali)))
- set_gali_super = dict_keys(dict_gali_super)
- // Merge the two
- while (integer_lt(0, read_nr_out(set_gali_super))):
- found_key_gali = set_pop(set_gali_super)
- dict_add(result_gali, found_key_gali, dict_read(dict_gali_super, found_key_gali))
- return result_gali
- Element function getInstantiatableAttributes(model_gili : Element, element_gili : Element):
- Element result_gili
- result_gili = create_node()
- // Get all outgoing "dictionary" links
- Element set_gili_own
- set_gili_own = dict_keys(element_gili)
- // Filter them
- Element e_gili
- while (integer_lt(0, read_nr_out(set_gili_own))):
- e_gili = set_pop(set_gili_own)
- if (bool_and(type_eq(typeof(e_gili), String), type_eq(typeof(dict_read(element_gili, e_gili)), Type))):
- // This is a primitive type, so add to the list
- dict_add(result_gili, e_gili, dict_read(element_gili, e_gili))
- return result_gili
- String function getName(m : Element, e : Element):
- Element element_keys
- Element s
- s = dict_read(m, "model")
- element_keys = dict_keys(s)
- while (integer_lt(0, read_nr_out(element_keys))):
- Element key
- key = set_pop(element_keys)
- if (element_eq(dict_read_node(s, key), e)):
- return key
- return string_join(string_join("(unknown: ", cast_e2s(e)), " )")
- String function reverseNameLookup(s_rnl : Element, e_rnl : Element):
- Element element_keys_rnl
- element_keys_rnl = dict_keys(s_rnl)
- while (integer_lt(0, read_nr_out(element_keys_rnl))):
- Element key_rnl
- key_rnl = set_pop(element_keys_rnl)
- if (element_eq(dict_read_node(s_rnl, key_rnl), e_rnl)):
- return key_rnl
- return string_join(string_join("(unknown: ", cast_e2s(e_rnl)), " )")
|