include "primitives.alh"

Element function export_node(model_name : String, model_reference : Element):
	Element splitted
	splitted = string_split(model_name, "/")
	Integer length
	length = list_len(splitted) - 1
	Integer counter_i
	counter_i = 0
	Element current
	current = dict_read(read_root(), "__hierarchy")
	while(counter_i < length):
		if (bool_not(dict_in(current, list_read(splitted, counter_i)))):
			// Create it first
			dict_add(current, splitted[counter_i], create_node())
		current = current[list_read(splitted, counter_i)]
		counter_i = counter_i + 1
	
	// current now contains the place where we should add the element
	dict_add(current, list_read(splitted, length), model_reference)

	return model_reference

Element function import_node(model_name : String):
	Element splitted
	splitted = string_split(model_name, "/")
	Integer length
	length = list_len(splitted)
	Integer counter_i
	counter_i = 0
	Element current
	current = dict_read(read_root(), "__hierarchy")
	while (counter_i < length):
		if dict_in(current, splitted[counter_i]):
			current = current[splitted[counter_i]]
			counter_i = counter_i + 1
		else:
			return read_root()

	return current
