Skip to content

Commit

Permalink
prototype write_create_element_function for jsbml
Browse files Browse the repository at this point in the history
  • Loading branch information
hovo1990 committed Jul 21, 2016
1 parent 78d74fb commit 7daebfd
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 68 deletions.
47 changes: 25 additions & 22 deletions generator/java_code_files/JavaCodeFile.py
Expand Up @@ -732,6 +732,17 @@ def write_child_lo_element_functions_by_groups(self, function_to_write):
code = lo_functions.write_get_list_of_function()
self.write_function_implementation(code)

if function_to_write == 'createElement':
if 'concretes' in element:
for n in range(0, len(element['concretes'])):
code = lo_functions.write_create_element_function(n+1)
self.write_function_implementation(code)
else:
# createInput
code = lo_functions.write_create_element_function()
self.write_function_implementation(code)



# main function to write the functions dealing with a child listOf element
def write_child_lo_element_functions(self):
Expand All @@ -747,6 +758,11 @@ def write_child_lo_element_functions(self):
function_to_write = 'getListOf'
self.write_child_lo_element_functions_by_groups(function_to_write)

function_to_write = 'createElement'
self.write_child_lo_element_functions_by_groups(function_to_write)




num_elements = len(self.child_lo_elements)
for i in range(0, num_elements):
Expand All @@ -770,12 +786,6 @@ def write_child_lo_element_functions(self):
# TODO



# # ? same as previous
# code = lo_functions.write_get_list_of_function(is_const=False)
# self.write_function_implementation(code)


#getInputCount
code = lo_functions.write_get_element_by_index(is_const=False)
self.write_function_implementation(code)
Expand Down Expand Up @@ -813,28 +823,21 @@ def write_child_lo_element_functions(self):
code = lo_functions.write_get_num_element_function()
self.write_function_implementation(code)

if 'concretes' in element:
for n in range(0, len(element['concretes'])):
code = lo_functions.write_create_element_function(n+1)
self.write_function_implementation(code)
else:
# createInput
code = lo_functions.write_create_element_function()
self.write_function_implementation(code)



# this tackles the situation where a listOfFoo class also
# contains an element of another type
# eg qual:ListOfFunctionTerms contains a DefaultTerm
if not self.is_plugin:
element_children = \
query.get_other_element_children(self.class_object, element)

for j in range(0, len(element_children)):
child_class = self.create_lo_other_child_element_class(
element_children[0], self.class_name)
self.write_child_element_functions(child_class)

# if not self.is_plugin:
# element_children = \
# query.get_other_element_children(self.class_object, element)
#
# for j in range(0, len(element_children)):
# child_class = self.create_lo_other_child_element_class(
# element_children[0], self.class_name)
# self.write_child_element_functions(child_class)
########################################################################


Expand Down
106 changes: 60 additions & 46 deletions generator/java_code_files/java_functions/ListOfQueryFunctions.py
Expand Up @@ -927,19 +927,27 @@ def write_create_element_function(self, index=0):
'and returns the {0} object ' \
'created.'.format(child, self.object_name)
params = []
if not self.is_java_api:
params.append('@param {0} the {1} structure '
'to which the {2} should be '
'added.'.format(self.abbrev_parent, self.object_name,
child))
# if not self.is_java_api:
# params.append('@param {0} the {1} structure '
# 'to which the {2} should be '
# 'added.'.format(self.abbrev_parent, self.object_name,
# child))
return_lines = ['@return a new {0} object '
'instance.'.format(child)]
additional = []
if self.is_java_api:
additional.append('@see add{0}(const {2}* {1})'
.format(strFunctions.remove_prefix(self.object_child_name),
self.abbrev_child,
self.object_child_name))
# if self.is_java_api:
# additional.append('@see add{0}(const {2}* {1})'
# .format(strFunctions.remove_prefix(self.object_child_name),
# self.abbrev_child,
# self.object_child_name))


