def __init__(self, object_desc, spec_name, number, package, pkg_ref): # members from object self.name = object_desc['name'] self.fullname = spec_name self.number = number self.package = package.lower() self.pkg_ref = pkg_ref self.up_package = strFunctions.upper_first(self.package) # useful repeated text strings self.valid = '\\validRule{' self.start_b = '{' self.end_b = '}' self.lower_name = strFunctions.lower_first(strFunctions.remove_prefix(self.name)) self.formatted_name = '\{0}'.format(strFunctions.remove_prefix(self.name)) self.indef = strFunctions.get_indefinite(self.lower_name) self.indef_u = strFunctions.upper_first(self.indef) self.reqd_att = [] self.opt_att = [] self.reqd_elem = [] self.opt_elem = [] self.reqd_child_lo_elem = [] self.opt_child_lo_elem = [] self.parse_attributes(self, object_desc['attribs']) self.parse_elements(self, object_desc['attribs'], object_desc['root']) self.rules = [] self.tc = 'TBC'
def write_attibute_paragraph(self, attrib, name): att_name = attrib['texname'] if attrib['type'] == 'lo_element' \ or attrib['type'] == 'inline_lo_element': return elif attrib['type'] == 'element' \ and attrib['element'] != 'RelAbsVector': return else: self.write_line('\paragraph{0}The \\fixttspace\\token{0}{1}{2} ' 'attribute{2}'.format(self.start_b, att_name, self.end_b)) self.skip_line() self.write_line('{0} \{1} has {2} attribute {3} {4}.' .format(strFunctions.get_indefinite(name). capitalize(), name, 'a required' if attrib['reqd'] is True else 'an optional', strFunctions.wrap_token(att_name), strFunctions.wrap_type(attrib['type'], attrib['element'], True))) if attrib['type'] == 'SIdRef': [string_name, a] = strFunctions.get_sid_refs(attrib['element']) self.write_line('This attribute must be the identifier of ' 'an existing \{0} object.'.format(string_name)) self.write_to_do('explain {0}'.format(att_name)) self.skip_line()
def write_body_for_extended_class(self, plugin): extended_object = plugin['sbase'] ex_objects = [] for i in range(0, len(plugin['extension'])): name = plugin['extension'][i]['name'] indef = strFunctions.get_indefinite(name) ex_objects.append('{0} \\{1} object'.format(indef, name)) for i in range(0, len(plugin['lo_extension'])): name = plugin['lo_extension'][i]['listOfClassName'] ex_objects.append('a \\{0} object'.format(name)) if len(plugin['attribs']) > 0: ex_objects.append('the following attributes.') # section heading self.write_comment_line('---------------------------------------------' '------------') self.write_line( '\subsection{0}The extended \class{0}{1}{2} class{2}'.format( self.start_b, plugin['sbase'], self.end_b)) self.write_line('\\label{0}{1}{2}'.format( self.start_b, strFunctions.make_class(plugin['sbase']), self.end_b)) self.skip_line() self.write_figure('extended', plugin['sbase']) self.skip_line() self.write_to_do( 'explain where {0} comes from'.format(extended_object)) self.write_line('The {0} extends the \\class{1}{2}{3} object ' 'with the addition of '.format(self.full_pkg_command, self.start_b, extended_object, self.end_b)) num_additions = len(ex_objects) if num_additions > 1: self.write_line('{0}'.format(ex_objects[0])) for i in range(1, num_additions - 1): self.write_line(', {0}'.format(ex_objects[i])) self.write_line(' and {0}.'.format(ex_objects[num_additions - 1])) elif num_additions == 1: self.write_line('{0}.'.format(ex_objects[0])) self.skip_line() for i in range(0, len(plugin['attribs'])): self.write_attibute_paragraph(plugin['attribs'][i], extended_object) # write body for child elements for i in range(0, len(plugin['extension'])): child = self.get_class(plugin['extension'][i]['name']) self.write_body_for_class(child) for i in range(0, len(plugin['lo_extension'])): child = self.get_class(plugin['lo_extension'][i]['name']) self.write_body_for_lo_class(child)
def write_body_for_extended_class(self, plugin): extended_object = plugin['sbase'] ex_objects = [] for i in range(0, len(plugin['extension'])): name = plugin['extension'][i]['name'] indef = strFunctions.get_indefinite(name) ex_objects.append('{0} \\{1} object'.format(indef, name)) for i in range(0, len(plugin['lo_extension'])): name = plugin['lo_extension'][i]['listOfClassName'] ex_objects.append('a \\{0} object'.format(name)) if len(plugin['attribs']) > 0: ex_objects.append('the following attributes.') # section heading self.write_comment_line('---------------------------------------------' '------------') self.write_line('\subsection{0}The extended \class{0}{1}{2} class{2}' .format(self.start_b, plugin['sbase'], self.end_b)) self.write_line('\\label{0}{1}{2}' .format(self.start_b, strFunctions.make_class(plugin['sbase']), self.end_b)) self.skip_line() self.write_figure('extended', plugin['sbase']) self.skip_line() self.write_to_do('explain where {0} comes from'.format(extended_object)) self.write_line('The {0} extends the \\class{1}{2}{3} object ' 'with the addition of ' .format(self.full_pkg_command, self.start_b, extended_object, self.end_b)) num_additions = len(ex_objects) if num_additions > 1: self.write_line('{0}'.format(ex_objects[0])) for i in range(1, num_additions-1): self.write_line(', {0}'.format(ex_objects[i])) self.write_line(' and {0}.'.format(ex_objects[num_additions-1])) elif num_additions == 1: self.write_line('{0}.'.format(ex_objects[0])) self.skip_line() for i in range(0, len(plugin['attribs'])): self.write_attibute_paragraph(plugin['attribs'][i], extended_object) # write body for child elements for i in range(0, len(plugin['extension'])): child = self.get_class(plugin['extension'][i]['name']) self.write_body_for_class(child) for i in range(0, len(plugin['lo_extension'])): child = self.get_class(plugin['lo_extension'][i]['name']) self.write_body_for_lo_class(child)
def write_child_element(self, attrib, name): if attrib['type'] == 'element': if self.derives_from_other_ns(attrib['element']): child_name = '\\class{' + attrib['element'] + '}' else: child_name = '\\' + attrib['element'] elif attrib['type'] == 'lo_element': child_name = '\\' + strFunctions.cap_list_of_name(attrib['name']) elif attrib['type'] == 'inline_lo_element': child_name = '\\' + strFunctions.cap_list_of_name(attrib['name']) else: return # hack for render if child_name == '\\RelAbsVector': return self.write_line('{0} \{1} contains {2} {3} element.'.format( strFunctions.get_indefinite(name).capitalize(), name, 'at most one' if attrib['reqd'] is True else 'exactly one', child_name))
def write_child_element(self, attrib, name): if attrib['type'] == 'element': if self.derives_from_other_ns(attrib['element']): child_name = '\\class{' + attrib['element'] + '}' else: child_name = '\\' + attrib['element'] elif attrib['type'] == 'lo_element': child_name = '\\' + strFunctions.cap_list_of_name(attrib['name']) elif attrib['type'] == 'inline_lo_element': child_name = '\\' + strFunctions.cap_list_of_name(attrib['name']) else: return # hack for render if child_name == '\\RelAbsVector': return self.write_line('{0} \{1} contains {2} {3} element.' .format(strFunctions.get_indefinite(name). capitalize(), name, 'at most one' if attrib['reqd'] is True else 'exactly one', child_name))
def __init__(self, language, is_cpp_api, is_list_of, class_object): self.language = language self.class_name = class_object['name'] self.is_cpp_api = is_cpp_api self.is_list_of = is_list_of if is_list_of: self.child_name = class_object['lo_child'] else: self.child_name = '' if is_cpp_api: self.object_name = self.class_name self.object_child_name = self.child_name else: if is_list_of: self.object_name = 'ListOf_t' else: self.object_name = self.class_name + '_t' self.object_child_name = self.child_name + '_t' self.concretes = class_object['concretes'] # useful variables if not self.is_cpp_api and self.is_list_of: self.struct_name = self.object_child_name else: self.struct_name = self.object_name self.plural = strFunctions.plural(self.child_name) self.indef_name = strFunctions.get_indefinite(self.object_child_name) self.abbrev_parent = strFunctions.abbrev_name(self.object_name) self.abbrev_child = strFunctions.abbrev_name(self.child_name) if self.is_cpp_api is False: self.true = '@c 1' self.false = '@c 0' else: self.true = '@c true' self.false = '@c false'
def __init__(self, language, is_java_api, is_list_of, class_object, jsbml_data_tree=None, jsbml_methods=None): self.language = language self.cap_language = language.upper() self.package = class_object['package'] self.class_name = class_object['name'] self.is_java_api = is_java_api self.is_list_of = is_list_of if is_list_of: self.child_name = class_object['lo_child'] else: self.child_name = '' if is_java_api: self.object_name = self.class_name self.object_child_name = self.child_name else: if is_list_of: self.object_name = 'ListOf' else: self.object_name = self.class_name self.object_child_name = self.child_name # class_attributes not suitable # self.attributes = class_object['class_attributes'] self.attributes = class_object['attribs'] self.child_elements = class_object['child_elements'] if 'num_versions' in class_object and class_object['num_versions'] > 1: self.has_multiple_versions = True else: self.has_multiple_versions = False self.document = False if 'document' in class_object: self.document = class_object['document'] # useful variables if not self.is_java_api and self.is_list_of: self.struct_name = self.object_child_name else: self.struct_name = self.object_name if self.is_java_api is False: self.true = '@c 1' self.false = '@c 0' else: self.true = '{@code true}' # For comments self.false = '{@code false}' self.plural = strFunctions.plural(self.child_name) self.indef_name = strFunctions.get_indefinite(self.object_child_name) self.abbrev_parent = strFunctions.abbrev_name(self.object_name) self.abbrev_child = strFunctions.abbrev_name(self.child_name) self.is_header = True if 'is_header' in class_object: self.is_header = class_object['is_header'] self.is_plugin = False if 'is_plugin' in class_object: self.is_plugin = class_object['is_plugin'] self.open_br = '{' self.close_br = '}' self.success = global_variables.ret_success self.failed = global_variables.ret_failed self.invalid_att = global_variables.ret_invalid_att self.invalid_obj = global_variables.ret_invalid_obj # JSBML unique helper data if jsbml_data_tree is not None: self.jsbml_data_tree = jsbml_data_tree if jsbml_methods is not None: self.jsbml_methods = jsbml_methods # Here it will hold mandatory functions informations self.mandatory_data = {} # The order the mandatory function have to be written self.write_order = self.determine_mandatory_methods()
def __init__(self, language, is_cpp_api, is_list_of, class_object, writing_test=False): self.is_cpp_api = is_cpp_api self.is_list_of = is_list_of if class_object['name'].startswith('SBML'): self.class_name = class_object['name'][4:] else: self.class_name = class_object['name'] self.base_class = class_object['baseClass'] if not writing_test: self.language = language self.cap_language = language.upper() self.package = class_object['package'] if is_list_of: self.child_name = class_object['lo_child'] else: self.child_name = '' if is_cpp_api: self.object_name = self.class_name self.object_child_name = self.child_name else: if is_list_of: self.object_name = 'ListOf_t' else: self.object_name = self.class_name + '_t' self.object_child_name = self.child_name + '_t' self.attributes = class_object['class_attributes'] self.classroot = None if 'root' in class_object: self.classroot = class_object['root'] self.elements = query.get_child_elements( class_object['child_elements'], class_object['child_lo_elements'], self.classroot) self.single_elements = query.get_child_elements( class_object['child_elements'], [], self.classroot) self.lo_elements = query.get_child_elements( [], class_object['child_lo_elements'], self.classroot) if 'num_versions' in class_object and class_object[ 'num_versions'] > 1: self.has_multiple_versions = True else: self.has_multiple_versions = False self.document = False if 'document' in class_object: self.document = class_object['document'] # useful variables if not self.is_cpp_api and self.is_list_of: self.struct_name = self.object_child_name else: self.struct_name = self.object_name if self.is_cpp_api is False: self.true = '@c 1' self.false = '@c 0' else: self.true = '@c true' self.false = '@c false' self.plural = strFunctions.plural(self.child_name) self.indef_name = strFunctions.get_indefinite( self.object_child_name) self.abbrev_parent = strFunctions.abbrev_name(self.object_name) self.abbrev_child = strFunctions.abbrev_name(self.child_name) self.is_header = True if 'is_header' in class_object: self.is_header = class_object['is_header'] self.is_plugin = False if 'is_plugin' in class_object: self.is_plugin = class_object['is_plugin'] self.open_br = '{' self.close_br = '}' self.success = global_variables.ret_success self.failed = global_variables.ret_failed self.invalid_att = global_variables.ret_invalid_att self.invalid_obj = global_variables.ret_invalid_obj self.tests = []