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'
Esempio n. 2
0
    def print_typecode_strings(self, fileout):
        """
        Write out the typecode strings, for each class represented
            in self.elements
        TODO not sure what typecode strings are

        :param fileout: object representing output file we are writing.
        """
        for element in self.elements:
            # if not element['name'].endswith('Document'):
            name = SF.remove_prefix(element['name'])
            fileout.copy_line_verbatim('  , \"{0}\"\n'.format(name))
Esempio n. 3
0
 def write_core_attribute_rule(self, lo_child=None):
     if lo_child is None:
         text = '{0} {1} object may have the optional SBML Level~3 ' \
                'Core attributes {2} and {3}. No other attributes from the ' \
                'SBML Level~3 Core namespaces are permitted on {4} {1}.'\
             .format(self.indef_u, self.formatted_name,
                     strFunctions.wrap_token('metaid'),
                     strFunctions.wrap_token('sboTerm'), self.indef)
         ref = 'SBML Level~3 Version~1 Core, Section~3.2.'
         sev = 'ERROR'
         lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib)
         tc = '{0}{1}AllowedCoreAttributes'.format(self.up_package,
                                                   self.name)
         short = 'Core attributes allowed on <{0}>.'.format(self.lower_name)
         lo = False
     else:
         loname = strFunctions.get_element_name(lo_child,
                                                leave_pkg_prefix=False)
         temp = strFunctions.remove_prefix(lo_child['element'])
         lo_name = loname[7:]  #strFunctions.plural(temp)
         text = 'A {0} object may have the optional SBML Level~3 ' \
                'Core attributes {1} and {2}. No other attributes from the ' \
                'SBML Level~3 Core namespaces are permitted on a {0} object.'\
             .format(strFunctions.get_element_name(lo_child, False),
                     strFunctions.wrap_token('metaid'),
                     strFunctions.wrap_token('sboTerm'))
         sec_name = 'listof' + lo_name.lower()
         ref = '{0}, {1}.'\
             .format(self.pkg_ref, strFunctions.wrap_section(sec_name))
         sev = 'ERROR'
         lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib)
         tc = '{0}{1}LO{2}AllowedCoreAttributes'.format(
             self.up_package, self.name, lo_name)
         lo = True
         short = 'Core attributes allowed on <listOf{0}>.'.format(lo_name)
     lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package)
     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': lo,
         'reqd': self.reqd_elem,
         'opt': self.opt_elem
     })
Esempio n. 4
0
 def write_core_subobject_rule(self, lo_child=None):
     if lo_child is None:
         text = '{0} {1} object may have the optional SBML Level~3 ' \
                'Core subobjects for notes and annotations. No other ' \
                'elements from the SBML Level~3 Core namespaces are ' \
                'permitted on {2} {1}.'\
             .format(self.indef_u, self.formatted_name, self.indef)
         ref = 'SBML Level~3 Version~1 Core, Section~3.2.'
         sev = 'ERROR'
         lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib)
         tc = '{0}{1}AllowedCoreElements'.format(self.up_package, self.name)
         short = 'Core elements allowed on <{0}>.'.format(self.lower_name)
         lo = False
     else:
         loname = strFunctions.get_element_name(lo_child,
                                                leave_pkg_prefix=False)
         temp = strFunctions.remove_prefix(lo_child['element'])
         lo_name = loname[7:]  #strFunctions.plural(temp)
         text = 'Apart from the general notes and annotations subobjects ' \
                'permitted on all SBML objects, a {0} container object ' \
                'may only contain \{1} objects.'\
             .format(loname, temp)
         sec_name = 'listof' + lo_name.lower()
         ref = '{0}, {1}.'\
             .format(self.pkg_ref, strFunctions.wrap_section(sec_name))
         sev = 'ERROR'
         lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib)
         tc = '{0}{1}LO{2}AllowedCoreElements'.format(
             self.up_package, self.name, lo_name)
         lo = True
         short = 'Core elements allowed on <listOf{0}>.'.format(lo_name)
     lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package)
     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': lo,
         'reqd': self.reqd_elem,
         'opt': self.opt_elem
     })