params.append('Creates a new {0} element and adds it to the'.format(child))
params.append('{{@link #listOf${0}s}} list.'.format(child))
params.append(' ')
params.append('@return the newly created element, i.e., the last item in the')
params.append('{{@link #listOf${0}s}}'.format(child))

# create the function declaration
arguments = []
used_c_name = strFunctions.remove_prefix(child_name)
Expand All @@ -949,48 +957,54 @@ def write_create_element_function(self, index=0):
function = '{0}_create{1}'.format(self.class_name, used_c_name)
arguments.append('{0}* {1}'.format(self.object_name,
self.abbrev_parent))
return_type = '{0}*'.format(child)
return_type = '{0}'.format(child)

# code = []
#Input, Output, FunctionTerm
if self.is_java_api and not is_concrete:
pack_up = self.package.upper()
pack_low = self.package.lower()
implementation = ['{0}* {1} = NULL'.format(self.child_name,
self.abbrev_child)]
implementation = ['return create{0}(null)'.format(child)]
code = [self.create_code_block('line', implementation)]

if self.class_object['num_versions'] > 1:
line = '{0}_CREATE_NS_WITH_VERSION({1}ns, get{2}Namespaces(), ' \
'getPackageVersion())'.format(pack_up, pack_low,
global_variables.prefix)
else:
line = '{0}_CREATE_NS({1}ns, ' \
'get{2}Namespaces())'.format(pack_up, pack_low,
global_variables.prefix)
if global_variables.is_package:
implementation = [line,
'{0} = new {1}({2}ns)'.format(self.abbrev_child,
self.child_name,
pack_low),
'delete {0}ns'.format(pack_low),
'catch', '...', '']
else:
implementation = ['{0} = new {1}(get{2}Namespaces())'
''.format(self.abbrev_child,
self.child_name,
global_variables.prefix),
'catch', '...', '']
code.append(self.create_code_block('try', implementation))
implementation = ['{0} != NULL'.format(self.abbrev_child)]
if self.is_list_of:
implementation.append('appendAndOwn'
'({0})'.format(self.abbrev_child))
else:
member = self.class_object['memberName']
implementation.append('{0}.appendAndOwn'
'({1})'.format(member, self.abbrev_child))
code.append(self.create_code_block('if', implementation))
implementation = ['return {0}'.format(self.abbrev_child)]
code.append(self.create_code_block('line', implementation))

# implementation = ['{0}* {1} = NULL'.format(self.child_name,
# self.abbrev_child)]
# code = [self.create_code_block('line', implementation)]
#
# if self.class_object['num_versions'] > 1:
# line = '{0}_CREATE_NS_WITH_VERSION({1}ns, get{2}Namespaces(), ' \
# 'getPackageVersion())'.format(pack_up, pack_low,
# global_variables.prefix)
# else:
# line = '{0}_CREATE_NS({1}ns, ' \
# 'get{2}Namespaces())'.format(pack_up, pack_low,
# global_variables.prefix)
# if global_variables.is_package:
# implementation = [line,
# '{0} = new {1}({2}ns)'.format(self.abbrev_child,
# self.child_name,
# pack_low),
# 'delete {0}ns'.format(pack_low),
# 'catch', '...', '']
# else:
# implementation = ['{0} = new {1}(get{2}Namespaces())'
# ''.format(self.abbrev_child,
# self.child_name,
# global_variables.prefix),
# 'catch', '...', '']
# code.append(self.create_code_block('try', implementation))
# implementation = ['{0} != NULL'.format(self.abbrev_child)]
# if self.is_list_of:
# implementation.append('appendAndOwn'
# '({0})'.format(self.abbrev_child))
# else:
# member = self.class_object['memberName']
# implementation.append('{0}.appendAndOwn'
# '({1})'.format(member, self.abbrev_child))
# code.append(self.create_code_block('if', implementation))
# implementation = ['return {0}'.format(self.abbrev_child)]
# code.append(self.create_code_block('line', implementation))
elif self.is_java_api and is_concrete:
pack_up = self.package.upper()
pack_low = self.package.lower()
Expand Down

0 comments on commit 7daebfd

Please sign in to comment.