Skip to content

Commit

Permalink
Protoype is_set_list_of_function for jsbml
Browse files Browse the repository at this point in the history
  • Loading branch information
hovo1990 committed Jul 21, 2016
1 parent 7dd54a4 commit 16df2c5
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 12 deletions.
17 changes: 11 additions & 6 deletions generator/java_code_files/JavaCodeFile.py
Expand Up @@ -81,6 +81,7 @@ def write_class(self):
self.write_child_element_functions()
self.write_listof_functions()

# TODOs
self.write_child_lo_element_functions()

self.write_concrete_functions()
Expand Down Expand Up @@ -325,13 +326,11 @@ def write_attribute_functions(self):



# self.write_function_implementation(code)
code = attrib_functions.write_set_string_for_enum(True, i)
self.write_function_implementation(code)

# code = attrib_functions.write_set_string_for_enum(True, i)
# self.write_function_implementation(code)
#
# code = attrib_functions.write_add_element_for_vector(True, i)
# self.write_function_implementation(code)
code = attrib_functions.write_add_element_for_vector(True, i)
self.write_function_implementation(code)

for i in range(0, num_attributes):
code = attrib_functions.write_unset(True, i)
Expand Down Expand Up @@ -713,6 +712,10 @@ def write_child_lo_element_functions_by_groups(self, function_to_write):
self.is_list_of,
element)

if function_to_write == 'isSetListOf':
code = lo_functions.write_is_set_list_of_function()
self.write_function_implementation(code)


if function_to_write == 'addElement':
code = lo_functions.write_add_element_function()
Expand Down Expand Up @@ -781,6 +784,8 @@ def write_child_lo_element_functions(self):
function_to_write = 'getNum'
self.write_child_lo_element_functions_by_groups(function_to_write)

function_to_write = 'isSetListOf'
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 Down
98 changes: 98 additions & 0 deletions generator/java_code_files/java_functions/ListOfQueryFunctions.py
Expand Up @@ -1428,6 +1428,104 @@ def write_get_list_of_function(self, is_const=False):

########################################################################

# Functions for writing isSetListOf

# function to write isSet

def write_is_set_list_of_function(self, is_const=False):
if not self.is_java_api and not is_const:
return

loname = strFunctions.list_of_name(self.child_name)
loname_lower = strFunctions.jsbml_list_of_name(self.child_name)
# create comment parts
params = []
if self.is_java_api:
title_line = 'Returns the {0} from this {1}.' \
''.format(loname, self.object_name)
return_lines = ['@return the {0} '
'from this {1}.'.format(loname, self.object_name)]
else:
title_line = 'Returns a ListOf_t* containing {0} objects ' \
'from this {1}.'.format(self.object_child_name,
self.object_name)
params.append('@param {0} the {1} structure whose \"{2}\" is sought'
'.'.format(self.abbrev_parent, self.object_name,
loname))
return_lines = ['@return the \"{0}\" from this {1} as a '
'ListOf_t *.'.format(loname, self.object_name)]
additional = []

# create the function declaration
lo_name = strFunctions.remove_prefix(loname)
lo_name_lower = strFunctions.remove_prefix(loname_lower)
used_java_name = strFunctions.upper_first(self.child_name)
used_java_name_lower = strFunctions.lower_first(self.child_name)

params.append('Returns the {{@link {0}}}'.format(loname_lower))
params.append('Creates it if it does not already exist.')
params.append(' ')
params.append('@return the {{@link {0}}}.'.format(loname_lower))

code = []
# used_java_name = strFunctions.upper_first(strFunctions.remove_prefix(self.object_name))
# used_java_name_lower = strFunctions.upper_first(strFunctions.remove_prefix(self.object_name_lower))
if self.is_java_api:
function = 'isSet{0}'.format(lo_name)
arguments = [] # ['{0}s'.format(used_java_name)]
return_type = 'boolean'
# if is_const:
# return_type = 'const {0}*'.format(loname)
# else:
# return_type = '{0}*'.format(loname)
else:
function = '{0}_get{1}'.format(self.class_name, name_used)
arguments = ['{0}* {1}'.format(self.object_name,
self.abbrev_parent)]
if global_variables.is_package:
return_type = 'ListOf_t*'
else:
return_type = '{0}ListOf_t*'.format(global_variables.prefix)


if self.is_java_api:
# implementation = ['return '
# '&{0}'.format(self.class_object['memberName'])]
# code = [self.create_code_block('line', implementation)]
implementation = ['({0} == null) || {1}.isEmpty()'.format(loname_lower,loname_lower)]
implementation.append('return false'.format(loname_lower, used_java_name))




temp_code = self.create_code_block('if', implementation)
code.append(temp_code)
else:
implementation = ['return ({0} != NULL) ? {0}->get{1}() : '
'NULL'.format(self.abbrev_parent, name_used)]
code = [self.create_code_block('line', implementation)]
# return the parts



line = 'return true'.format(loname_lower)
line_code = line # self.create_code_block('line', line)
code.append(line_code)

return dict({'title_line': title_line,
'params': params,
'return_lines': return_lines,
'additional': additional,
'function': function,
'return_type': return_type,
'arguments': arguments,
'constant': is_const,
'virtual': False,
'object_name': self.struct_name,
'implementation': code})

########################################################################

# HELPER FUNCTIONS

@staticmethod
Expand Down
12 changes: 6 additions & 6 deletions generator/tests/test_java_code/run_java_tests.py
Expand Up @@ -284,12 +284,12 @@ def main():


# # TODO qual tests
# name = 'qual'
# num = 0
# class_name = 'QualitativeSpecies'
# list_of = 'ListOfQualitativeSpecies'
# test_case = 'an element on QualitativeSpecies'
# fail += run_test(name, num, class_name, test_case)
name = 'qual'
num = 0
class_name = 'QualitativeSpecies'
list_of = 'ListOfQualitativeSpecies'
test_case = 'an element on QualitativeSpecies'
fail += run_test(name, num, class_name, test_case)


name = 'qual'
Expand Down

0 comments on commit 16df2c5

Please sign in to comment.