Esempio n. 5
0
 def adjust_line(line):
     lowerlibname = global_variables.library_name.lower()
     nonlibname = lowerlibname
     if lowerlibname.startswith('lib'):
         nonlibname = lowerlibname[3:]
     line = re.sub('nonlibsbml', nonlibname, line)
     line = re.sub('SBase', global_variables.std_base, line)
     line = re.sub('LIBSBML', global_variables.library_name.upper(), line)
     line = re.sub('LibSBML', strFunctions.upper_first(global_variables.library_name), line)
     line = re.sub('libSBML', strFunctions.lower_first(global_variables.library_name), line)
     line = re.sub('libsbml', lowerlibname, line)
     if lowerlibname.startswith('lib'):
         line = re.sub('sbmlfwd', '{0}fwd'.format(lowerlibname[3:]), line)
     else:
         line = re.sub('sbmlfwd', '{0}fwd'.format(lowerlibname), line)
     doctype = '{0}_DOCUMENT'.format(global_variables.language.upper())
     if global_variables.document_class != 'SedDocument':
         doctype = 'LIB_{0}_{1}'.format(strFunctions.get_library_suffix(global_variables.library_name).upper(),
                                        strFunctions.remove_prefix(global_variables.document_class).upper())
     line = re.sub('SBML_DOCUMENT', doctype, line)
     line = re.sub('SBMLDocument', global_variables.document_class, line)
     line = re.sub('toplevelname', strFunctions.lower_first(global_variables.top_level_element_name), line)
     line = re.sub('CAT_SBML',
                   'CAT_{0}'.format(global_variables.language.upper()), line)
     line = re.sub('SBML_Lang',
                   '{0}'.format(global_variables.language.upper()), line)
     line = re.sub('SBML_',
                   '{0}_'.format(global_variables.language.upper()), line)
     # hack for SedML
     if global_variables.prefix == 'Sed':
         line = re.sub('readSBML', 'read{0}ML'.format(global_variables.prefix), line)
         line = re.sub('writeSBML', 'write{0}ML'.format(global_variables.prefix), line)
     else:
         line = re.sub('readSBML', 'read{0}'.format(global_variables.language.upper()), line)
         line = re.sub('writeSBML', 'write{0}'.format(global_variables.language.upper()), line)
     line = re.sub('sbml', global_variables.language, line)
     line = re.sub('SBMLSBML', '{0}{1}'.format(strFunctions.upper_first(global_variables.language), global_variables.prefix), line)
     line = re.sub('SBML', global_variables.prefix, line)
     line = re.sub('ListOf', '{0}ListOf'.format(global_variables.prefix), line)
     line = re.sub('SPEC_NAMESPACE', '\"{0}\"'.format(global_variables.namespaces[0]['namespace']), line)
     line = re.sub('language_', '{0}'.format(global_variables.language.lower()), line)
     line = re.sub('LANGUAGE', '{0}'.format(global_variables.language.upper()), line)
     return line
 def write_core_attribute_rule(self, lo_child=None):
     if lo_child is None:
         text = '{0} {1} object may have the optional SBML Level~3 ' \
                'Core attributes {2} and {3}. No other attributes from the ' \
                'SBML Level 3 Core namespaces are permitted on {4} {1}.'\
             .format(self.indef_u, self.formatted_name,
                     strFunctions.wrap_token('metaid'),
                     strFunctions.wrap_token('sboTerm'), self.indef)
         ref = 'SBML Level~3 Version~1 Core, Section~3.2.'
         sev = 'ERROR'
         lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib)
         tc = '{0}{1}AllowedCoreAttributes'.format(self.up_package,
                                                   self.name)
         short = 'Core attributes allowed on <{0}>.'.format(self.lower_name)
         lo = False
     else:
         temp = strFunctions.remove_prefix(lo_child['element'])
         lo_name = strFunctions.plural(temp)
         text = 'A {0} object may have the optional SBML Level~3 ' \
                'Core attributes {1} and {2}. No other attributes from the ' \
                'SBML Level 3 Core namespaces are permitted on a {0} object.'\
             .format(strFunctions.get_element_name(lo_child, False),
                     strFunctions.wrap_token('metaid'),
                     strFunctions.wrap_token('sboTerm'))
         sec_name = 'listof' + lo_name.lower()
         ref = '{0}, {1}.'\
             .format(self.pkg_ref, strFunctions.wrap_section(sec_name))
         sev = 'ERROR'
         lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib)
         tc = '{0}{1}LO{2}AllowedCoreAttributes'.format(self.up_package,
                                                        self.name, lo_name)
         lo = True
         short = 'Core attributes allowed on <listOf{0}>.'.format(lo_name)
     lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package)
     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': lo,
                  'reqd': self.reqd_elem, 'opt': self.opt_elem})
