def print_derived_listof_types(self, fileout): if self.binding == 'java' or self.binding == 'csharp': for element in self.elements: if not element['name'].endswith('Document') and \ element['hasListOf']: name = strFunctions.lower_list_of_name_no_prefix( element['name']) loname = strFunctions.prefix_name( strFunctions.list_of_name(element['name'])) fileout.copy_line_verbatim( ' else if (name == \"{0}\")\n' ''.format(name)) fileout.copy_line_verbatim(' {\n') fileout.copy_line_verbatim(' return new {0}(cPtr, ' 'owner);\n'.format(loname)) fileout.copy_line_verbatim(' }\n') else: for element in self.elements: if not element['name'].endswith('Document') and \ element['hasListOf']: name = strFunctions.lower_list_of_name_no_prefix( element['name']) loname = strFunctions.prefix_name( strFunctions.list_of_name(element['name'])) fileout.copy_line_verbatim( ' else if (name == \"{0}\")\n' ''.format(name)) fileout.copy_line_verbatim(' {\n') fileout.copy_line_verbatim( ' return SWIGTYPE_p_{0};\n'.format(loname)) fileout.copy_line_verbatim(' }\n')
def create_list_of_block(self, b_type=''): line = [] count = 0 for element in self.elements: if element['hasListOf']: count += 1 up_loname = strFunctions.list_of_name(element['name']) loname = strFunctions.lower_first(up_loname) if len(line) > 0: line.append('else if') if b_type == 'java': line.append('name.equals(\"{0}\")'.format(loname)) else: line.append('name == \"{0}\"'.format(loname)) if b_type == 'java' or b_type == 'csharp': line.append( 'return new {0}(cPtr, owner)'.format(up_loname)) else: line.append('return SWIGTYPE_p_{0}'.format(up_loname)) if count == 0: code = self.create_code_block('blank', []) elif count == 1: code = self.create_code_block('if', line) else: code = self.create_code_block('else_if', line) return code
def write_covariant_clone(self): rtype = 'COVARIANT_RTYPE_CLONE' self.write_specific_line(rtype, '{0}Extension'.format(self.up_package)) for element in self.elements: self.write_specific_line(rtype, element['name']) for element in self.elements: if element['hasListOf']: name = strFunctions.list_of_name(element['name']) self.write_specific_line(rtype, name)
def write_exception_list(self): rtype = '{0}CONSTRUCTOR_EXCEPTION'.format(self.cap_language) self.write_specific_line(rtype, '{0}Pkg' 'Namespaces'.format(self.up_package)) for element in self.elements: self.write_specific_line(rtype, element['name']) for element in self.elements: if element['hasListOf']: name = strFunctions.list_of_name(element['name']) self.write_specific_line(rtype, name)
def find_lo_element(elements, name): if elements is None or name is None: return None for element in elements: if 'isListOf' in element and element['isListOf'] is True: match = strFunctions.list_of_name(element['name']) if 'listOfClassName' in element \ and element['listOfClassName'] != '': match = element['listOfClassName'] if match.lower() == name.lower(): return element return None
def find_lo_element(elements, name): if elements is None or name is None: return None for element in elements: if 'isListOf' in element and element['isListOf'] is True: match = strFunctions.list_of_name(element['name']) if 'listOfClassName' in element \ and element['listOfClassName'] != '': match = element['listOfClassName'] if match.lower() == name.lower(): return element return None
def print_includes(self, fileout): for element in self.elements: if not element['name'].endswith('Document'): name = strFunctions.prefix_name(element['name']) fileout.copy_line_verbatim('%include <{0}/{1}.h>\n' ''.format(global_variables.language, name)) if element['hasListOf']: loname = strFunctions.prefix_name( strFunctions.list_of_name(element['name'])) fileout.copy_line_verbatim('%include <{0}/{1}.h>\n' ''.format(global_variables.language, loname))
def print_includes(self, fileout): for element in self.elements: if not element['name'].endswith('Document'): name = strFunctions.prefix_name(element['name']) fileout.copy_line_verbatim('%include <{0}/{1}.h>\n' ''.format(global_variables.language, name)) if element['hasListOf']: loname = strFunctions.prefix_name( strFunctions.list_of_name(element['name'])) fileout.copy_line_verbatim('%include <{0}/{1}.h>\n' ''.format( global_variables.language, loname))
def print_derived_listof_types(self, fileout): for element in self.elements: if not element['name'].endswith('Document') and \ element['hasListOf']: name = strFunctions.lower_list_of_name_no_prefix( element['name']) loname = strFunctions.prefix_name( strFunctions.list_of_name(element['name'])) fileout.copy_line_verbatim(' else if (name == \"{0}\")\n' ''.format(name)) fileout.copy_line_verbatim(' {\n') fileout.copy_line_verbatim(' return new {0}(cPtr, ' 'owner);\n'.format(loname)) fileout.copy_line_verbatim(' }\n')
def print_for_all_classes(self, fileout, line, classes=True, lists=True): l_len = len(line) declaration = line[0:l_len - 1] if classes: for element in self.elements: name = strFunctions.prefix_name(element['name']) fileout.copy_line_verbatim('{0}({1})\n'.format( declaration, name)) if lists: for element in self.elements: if element['hasListOf']: loname = strFunctions.prefix_name( strFunctions.list_of_name(element['name'])) fileout.copy_line_verbatim('{0}({1})\n'.format( declaration, loname))
def print_for_all_classes(self, fileout, line, classes=True, lists=True): l_len = len(line) declaration = line[0:l_len-1] if classes: for element in self.elements: name = strFunctions.prefix_name(element['name']) fileout.copy_line_verbatim('{0}({1})\n'.format(declaration, name)) if lists: for element in self.elements: if element['hasListOf']: loname = strFunctions.prefix_name( strFunctions.list_of_name(element['name'])) fileout.copy_line_verbatim('{0}({1})\n'.format(declaration, loname))
def write_includes(self, sep): self.write_include_line(sep, '{0}Extension'.format(self.up_package), self.ext_dir) for plugin in self.plugins: name = '{0}{1}Plugin'.format(self.up_package, plugin['sbase']) self.write_include_line(sep, name, self.ext_dir) if sep == '#': self.write_include_line(sep, '{0}Extension' 'Types'.format(self.up_package), self.common_dir) for element in self.elements: name = element['name'] self.write_include_line(sep, name, self.base_dir) for element in self.elements: if element['hasListOf']: name = strFunctions.list_of_name(element['name']) self.write_include_line(sep, name, self.base_dir)
def write_includes(self, sep): self.write_include_line(sep, '{0}Extension'.format(self.up_package), self.ext_dir) for plugin in self.plugins: name = '{0}{1}Plugin'.format(self.up_package, plugin['sbase']) self.write_include_line(sep, name, self.ext_dir) if sep == '#': self.write_include_line( sep, '{0}Extension' 'Types'.format(self.up_package), self.common_dir) for element in self.elements: name = element['name'] self.write_include_line(sep, name, self.base_dir) for element in self.elements: if element['hasListOf']: name = strFunctions.list_of_name(element['name']) self.write_include_line(sep, name, self.base_dir)
def create_list_of_description(self): # default list of name lo_name = strFunctions.list_of_name(self.class_object['name']) # check that we have not specified this should be different if 'lo_class_name' in self.class_object and \ len(self.class_object['lo_class_name']) > 0: lo_name = self.class_object['lo_class_name'] descrip = copy.deepcopy(self.class_object) descrip['is_list_of'] = True descrip['attribs'] = self.class_object['lo_attribs'] descrip['child_base_class'] = self.class_object['baseClass'] if global_variables.is_package: descrip['baseClass'] = 'ListOf' else: descrip['baseClass'] = strFunctions.prefix_name('ListOf') descrip['list_of_name'] = lo_name descrip['lo_child'] = self.class_object['name'] descrip['name'] = lo_name return descrip
def get_attrib_descrip(element): if element['isListOf']: attr_name = strFunctions.list_of_name(element['name']) attr_type = 'lo_element' attr_element = element['name'] else: attr_name = element['name'] attr_type = 'element' attr_element = element['name'] attribute_dict = dict({'type': attr_type, 'reqd': False, 'name': attr_name, 'element': attr_element, 'abstract': False, 'num_versions': 1, 'version': 1, 'version_info': [True], 'parent': element, 'root': element['root'] }) return attribute_dict
def get_attrib_descrip(element): if element['isListOf']: attr_name = strFunctions.list_of_name(element['name']) attr_type = 'lo_element' attr_element = element['name'] else: attr_name = element['name'] attr_type = 'element' attr_element = element['name'] attribute_dict = dict({ 'type': attr_type, 'reqd': False, 'name': attr_name, 'element': attr_element, 'abstract': False, 'num_versions': 1, 'version': 1, 'version_info': [True], 'parent': element, 'root': element['root'] }) return attribute_dict
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_lochild_attribute_rule(self, child, lo_info): child_class = query.get_class(child['element'], child['root']) if not child_class or len(child_class['lo_attribs']) == 0: return # if these are all elements we dont need this num = len(child_class['lo_attribs']) count = 0 for attrib in child_class['lo_attribs']: if self.is_element(attrib['type']): count += 1 if count == num: return attributes = [] if len(child_class['lo_class_name']) == 0: child_class['lo_class_name'] = strFunctions.list_of_name(child_class['name']) formatted_name = '\\' + child_class['lo_class_name'] name = child_class['name'] child_reqd = [] child_opt = [] for attrib in child_class['lo_attribs']: attributes.append(attrib) if attrib['reqd']: child_reqd.append(attrib) else: child_opt.append(attrib) lo_info.append(dict({'formatted_name': formatted_name, 'name': child_class['lo_class_name'], 'attributes': attributes})) reqd = self.parse_required(self, child_reqd) opt = self.parse_optional(self, child_opt) no_other_statement = 'No other attributes from the SBML Level 3 {0} ' \ 'namespaces are permitted on {1} {2} object. '\ .format(self.fullname, self.indef, formatted_name) if len(opt) == 0 and len(reqd) > 0: text = '{0} {1} object must have {2}. {3}'\ .format(self.indef_u, formatted_name, reqd, no_other_statement) elif len(reqd) == 0 and len(opt) > 0: text = '{0} {1} object may have {2}. {3}'\ .format(self.indef_u, formatted_name, opt, no_other_statement) else: text = '{0} {1} object must have {2}, and may have {3}. {4}'\ .format(self.indef_u, formatted_name, reqd, opt, no_other_statement) ref = '{0}, {1}.'\ .format(self.pkg_ref, strFunctions.wrap_section(child_class['lo_class_name'])) sev = 'ERROR' lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) short = 'Attributes allowed on <{0}>.'.format(strFunctions.lower_first(child_class['lo_class_name'])) lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package) tc = '{0}{1}LO{2}AllowedAttributes'.format(self.up_package, self.name, strFunctions.plural(name)) return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev, 'typecode': tc, 'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref, 'plugin': False, 'object': self.name, 'lo': True, 'reqd': child_reqd, 'opt': child_opt, 'lo_object': lo_info[0]['name']})
def expand_attributes(self, attributes): for i in range(0, len(attributes)): capname = strFunctions.upper_first(attributes[i]['name']) attributes[i]['name'] = strFunctions.lower_first(capname) attributes[i]['capAttName'] = capname attributes[i]['memberName'] = 'm' + capname attributes[i]['pluralName'] = \ strFunctions.plural(attributes[i]['name']) attributes[i]['isEnum'] = False attributes[i]['isArray'] = False attributes[i]['isVector'] = False attributes[i]['children_overwrite'] = False att_type = attributes[i]['type'] if att_type == 'SId' or att_type == 'SIdRef' or att_type == 'IDREF': attributes[i]['attType'] = 'string' attributes[i]['attTypeCode'] = 'std::string&' attributes[i]['CType'] = 'const char *' attributes[i]['isNumber'] = False attributes[i]['default'] = '""' elif att_type == 'UnitSId' or att_type == 'UnitSIdRef': attributes[i]['attType'] = 'string' attributes[i]['attTypeCode'] = 'std::string&' attributes[i]['CType'] = 'const char *' attributes[i]['isNumber'] = False attributes[i]['default'] = '""' elif att_type == 'string': attributes[i]['attType'] = 'string' attributes[i]['attTypeCode'] = 'std::string&' attributes[i]['CType'] = 'const char *' attributes[i]['isNumber'] = False attributes[i]['default'] = '""' elif att_type == 'double': attributes[i]['attType'] = 'double' attributes[i]['attTypeCode'] = 'double' attributes[i]['CType'] = 'double' attributes[i]['isNumber'] = True attributes[i]['default'] = 'util_NaN()' elif att_type == 'int': attributes[i]['attType'] = 'integer' attributes[i]['attTypeCode'] = 'int' attributes[i]['CType'] = 'int' attributes[i]['isNumber'] = True attributes[i]['default'] = '{0}_INT_' \ 'MAX'.format(self.cap_language) elif att_type == 'uint': attributes[i]['attType'] = 'unsigned integer' attributes[i]['attTypeCode'] = 'unsigned int' attributes[i]['CType'] = 'unsigned int' attributes[i]['isNumber'] = True attributes[i]['default'] = '{0}_INT_' \ 'MAX'.format(self.cap_language) elif att_type == 'bool' or att_type == 'boolean': attributes[i]['attType'] = 'boolean' attributes[i]['attTypeCode'] = 'bool' attributes[i]['CType'] = 'int' attributes[i]['isNumber'] = False attributes[i]['default'] = 'false' elif att_type == 'enum': attributes[i]['isEnum'] = True attributes[i]['attType'] = 'enum' attributes[i]['attTypeCode'] = attributes[i]['element'] + '_t' attributes[i]['CType'] = attributes[i]['element'] + '_t' attributes[i]['isNumber'] = False attributes[i]['default'] = \ query.get_default_enum_value(attributes[i]) elif att_type == 'element': el_name = attributes[i]['element'] at_name = attributes[i]['name'] attributes[i]['attType'] = 'element' if attributes[i]['name'] == 'math': if global_variables.is_package: attributes[i]['attTypeCode'] = 'ASTNode*' attributes[i]['CType'] = 'ASTNode_t*' else: attributes[i]['attTypeCode'] = 'LIBSBML_CPP_NAMESPACE_QUALIFIER ASTNode*' attributes[i]['CType'] = 'LIBSBML_CPP_NAMESPACE_QUALIFIER ASTNode_t*' else: attributes[i]['attTypeCode'] = attributes[i]['element']+'*' attributes[i]['CType'] = attributes[i]['element']+'_t*' if attributes[i]['attTypeCode'] == 'XMLNode*' and not global_variables.is_package: attributes[i]['attTypeCode'] = 'LIBSBML_CPP_NAMESPACE_QUALIFIER {0}*'.format(attributes[i]['element']) attributes[i]['CType'] = 'LIBSBML_CPP_NAMESPACE_QUALIFIER {0}_t*'.format(attributes[i]['element']) attributes[i]['isNumber'] = False attributes[i]['default'] = 'NULL' if strFunctions.compare_no_case(strFunctions.remove_prefix(el_name), at_name): attributes[i]['children_overwrite'] = False else: attributes[i]['children_overwrite'] = True elif att_type == 'lo_element' or att_type == 'inline_lo_element': name = strFunctions.list_of_name(attributes[i]['element']) plural = strFunctions.plural_no_prefix(attributes[i]['element']) attributes[i]['attType'] = 'lo_element' attributes[i]['attTypeCode'] = name attributes[i]['CType'] = 'ListOf_t' attributes[i]['memberName'] = 'm' + plural attributes[i]['isNumber'] = False attributes[i]['default'] = 'NULL' elif att_type == 'array': attributes[i]['isArray'] = True attributes[i]['element'] = \ strFunctions.lower_first(attributes[i]['element']) attributes[i]['attType'] = 'array' attributes[i]['attTypeCode'] = attributes[i]['element'] + '*' attributes[i]['CType'] = attributes[i]['attTypeCode'] attributes[i]['isNumber'] = False attributes[i]['default'] = 'NULL' elif att_type == 'vector': attributes[i]['isVector'] = True attributes[i]['element'] = \ strFunctions.lower_first(attributes[i]['element']) attributes[i]['attType'] = 'vector' attributes[i]['attTypeCode'] = 'std::vector<{0}>'.format(attributes[i]['element']) attributes[i]['CType'] = attributes[i]['attTypeCode'] attributes[i]['isNumber'] = False attributes[i]['default'] = 'NULL' else: global_variables.code_returned \ = global_variables.return_codes['unknown type used'] attributes[i]['attType'] = 'FIXME_{0}'.format(att_type) attributes[i]['attTypeCode'] = 'FIXME_{0}'.format(att_type) attributes[i]['CType'] = 'FIXME_{0}'.format(att_type) attributes[i]['isNumber'] = False attributes[i]['default'] = 'FIXME_{0}'.format(att_type) return attributes
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()