object_operations.alc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. include "primitives.alh"
  2. include "conformance_scd.alh"
  3. include "constructors.alh"
  4. Element function allInstances(model : Element, type : Element):
  5. Element type_mapping
  6. Element result
  7. type_mapping = model["type_mapping"]
  8. result = create_node()
  9. Integer counter
  10. counter = 0
  11. Integer length
  12. length = read_nr_out(type_mapping)
  13. Element edge
  14. while (counter < length):
  15. edge = read_out(type_mapping, counter)
  16. if (element_eq(read_edge_dst(edge), type)):
  17. // Found an element of the specified type
  18. set_add(result, read_edge_dst(read_out(edge, 0)))
  19. counter = counter + 1
  20. return result
  21. Element function allOutgoingAssociationInstances(model : Element, source : Element, assoc : Element):
  22. // Read out all outgoing edges of the model and select those that are typed by the specified association
  23. // TODO for some reason this crashes if allInstances is used!
  24. Integer length
  25. length = read_nr_out(source)
  26. Integer counter
  27. counter = 0
  28. Element result
  29. result = create_node()
  30. Element edge
  31. while (counter < length):
  32. edge = read_out(source, counter)
  33. if (element_eq(dict_read_node(model["type_mapping"], edge), assoc)):
  34. set_add(result, edge)
  35. counter = counter + 1
  36. return result
  37. Element function allIncomingAssociationInstances(model : Element, source : Element, assoc : Element):
  38. // Read out all outgoing edges of the model and select those that are typed by the specified association
  39. Element result
  40. result = create_node()
  41. Element allinsts
  42. allinsts = allInstances(model, assoc)
  43. Element understudy
  44. while (0 < read_nr_out(allinsts)):
  45. understudy = set_pop(allinsts)
  46. if (element_eq(read_edge_dst(understudy), source)):
  47. set_add(result, understudy)
  48. return result
  49. Element function readElementByName(model : Element, name : String):
  50. return model["model"][name]
  51. Element function getAttributeList(model : Element, element : String):
  52. Element result
  53. Element keys
  54. Element type
  55. Element attr_name
  56. String attr_type
  57. result = create_node()
  58. type = dict_read_node(model["type_mapping"], model["model"][element])
  59. keys = dict_keys(type)
  60. // Add our own attributes
  61. while (0 < list_len(keys)):
  62. attr_name = set_pop(keys)
  63. log("Test for " + cast_e2s(attr_name))
  64. if (is_physical_string(attr_name)):
  65. log("Found attribute " + cast_v2s(attr_name))
  66. attr_type = getName(model["metamodel"], type[attr_name])
  67. dict_add(result, attr_name, attr_type)
  68. // Go on to the metalevel
  69. // TODO
  70. return result
  71. Element function getInstantiatableAttributes(model : Element, element : Element):
  72. Element result
  73. result = create_node()
  74. // Get all outgoing "dictionary" links
  75. Element set_own
  76. set_own = dict_keys(element)
  77. // Filter them
  78. Element e
  79. while (0 < read_nr_out(set_own)):
  80. e = set_pop(set_own)
  81. if (is_physical_string(e)):
  82. // This is a primitive type, so add to the list
  83. dict_add(result, e, element[e])
  84. return result
  85. String function getName(m : Element, e : Element):
  86. Element element_keys
  87. Element s
  88. s = m["model"]
  89. element_keys = dict_keys(s)
  90. Element key
  91. while (0 < read_nr_out(element_keys)):
  92. key = set_pop(element_keys)
  93. if (element_eq(dict_read_node(s, key), e)):
  94. return key
  95. return string_join(string_join("(unknown: ", cast_e2s(e)), " )")
  96. String function reverseNameLookup(s : Element, e : Element):
  97. Element element_keys
  98. element_keys = dict_keys(s)
  99. Element key
  100. while (0 < read_nr_out(element_keys)):
  101. key = set_pop(element_keys)
  102. if (element_eq(dict_read_node(s, key), e)):
  103. return key
  104. return string_join(string_join("(unknown: ", cast_e2s(e)), " )")
  105. String function print_dict(dict : Element):
  106. Element keys
  107. Element key
  108. String result
  109. keys = dict_keys(dict)
  110. result = ""
  111. while (0 < list_len(keys)):
  112. key = set_pop(keys)
  113. result = result + cast_v2s(key)
  114. result = result + ": "
  115. result = result + cast_v2s(dict[key])
  116. result = result + "\n"
  117. return result