Esempio n. 7
0
    def print_document_errors(self, fileout):
        """
        Write out the document errors to the file.
        TODO Sorry, I don't know what these are

        :param fileout: object representing output file we are writing.
        """
        root = {'baseElements': self.elements}
        doc = query.get_class(gv.document_class, root)
        if not doc:
            docname = 'Document'
        else:
            docname = SF.remove_prefix(doc['name'],
                                       remove_package=False,
                                       remove_doc_prefix=True)
        libname = SF.get_library_suffix(gv.library_name)
        if not libname.endswith('ml'):
            libname = libname + 'ml'
        fileout.copy_line_verbatim((10 * '') + 'if ( errorId == {0}{1}Allowed'
                                   'CoreAttributes\n'.format(libname, docname))
        level = False
        version = False
        if doc and 'attribs' in doc:
            for a in doc['attribs']:
                if a['name'] == 'level':
                    level = True
                elif a['name'] == 'version':
                    version = True
        if level:
            fileout.copy_line_verbatim((12 * ' ') + '|| errorId == {0}{1}'
                                       'LevelMustBeNonNegativeInteger\n'
                                       ''.format(libname, docname))
        if version:
            fileout.copy_line_verbatim((12 * ' ') + '|| errorId == {0}{1}'
                                       'VersionMustBeNonNegativeInteger\n'
                                       ''.format(libname, docname))
        fileout.copy_line_verbatim('            || errorId == InvalidNamespace'
                                   'On{0})\n'.format(gv.prefix))
 def write_core_subobject_rule(self, lo_child=None):
     if lo_child is None:
         text = '{0} {1} object may have the optional SBML Level~3 ' \
                'Core subobjects for notes and annotations. No other ' \
                'elements from the SBML Level 3 Core namespaces are ' \
                'permitted on {2} {1}.'\
             .format(self.indef_u, self.formatted_name, self.indef)
         ref = 'SBML Level~3 Version~1 Core, Section~3.2.'
         sev = 'ERROR'
         lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib)
         tc = '{0}{1}AllowedCoreElements'.format(self.up_package, self.name)
         short = 'Core elements allowed on <{0}>.'.format(self.lower_name)
         lo = False
     else:
         loname = strFunctions.get_element_name_no_prefix(lo_child)
         temp = strFunctions.remove_prefix(lo_child['element'])
         lo_name = strFunctions.plural(temp)
         text = 'Apart from the general notes and annotations subobjects ' \
                'permitted on all SBML objects, a {0} container object ' \
                'may only contain \{1} objects.'\
             .format(loname, temp)
         sec_name = 'listof' + lo_name.lower()
         ref = '{0}, {1}.'\
             .format(self.pkg_ref, strFunctions.wrap_section(sec_name))
         sev = 'ERROR'
         lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib)
         tc = '{0}{1}LO{2}AllowedCoreElements'.format(self.up_package, self.name,
                                                  lo_name)
         lo = True
         short = 'Core elements allowed on <listOf{0}>.'.format(lo_name)
     lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package)
     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': lo,
                  'reqd': self.reqd_elem, 'opt': self.opt_elem})
