From 16df2c5bb7cfb56f4373ef0a4bb20c48e0975d29 Mon Sep 17 00:00:00 2001 From: Hovakim Grabski Date: Thu, 21 Jul 2016 19:48:15 +0400 Subject: [PATCH] Protoype is_set_list_of_function for jsbml --- generator/java_code_files/JavaCodeFile.py | 17 ++-- .../java_functions/ListOfQueryFunctions.py | 98 +++++++++++++++++++ .../tests/test_java_code/run_java_tests.py | 12 +-- 3 files changed, 115 insertions(+), 12 deletions(-) diff --git a/generator/java_code_files/JavaCodeFile.py b/generator/java_code_files/JavaCodeFile.py index a1808703..25747398 100644 --- a/generator/java_code_files/JavaCodeFile.py +++ b/generator/java_code_files/JavaCodeFile.py @@ -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() @@ -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) @@ -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() @@ -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): diff --git a/generator/java_code_files/java_functions/ListOfQueryFunctions.py b/generator/java_code_files/java_functions/ListOfQueryFunctions.py index 7bc123dc..f50060b0 100644 --- a/generator/java_code_files/java_functions/ListOfQueryFunctions.py +++ b/generator/java_code_files/java_functions/ListOfQueryFunctions.py @@ -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 diff --git a/generator/tests/test_java_code/run_java_tests.py b/generator/tests/test_java_code/run_java_tests.py index 5d7c0e75..034177f1 100644 --- a/generator/tests/test_java_code/run_java_tests.py +++ b/generator/tests/test_java_code/run_java_tests.py @@ -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'