def write_child_lo_element_functions(self): function_to_write = 'addElement' self.write_child_lo_element_functions_by_groups(function_to_write) function_to_write = 'removeElement' self.write_child_lo_element_functions_by_groups(function_to_write) function_to_write = 'removeElementByIndex' self.write_child_lo_element_functions_by_groups(function_to_write) function_to_write = 'removeElementById' self.write_child_lo_element_functions_by_groups(function_to_write) 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) # TODO not necessary for deviser right now for child_lo_elements functions # function_to_write = 'createElementID' # self.write_child_lo_element_functions_by_groups(function_to_write) function_to_write = 'getNum' self.write_child_lo_element_functions_by_groups(function_to_write) function_to_write = 'getCount' 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) function_to_write = 'setListOf' self.write_child_lo_element_functions_by_groups(function_to_write) function_to_write = 'unsetListOf' 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): element = self.child_lo_elements[i] element['std_base'] = self.std_base element['package'] = self.package element['is_header'] = self.is_header element['is_plugin'] = self.is_plugin if self.is_plugin: element['plugin'] = self.class_name if 'concrete' in element: element['concretes'] = query.get_concretes( self.class_object['root'], element['concrete']) lo_functions = ListOfQueryFunctions \ .ListOfQueryFunctions(self.language, self.is_java_api, self.is_list_of, element) sid_ref = query.get_sid_refs_for_class(element) for j in range(0, len(sid_ref)): if self.is_list_of: code = lo_functions.write_lookup(sid_ref[j]) self.write_function_verbatim(code)
def write_child_element_functions(self, override=None): if override is None: if not self.has_children: return attrib_functions = SetGetFunctions. \ SetGetFunctions(self.language, self.is_java_api, self.is_list_of, self.class_object, self.jsbml_data_tree, self.jsbml_methods) num_elements = len(self.child_elements) else: attrib_functions = SetGetFunctions.SetGetFunctions(self.language, self.is_java_api, self.is_list_of, override, self.jsbml_data_tree, self.jsbml_methods) num_elements = 1 for i in range(0, num_elements): code = attrib_functions.write_get(False, i) self.write_function_implementation(code) for i in range(0, num_elements): code = attrib_functions.write_is_set(False, i) self.write_function_implementation(code) for i in range(0, num_elements): self.line_length = 150 code = attrib_functions.write_set(False, i) self.write_function_implementation(code) self.line_length = 79 for i in range(0, num_elements): code = attrib_functions.write_create(False, i) if override is None and code is None \ and 'concrete' in self.child_elements[i]: # need to write creates for the concrete member = self.child_elements[i]['memberName'] concrete = self.child_elements[i]['concrete'] concretes = query.get_concretes(self.class_object['root'], concrete) for j in range(0, len(concretes)): code = attrib_functions \ .write_create_concrete_child(concretes[j], member) self.write_function_implementation(code) else: self.write_function_implementation(code) for i in range(0, num_elements): code = attrib_functions.write_unset(False, i) self.write_function_implementation(code)
def write_child_element_functions(self, override=None): if override is None: if not self.has_children: return attrib_functions = SetGetFunctions.\ SetGetFunctions(self.language, self.is_cpp_api, self.is_list_of, self.class_object, self.lv_info, False, [], True) num_elements = len(self.child_elements) else: attrib_functions = SetGetFunctions.SetGetFunctions(self.language, self.is_cpp_api, self.is_list_of, override) num_elements = 1 for i in range(0, num_elements): code = attrib_functions.write_get(False, i) self.write_function_declaration(code) code = attrib_functions.write_get(False, i, const=False) self.write_function_declaration(code) for i in range(0, num_elements): code = attrib_functions.write_is_set(False, i) self.write_function_declaration(code) for i in range(0, num_elements): code = attrib_functions.write_set(False, i) self.write_function_declaration(code) for i in range(0, num_elements): code = attrib_functions.write_create(False, i) if override is None and code is None \ and 'concrete' in self.child_elements[i]: # need to write creates for the concrete concrete = self.child_elements[i]['concrete'] concretes = query.get_concretes(self.class_object['root'], concrete) for j in range(0, len(concretes)): code = attrib_functions\ .write_create_concrete_child(concretes[j]) self.write_function_declaration(code) else: self.write_function_declaration(code) for i in range(0, num_elements): code = attrib_functions.write_unset(False, i) self.write_function_declaration(code)
def write_child_element_functions(self, override=None): if override is None: if not self.has_children: return attrib_functions = SetGetFunctions.\ SetGetFunctions(self.language, self.is_cpp_api, self.is_list_of, self.class_object) num_elements = len(self.child_elements) else: attrib_functions = SetGetFunctions.SetGetFunctions(self.language, self.is_cpp_api, self.is_list_of, override) num_elements = 1 for i in range(0, num_elements): code = attrib_functions.write_get(False, i) self.write_function_declaration(code) code = attrib_functions.write_get(False, i, const=False) self.write_function_declaration(code) for i in range(0, num_elements): code = attrib_functions.write_is_set(False, i) self.write_function_declaration(code) for i in range(0, num_elements): code = attrib_functions.write_set(False, i) self.write_function_declaration(code) for i in range(0, num_elements): code = attrib_functions.write_create(False, i) if override is None and code is None \ and 'concrete' in self.child_elements[i]: # need to write creates for the concrete concrete = self.child_elements[i]['concrete'] concretes = query.get_concretes(self.class_object['root'], concrete) for j in range(0, len(concretes)): code = attrib_functions\ .write_create_concrete_child(concretes[j]) self.write_function_declaration(code) else: self.write_function_declaration(code) for i in range(0, num_elements): code = attrib_functions.write_unset(False, i) self.write_function_declaration(code)
def write_child_lo_element_functions_by_groups(self, function_to_write): num_elements = len(self.child_lo_elements) for i in range(0, num_elements): element = self.child_lo_elements[i] element['std_base'] = self.std_base element['package'] = self.package element['is_header'] = self.is_header element['is_plugin'] = self.is_plugin if self.is_plugin: element['plugin'] = self.class_name if 'concrete' in element: element['concretes'] = query.get_concretes( self.class_object['root'], element['concrete']) lo_functions = ListOfQueryFunctions \ .ListOfQueryFunctions(self.language, self.is_java_api, 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 == 'setListOf': code = lo_functions.write_set_list_of_function() self.write_function_implementation(code) if function_to_write == 'unsetListOf': code = lo_functions.write_unset_list_of_function() self.write_function_implementation(code) if function_to_write == 'addElement': code = lo_functions.write_add_element_function() self.write_function_implementation(code) # removeInput if function_to_write == 'removeElement': code = lo_functions.write_remove_element() self.write_function_implementation(code) if function_to_write == 'removeElementByIndex': code = lo_functions.write_remove_element_by_index() self.write_function_implementation(code) if function_to_write == 'removeElementById': code = lo_functions.write_remove_element_by_id() self.write_function_implementation(code) if function_to_write == 'getListOf': code = lo_functions.write_get_list_of_function() self.write_function_implementation(code) if function_to_write == 'getNum': code = lo_functions.write_get_num_element_function() self.write_function_implementation(code) if function_to_write == 'getCount': code = lo_functions.write_get_element_function_count() 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) if function_to_write == 'createElementID': if 'concretes' in element: for n in range(0, len(element['concretes'])): code = lo_functions.write_create_element_id_function(n + 1) self.write_function_implementation(code) else: # createInput code = lo_functions.write_create_element_id_function() self.write_function_implementation(code)
def write_child_lo_element_functions(self): num_elements = len(self.child_lo_elements) for i in range(0, num_elements): element = self.child_lo_elements[i] element['std_base'] = self.std_base element['package'] = self.package element['is_header'] = self.is_header element['is_plugin'] = self.is_plugin if self.is_plugin: element['plugin'] = self.class_name if 'concrete' in element: element['concretes'] = query.get_concretes( self.class_object['root'], element['concrete']) lo_functions = ListOfQueryFunctions\ .ListOfQueryFunctions(self.language, self.is_cpp_api, self.is_list_of, element) code = lo_functions.write_get_list_of_function(is_const=True) self.write_function_declaration(code) code = lo_functions.write_get_list_of_function(is_const=False) self.write_function_declaration(code) code = lo_functions.write_get_element_by_index(is_const=False) self.write_function_declaration(code) code = lo_functions.write_get_element_by_index(is_const=True) self.write_function_declaration(code) code = lo_functions.write_get_element_by_id(is_const=False) self.write_function_declaration(code) code = lo_functions.write_get_element_by_id(is_const=True) self.write_function_declaration(code) sid_ref = query.get_sid_refs_for_class(element) for j in range(0, len(sid_ref)): code = \ lo_functions.write_get_element_by_sidref(sid_ref[j], const=True) self.write_function_declaration(code) code = \ lo_functions.write_get_element_by_sidref(sid_ref[j], const=False) self.write_function_declaration(code) code = lo_functions.write_add_element_function() self.write_function_declaration(code) code = lo_functions.write_get_num_element_function() self.write_function_declaration(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_declaration(code) else: code = lo_functions.write_create_element_function() self.write_function_declaration(code) code = lo_functions.write_remove_element_by_index() self.write_function_declaration(code) code = lo_functions.write_remove_element_by_id() self.write_function_declaration(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)
def write_general_includes(self): lo_name = '' if self.has_parent_list_of: if 'lo_class_name' in self.class_object: lo_name = self.class_object['lo_class_name'] if len(lo_name) == 0: lo_name = strFunctions.list_of_name(self.class_name) if global_variables.is_package: folder = self.language if not self.is_plugin else 'extension' self.write_line_verbatim('#include <{0}/packages/{1}/{2}/{3}' '.h>'.format(self.language, self.package.lower(), folder, self.class_name)) if self.has_parent_list_of and not self.is_list_of: self.write_line_verbatim('#include <{0}/packages/{1}/{0}/' '{2}' '.h>'.format(self.language, self.package.lower(), lo_name)) self.write_line_verbatim('#include <{0}/packages/{1}/validator/' '{2}{3}Error' '.h>'.format(self.language, self.package.lower(), self.package, self.cap_language)) else: self.write_line_verbatim('#include <{0}/{1}' '.h>'.format(self.language, self.class_name)) if self.has_parent_list_of and not self.is_list_of: self.write_line_verbatim('#include <{0}/{1}' '.h>'.format(self.language, lo_name)) self.write_line_verbatim('#include <sbml/xml/XMLInputStream.h>') # determine whether we need to write other headers write_element_filter = False concrete_classes = [] write_model = False write_validators = False write_math = False if len(self.child_lo_elements) > 0 and global_variables.is_package: write_element_filter = True elif global_variables.is_package: # for element in self.child_elements: # if 'concrete' in element: # write_element_filter = True if self.num_children > 0 and self.num_children != self.num_non_std_children: write_element_filter = True if self.is_plugin and not self.is_doc_plugin \ and self.language == 'sbml': write_model = True if self.is_doc_plugin: write_validators = True if self.has_math: write_math = True for lo in self.child_lo_elements: if 'concrete' in lo: child_concretes = query.get_concretes(lo['root'], lo['concrete']) for j in range(0, len(child_concretes)): element = child_concretes[j]['element'] if element not in concrete_classes: concrete_classes.append(element) for i in range(0, len(self.concretes)): element = self.concretes[i]['element'] if element not in concrete_classes: concrete_classes.append(element) for child in self.child_elements: if 'concrete' in child: child_concretes = query.get_concretes(child['root'], child['concrete']) for j in range(0, len(child_concretes)): element = child_concretes[j]['element'] if element not in concrete_classes: concrete_classes.append(element) if write_element_filter: self.write_line_verbatim('#include <{0}/util/ElementFilter.' 'h>'.format(self.language)) if write_model: self.write_line_verbatim('#include <{0}/Model' '.h>'.format(self.language)) if write_validators: self.write_line_verbatim('#include <{0}/packages/{1}/validator/{2}' 'ConsistencyValidator' '.h>'.format(self.language, self.package.lower(), self.package)) self.write_line_verbatim('#include <{0}/packages/{1}/validator/{2}' 'IdentifierConsistencyValidator.' 'h>'.format(self.language, self.package.lower(), self.package)) if write_math: self.write_line_verbatim('#include <sbml/math/MathML.h>') if len(concrete_classes) > 0: self.skip_line() for element in concrete_classes: if global_variables.is_package: self.write_line_verbatim('#include <{0}/packages/{1}/{0}/{2}' '.h>'.format(self.language, self.package.lower(), element)) else: self.write_line_verbatim('#include <{0}/{1}.h>' ''.format(self.language, element)) self.skip_line(2) self.write_line('using namespace std;') self.skip_line()
def write_child_lo_element_functions(self): num_elements = len(self.child_lo_elements) for i in range(0, num_elements): element = self.child_lo_elements[i] element['std_base'] = self.std_base element['package'] = self.package element['is_header'] = self.is_header element['is_plugin'] = self.is_plugin if self.is_plugin: element['plugin'] = self.class_name if 'concrete' in element: element['concretes'] = query.get_concretes( self.class_object['root'], element['concrete']) lo_functions = ListOfQueryFunctions\ .ListOfQueryFunctions(self.language, self.is_cpp_api, self.is_list_of, element) code = lo_functions.write_get_list_of_function(is_const=True) self.write_function_declaration(code) code = lo_functions.write_get_list_of_function(is_const=False) self.write_function_declaration(code) code = lo_functions.write_get_element_by_index(is_const=False) self.write_function_declaration(code) code = lo_functions.write_get_element_by_index(is_const=True) self.write_function_declaration(code) code = lo_functions.write_get_element_by_id(is_const=False) self.write_function_declaration(code) code = lo_functions.write_get_element_by_id(is_const=True) self.write_function_declaration(code) sid_ref = query.get_sid_refs_for_class(element) for j in range(0, len(sid_ref)): code = \ lo_functions.write_get_element_by_sidref(sid_ref[j], const=True) self.write_function_declaration(code) code = \ lo_functions.write_get_element_by_sidref(sid_ref[j], const=False) self.write_function_declaration(code) code = lo_functions.write_add_element_function() self.write_function_declaration(code) code = lo_functions.write_get_num_element_function() self.write_function_declaration(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_declaration(code) else: code = lo_functions.write_create_element_function() self.write_function_declaration(code) code = lo_functions.write_remove_element_by_index() self.write_function_declaration(code) code = lo_functions.write_remove_element_by_id() self.write_function_declaration(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)
def expand_class(self, class_object): self.class_object = class_object self.is_list_of = class_object['is_list_of'] self.has_parent_list_of = class_object['hasListOf'] self.name = class_object['name'] self.class_name = class_object['name'] self.package = class_object['package'] self.typecode = class_object['typecode'] if class_object['is_list_of']: self.list_of_name = class_object['list_of_name'] self.list_of_child = class_object['lo_child'] else: self.list_of_name = '' self.list_of_child = '' # check case of things where we assume upper/lower if self.package[0].islower(): self.package = strFunctions.upper_first(class_object['package']) # are we a plugin if 'is_plugin' in class_object: self.is_plugin = class_object['is_plugin'] if 'is_doc_plugin' in class_object: self.is_doc_plugin = class_object['is_doc_plugin'] # information about the base class self.baseClass = class_object['baseClass'] if self.language != 'sbml': if not self.is_list_of: base = '{0}Base'.format(global_variables.prefix) else: base = '{0}ListOf'.format(global_variables.prefix) if base != self.baseClass: self.has_std_base = False elif not self.is_list_of and not self.is_plugin \ and self.baseClass != 'SBase': self.has_std_base = False elif self.is_list_of and not self.is_plugin \ and self.baseClass != 'ListOf': self.has_std_base = False elif self.is_plugin and not self.is_doc_plugin \ and self.baseClass != 'SBasePlugin': self.has_std_base = False elif self.is_doc_plugin: self.has_std_base = True self.std_base = '{0}DocumentPlugin'.format(self.cap_language) self.class_object['has_std_base'] = self.has_std_base self.class_object['std_base'] = self.std_base # references self.sid_refs = class_object['sid_refs'] self.unit_sid_refs = class_object['unit_sid_refs'] if 'addDecls' in class_object: self.add_decls = class_object['addDecls'] if 'addDefs' in class_object: self.add_impl = class_object['addDefs'] # if 'childrenOverwriteElementName' in class_object: # self.overwrites_children = \ # class_object['childrenOverwriteElementName'] if 'root' in class_object: self.overwrites_children = \ query.overwrites_name(class_object['root'], class_object['name']) self.class_object['overwrites_children'] = self.overwrites_children # child elements self.has_math = class_object['hasMath'] self.has_children = query.has_children(class_object['attribs']) if self.has_math and \ not query.has_children_not_math(class_object['attribs']): self.has_only_math = True # mark child elements as ML nodes for i in range(0, len(self.child_elements)): element = self.child_elements[i] if element['element'].endswith('Node') \ and not element['element'].endswith('CSGNode'): self.child_elements[i]['is_ml'] = True self.has_non_std_children = True self.num_non_std_children += 1 else: self.child_elements[i]['is_ml'] = False if 'concrete' in class_object: self.concretes = query.get_concretes(class_object['root'], class_object['concrete']) self.class_attributes = query.separate_attributes(self.attributes) # document class for other libraries self.document = False if 'document' in class_object: self.document = class_object['document'] # add info back to the class_object so we can pass it on self.class_object['package'] = self.package self.class_object['class_attributes'] = self.class_attributes self.class_object['child_lo_elements'] = self.child_lo_elements self.class_object['child_elements'] = self.child_elements self.class_object['concretes'] = self.concretes self.class_object['has_array'] = query.has_array(self.class_attributes) self.class_object['has_vector'] = query.has_vector(self.class_attributes) self.class_object['has_math'] = self.has_math self.class_object['has_children'] = self.has_children self.class_object['has_only_math'] = self.has_only_math self.class_object['has_parent_list_of'] = self.has_parent_list_of self.class_object['num_children'] = self.num_children self.class_object['has_non_std_chilren'] = self.has_non_std_children self.class_object['num_non_std_children'] = self.num_non_std_children self.class_object['is_header'] = self.is_header self.class_object['document'] = self.document
def write_general_includes(self): lo_name = '' if self.has_parent_list_of: if 'lo_class_name' in self.class_object: lo_name = self.class_object['lo_class_name'] if len(lo_name) == 0: lo_name = strFunctions.list_of_name(self.class_name) if global_variables.is_package: folder = self.language if not self.is_plugin else 'extension' self.write_line_verbatim('#include <{0}/packages/{1}/{2}/{3}' '.h>'.format(self.language, self.package.lower(), folder, self.class_name)) if self.has_parent_list_of and not self.is_list_of: self.write_line_verbatim('#include <{0}/packages/{1}/{0}/' '{2}' '.h>'.format(self.language, self.package.lower(), lo_name)) self.write_line_verbatim('#include <{0}/packages/{1}/validator/' '{2}{3}Error' '.h>'.format(self.language, self.package.lower(), self.package, self.cap_language)) else: self.write_line_verbatim('#include <{0}/{1}' '.h>'.format(self.language, self.class_name)) if self.has_parent_list_of and not self.is_list_of: self.write_line_verbatim('#include <{0}/{1}' '.h>'.format(self.language, lo_name)) self.write_line_verbatim('#include <sbml/xml/XMLInputStream.h>') # determine whether we need to write other headers write_element_filter = False concrete_classes = [] write_model = False write_validators = False write_math = False if len(self.child_lo_elements) > 0 and global_variables.is_package: write_element_filter = True elif global_variables.is_package: for element in self.child_elements: if 'concrete' in element: write_element_filter = True if self.is_plugin and not self.is_doc_plugin \ and self.language == 'sbml': write_model = True if self.is_doc_plugin: write_validators = True if self.has_math: write_math = True for lo in self.child_lo_elements: if 'concrete' in lo: child_concretes = query.get_concretes(lo['root'], lo['concrete']) for j in range(0, len(child_concretes)): element = child_concretes[j]['element'] if element not in concrete_classes: concrete_classes.append(element) for i in range(0, len(self.concretes)): element = self.concretes[i]['element'] if element not in concrete_classes: concrete_classes.append(element) for child in self.child_elements: if 'concrete' in child: child_concretes = query.get_concretes(child['root'], child['concrete']) for j in range(0, len(child_concretes)): element = child_concretes[j]['element'] if element not in concrete_classes: concrete_classes.append(element) if write_element_filter: self.write_line_verbatim('#include <{0}/util/ElementFilter.' 'h>'.format(self.language)) if write_model: self.write_line_verbatim('#include <{0}/Model' '.h>'.format(self.language)) if write_validators: self.write_line_verbatim('#include <{0}/packages/{1}/validator/{2}' 'ConsistencyValidator' '.h>'.format(self.language, self.package.lower(), self.package)) self.write_line_verbatim('#include <{0}/packages/{1}/validator/{2}' 'IdentifierConsistencyValidator.' 'h>'.format(self.language, self.package.lower(), self.package)) if write_math: self.write_line_verbatim('#include <sbml/math/MathML.h>') if len(concrete_classes) > 0: self.skip_line() for element in concrete_classes: if global_variables.is_package: self.write_line_verbatim('#include <{0}/packages/{1}/{0}/{2}' '.h>'.format(self.language, self.package.lower(), element)) else: self.write_line_verbatim('#include <{0}/{1}.h>' ''.format(self.language, element)) self.skip_line(2) self.write_line('using namespace std;') self.skip_line()