Esempio n. 9
0
    def write_level_version_constructor(self, index=0):
        # I want to write the equivalent constructor but without level and version
        if not global_variables.has_level_version:
            return self.write_class_constructor(index)
        if (len(self.concretes) == 0 and index == 0) or index == -1:
            ob_name = self.object_name
            create = 'create'
        elif self.is_cpp_api:
            ob_name = self.object_name
            create = 'create'
        else:
            if index == 0:
                return
            else:
                i = index - 1
            ob_name = '{0}'.format(self.concretes[i]['element'],
                                   self.object_name)
            create = 'create{0}'.format(
                strFunctions.remove_prefix(self.concretes[i]['element']))
        # create doc string header
        title_line = 'Creates a new {0} using the given {1} Level' \
            .format(ob_name, self.cap_language)
        if global_variables.is_package:
            title_line += ', Version and &ldquo;{0}&rdquo; package ' \
                          'version.'.format(strFunctions.
                                            lower_first(self.package))
        else:
            title_line += ' and @ p version values.'

        params = [
            '@param level an unsigned int, the {0} Level to '
            'assign to this {1}.'.format(self.cap_language, self.object_name),
            '@param version an unsigned int, the {0} Version to '
            'assign to this {1}.'.format(self.cap_language, self.object_name)
        ]
        if global_variables.is_package:
            params.append('@param pkgVersion an unsigned int, the {0} {1} '
                          'Version to assign to this {2}.'.format(
                              self.cap_language, self.package,
                              self.object_name))
        #changed following current documentation practice
        return_lines = ['@copydetails doc_note_setting_lv_pkg']

        # return_lines = ['@throws {0}Constructor'
        #                 'Exception'.format(self.cap_language),
        #                 'Thrown if the given @p level and @p version '
        #                 'combination, or this kind of {0} object, are either '
        #                 'invalid or mismatched with respect to the parent '
        #                 '{1} object.'.format(self.cap_language,
        #                                      global_variables.document_class),
        #                 '@copydetails doc_note_setting_lv']

        additional = []
        if not self.is_cpp_api:
            additional.append('@copydetails doc_returned_owned_pointer')

        # create the function declaration
        if self.is_cpp_api:
            function = self.class_name
            return_type = ''
        else:
            function = '{0}_{1}'.format(self.class_name, create)
            if not ob_name.endswith('_t'):
                return_type = '{0}_t *'.format(ob_name)
            else:
                return_type = '{0} *'.format(ob_name)

        if global_variables.is_package:
            arguments = [
                'unsigned int level = '
                '{0}Extension::getDefaultLevel()'.format(self.package),
                'unsigned int version = '
                '{0}Extension::getDefaultVersion()'.format(self.package),
                'unsigned int pkgVersion = '
                '{0}Extension::getDefaultPackageVersion()'.format(self.package)
            ]
            arguments_no_defaults = [
                'unsigned int level', 'unsigned int version',
                'unsigned int pkgVersion'
            ]
        else:
            if self.is_cpp_api:
                arguments = [
                    'unsigned int level = {0}_DEFAULT_'
                    'LEVEL'.format(global_variables.language.upper()),
                    'unsigned int version = {0}_DEFAULT_VERSI'
                    'ON'.format(global_variables.language.upper())
                ]
                arguments_no_defaults = [
                    'unsigned int level', 'unsigned int version'
                ]
            else:
                arguments = ['unsigned int level', 'unsigned int version']
                arguments_no_defaults = [
                    'unsigned int level', 'unsigned int version'
                ]

        # create the function implementation
        constructor_args = self.write_constructor_args(None)
        if global_variables.is_package:
            if self.is_cpp_api:
                implementation = [
                    'set{0}NamespacesAndOwn(new {1}PkgNamespaces'
                    '(level, version, '
                    'pkgVersion))'.format(global_variables.prefix,
                                          self.package)
                ]
                if self.has_children:
                    implementation.append('connectToChild()')
            else:
                if index == 0 or index == -1:
                    name = self.class_name
                else:
                    name = self.concretes[index - 1]['element']
                implementation = [
                    'return new {0}(level, version, '
                    'pkgVersion)'.format(name)
                ]
        else:
            if self.is_cpp_api:
                implementation = [
                    'set{0}NamespacesAndOwn(new {0}Namespaces('
                    'level, '
                    'version))'.format(global_variables.prefix)
                ]
                if self.document:
                    for attrib in self.attributes:
                        if attrib['name'] == 'level':
                            implementation.append('setLevel(level)')
                        elif attrib['name'] == 'version':
                            implementation.append('setVersion(version)')
                    implementation.append('set{0}(this)'.format(
                        global_variables.document_class))
                if self.has_children:
                    for lo_element in self.child_lo_elements:
                        if lo_element['name'].lower(
                        ) != strFunctions.remove_prefix(
                                lo_element['element']).lower():
                            implementation.append(
                                '{0}.setElementName(\"{1}\")'.format(
                                    lo_element['memberName'],
                                    lo_element['name']))
                    implementation.append('connectToChild()')
            else:
                name_to_use = ob_name
                if ob_name.endswith('_t'):
                    length = len(ob_name)
                    name_to_use = ob_name[0:length - 2]
                implementation = [
                    'return new {0}(level, '
                    'version)'.format(name_to_use)
                ]

        code = [dict({'code_type': 'line', 'code': implementation})]

        return dict({
            'title_line': title_line,
            'params': params,
            'return_lines': return_lines,
            'additional': additional,
            'function': function,
            'return_type': return_type,
            'arguments': arguments,
            'constant': False,
            'virtual': False,
            'object_name': self.object_name,
            'implementation': code,
            'args_no_defaults': arguments_no_defaults,
            'constructor_args': constructor_args
        })
Esempio n. 10
0
    def write_namespace_constructor(self, index=0):
        if len(self.concretes) == 0 and index == 0:
            ob_name = self.object_name
            create = 'create'
        elif self.is_cpp_api:
            ob_name = self.object_name
            create = 'create'
        else:
            if index == 0:
                return
            else:
                i = index - 1
            ob_name = '{0} ({1})'.format(self.concretes[i]['element'],
                                         self.object_name)
            create = 'create{0}'.format(self.concretes[i]['element'])
        # create doc string header
        title_line = 'Creates a new {0} using the given'\
            .format(ob_name)
        if global_variables.is_package:
            title_line = title_line + ' {0}PkgNamespaces object.' \
                .format(self.package)
        else:
            title_line = title_line + ' {0}Namespaces object @p {1}ns.' \
                .format(global_variables.prefix, self.language)

        params = []
        if global_variables.is_package:
            params.append('@copydetails doc_what_are_sbml_package_namespaces')
            params.append('@param {0}ns the {1}PkgNamespaces object.'.format(
                self.package.lower(), self.package))
        else:
            params.append('@param {0}ns the {1}Namespaces object.'.format(
                self.language, global_variables.prefix))

        #changed following current documentation practice
        return_lines = ['@copydetails doc_note_setting_lv_pkg']
        # return_lines = ['@throws {0}Constructor'
        #                  'Exception'.format(self.cap_language),
        #                  'Thrown if the given @p level and @p version '
        #                  'combination, or this kind of {0} object, are either '
        #                  'invalid or mismatched with respect to the parent '
        #                  '{1} object.'.format(self.cap_language,
        #                                       global_variables.document_class),
        #                  '@copydetails doc_note_setting_lv']
        additional = ''

        # create the function declaration
        if self.is_cpp_api:
            function = self.class_name
            return_type = ''
        else:
            function = '{0}_{1}WithNS'.format(self.class_name, create)
            return_type = '{0} *'.format(self.object_name)

        arguments = []

        if global_variables.is_package:
            if self.is_cpp_api:
                arguments.append('{0}PkgNamespaces *{1}ns'.format(
                    self.package, self.package.lower()))
            else:
                arguments.append('{0}PkgNamespaces_t *{1}ns'.format(
                    self.package, self.package.lower()))
            ns = '{0}ns'.format(self.package.lower())
        else:
            if self.is_cpp_api:
                arguments.append('{0}Namespaces *{1}ns'.format(
                    global_variables.prefix, self.language))
            else:
                arguments.append('{0}Namespaces_t *{1}ns'.format(
                    global_variables.prefix, self.language))
            ns = '{0}ns'.format(self.language)

        # create the function implementation
        constructor_args = self.write_constructor_args(ns)
        #        if global_variables.is_package:
        implementation = ['setElementNamespace({0}' '->getURI())'.format(ns)]
        if self.document:
            for attrib in self.attributes:
                if attrib['name'] == 'level':
                    implementation.append(
                        'setLevel({0}->getLevel())'.format(ns))
                elif attrib['name'] == 'version':
                    implementation.append(
                        'setVersion({0}->getVersion())'.format(ns))
            implementation.append('set{0}(this)'.format(
                global_variables.document_class))

        if self.has_children:
            for lo_element in self.child_lo_elements:
                if lo_element['name'].lower() != strFunctions.remove_prefix(
                        lo_element['element']).lower():
                    implementation.append('{0}.setElementName(\"{1}\")'.format(
                        lo_element['memberName'], lo_element['name']))
            implementation.append('connectToChild()')
        if global_variables.is_package and not self.is_list_of:
            implementation.append('loadPlugins({0}ns)'.format(
                self.package.lower()))
        # else:
        #     implementation = ['set{0}NamespacesAndOwn(new {0}Namespaces'
        #                       '(level, '
        #                       'version))'.format(global_variables.prefix)]
        code = [dict({'code_type': 'line', 'code': implementation})]

        return dict({
            'title_line': title_line,
            'params': params,
            'return_lines': return_lines,
            'additional': additional,
            'function': function,
            'return_type': return_type,
            'arguments': arguments,
            'constant': False,
            'virtual': False,
            'object_name': self.object_name,
            'implementation': code,
            'constructor_args': constructor_args
        })
Esempio n. 11
0
    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
Esempio n. 12
0
 def adjust_line(line):
     lowerlibname = global_variables.library_name.lower()
     nonlibname = lowerlibname
     if lowerlibname.startswith('lib'):
         nonlibname = lowerlibname[3:]
     line = re.sub('nonlibsbml', nonlibname, line)
     line = re.sub('SBase', global_variables.std_base, line)
     line = re.sub('LIBSBML', global_variables.library_name.upper(), line)
     line = re.sub('LibSBML',
                   strFunctions.upper_first(global_variables.library_name),
                   line)
     line = re.sub('libSBML',
                   strFunctions.lower_first(global_variables.library_name),
                   line)
     line = re.sub('libsbml', lowerlibname, line)
     if lowerlibname.startswith('lib'):
         line = re.sub('sbmlfwd', '{0}fwd'.format(lowerlibname[3:]), line)
     else:
         line = re.sub('sbmlfwd', '{0}fwd'.format(lowerlibname), line)
     doctype = '{0}_DOCUMENT'.format(global_variables.language.upper())
     if global_variables.document_class != 'SedDocument':
         doctype = 'LIB_{0}_{1}'.format(
             strFunctions.get_library_suffix(
                 global_variables.library_name).upper(),
             strFunctions.remove_prefix(
                 global_variables.document_class).upper())
     line = re.sub('SBML_DOCUMENT', doctype, line)
     line = re.sub('SBMLDocument', global_variables.document_class, line)
     line = re.sub(
         'toplevelname',
         strFunctions.lower_first(global_variables.top_level_element_name),
         line)
     line = re.sub('CAT_SBML',
                   'CAT_{0}'.format(global_variables.language.upper()),
                   line)
     line = re.sub('SBML_Lang',
                   '{0}'.format(global_variables.language.upper()), line)
     line = re.sub('SBML_',
                   '{0}_'.format(global_variables.language.upper()), line)
     # hack for SedML
     if global_variables.prefix == 'Sed':
         line = re.sub('readSBML',
                       'read{0}ML'.format(global_variables.prefix), line)
         line = re.sub('writeSBML',
                       'write{0}ML'.format(global_variables.prefix), line)
     else:
         line = re.sub('readSBML',
                       'read{0}'.format(global_variables.language.upper()),
                       line)
         line = re.sub('writeSBML',
                       'write{0}'.format(global_variables.language.upper()),
                       line)
     line = re.sub('sbml', global_variables.language, line)
     line = re.sub(
         'SBMLSBML', '{0}{1}'.format(
             strFunctions.upper_first(global_variables.language),
             global_variables.prefix), line)
     line = re.sub('SBML', global_variables.prefix, line)
     line = re.sub('ListOf', '{0}ListOf'.format(global_variables.prefix),
                   line)
     line = re.sub(
         'SPEC_NAMESPACE',
         '\"{0}\"'.format(global_variables.namespaces[0]['namespace']),
         line)
     line = re.sub('language_',
                   '{0}'.format(global_variables.language.lower()), line)
     line = re.sub('LANGUAGE',
                   '{0}'.format(global_variables.language.upper()), line)
     return line
Esempio n. 13
0
 def print_typecode_strings(self, fileout):
     for element in self.elements:
     #   if not element['name'].endswith('Document'):
         name = strFunctions.remove_prefix(element['name'])
         fileout.copy_line_verbatim('  , \"{0}\"\n'
                                        ''.format(name))
Esempio n. 14
0
 def print_typecode_strings(self, fileout):
     for element in self.elements:
     #   if not element['name'].endswith('Document'):
         name = strFunctions.remove_prefix(element['name'])
         fileout.copy_line_verbatim('  , \"{0}\"\n'
                                        ''.format(name))
    def write_create_object(self):
        if not self.is_cpp_api:
            return
        elif self.is_list_of:
            return

        if len(self.elements) == 0:
            return

        # create comment parts
        params = []
        return_lines = []
        additional = []
        title_line = 'Creates and returns an new "elementName" object in this {0}.' \
            .format(self.class_name)
        params.append('@param elementName, the name of the element to create.')

        return_lines.append('@return pointer to the element created.')

        # create the function declaration
        function = 'createChildObject'
        #        if self.is_plugin:
        return_type = '{0}*'.format(global_variables.baseClass)

        arguments = ['const std::string& elementName']

        code = []
        # create the function implementation
        if self.is_plugin:
            first_line = ['{0}* obj = NULL'.format(global_variables.baseClass)]
        else:
            first_line = ['{0}* obj = NULL'.format(self.base_class)]

        last_line = ['return obj']
        if not self.has_elements_with_same_xml_name():
            first = True
            block = []
            if_block = []

            for elem in self.elements:
                if elem['concrete']:
                    for conc in elem['concrete']:
                        if not first:
                            block.append('else if')
                        else:
                            first = False
                        concname = conc['name']
                        concelem = conc['name']
                        if conc['name'].lower() != conc['element'].lower():
                            concelem = strFunctions.lower_first(
                                strFunctions.remove_prefix(conc['element']))
                            # hack for render
                            if self.package == 'Render' or self.package == 'render':
                                remove_prefix = True
                                prefix_to_remove = strFunctions.upper_first(
                                    self.package)
                                concelem = strFunctions.remove_prefix(
                                    conc['element'], False, remove_prefix,
                                    prefix_to_remove)

                        block.append('elementName == \"{0}\"'.format(concname))
                        block.append('return create{0}()'.format(
                            strFunctions.upper_first(concelem)))
                        if len(block) > 2:
                            if_block = self.create_code_block('else_if', block)
                        else:
                            if_block = self.create_code_block('if', block)
                else:
                    if not first:
                        block.append('else if')
                    else:
                        first = False
                    block.append('elementName == \"{0}\"'.format(elem['name']))
                    [elem_name,
                     unused] = strFunctions.remove_hyphens(elem['name'])
                    block.append('return create{0}()'.format(
                        strFunctions.upper_first(elem_name)))
                    if len(block) > 2:
                        if_block = self.create_code_block('else_if', block)
                    else:
                        if_block = self.create_code_block('if', block)
            code = [
                self.create_code_block('line', first_line), if_block,
                self.create_code_block('line', last_line)
            ]
        else:
            code = [
                self.create_code_block('line', first_line),
                self.create_code_block('comment', ['TO DO']),
                self.create_code_block('line', last_line)
            ]

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