def writeProtectedFunctions(output, element, package, elementDict): listOf = generalFunctions.getListOfClassName(elementDict, element) generalFunctions.writeInternalStart(output) output.write('/*\n') output.write(' * Creates a new {0} in this {1}\n'.format(element, listOf)) output.write(' */\n') output.write('SBase*\n{0}::createObject(XMLInputStream& stream)\n'.format(listOf)) output.write('{\n' ) output.write(' const std::string& name = stream.peek().getName();\n') output.write(' SBase* object = NULL;\n\n') name = strFunctions.lowerFirst(element) if elementDict.has_key('elementName'): name = elementDict['elementName'] output.write(' if (name == "{0}")\n'.format(name)) output.write(' {\n') output.write(' {0}_CREATE_NS({1}ns, getSBMLNamespaces());\n'.format(package.upper(), package.lower())) output.write(' object = new {0}({1}ns);\n'.format(element, package.lower())) output.write(' appendAndOwn(object);\n') output.write(' delete {0}ns;\n'.format(package.lower())) output.write(' }\n\n') # need to create concrete objects if elementDict.has_key('concrete'): for elem in generalFunctions.getConcretes(elementDict['root'], elementDict['concrete']): output.write(' if (name == "{0}")\n'.format(strFunctions.lowerFirst(elem['name']))) output.write(' {\n') output.write(' {0}_CREATE_NS({1}ns, getSBMLNamespaces());\n'.format(package.upper(), package.lower())) output.write(' object = new {0}({1}ns);\n'.format(elem['element'], package.lower())) output.write(' appendAndOwn(object);\n') output.write(' delete {0}ns;\n'.format(package.lower())) output.write(' }\n\n') output.write(' return object;\n') output.write('}\n\n\n') generalFunctions.writeInternalEnd(output) generalFunctions.writeInternalStart(output) output.write('/*\n') output.write(' * Write the namespace for the {0} package.\n'.format(package)) output.write(' */\n') output.write('void\n{0}::writeXMLNS(XMLOutputStream& stream) const\n'.format(listOf)) output.write('{\n' ) output.write(' XMLNamespaces xmlns;\n\n') output.write(' std::string prefix = getPrefix();\n\n') output.write(' if (prefix.empty())\n') output.write(' {\n') output.write(' XMLNamespaces* thisxmlns = getNamespaces();\n') output.write(' if (thisxmlns && thisxmlns->hasURI({0}'.format(package)) output.write('Extension::getXmlnsL3V1V1()))\n') output.write(' {\n') output.write(' xmlns.add({0}Extension::getXmlnsL3V1V1(),prefix);\n'.format(package)) output.write(' }\n') output.write(' }\n\n') output.write(' stream << xmlns;\n') output.write('}\n\n\n') generalFunctions.writeInternalEnd(output)
def writeMemberFunctions(fileOut, object, plugin): fileOut.write(' /**\n') fileOut.write(' * Returns the {0} from this {1} object.\n'.format( object, plugin)) fileOut.write(' *\n') fileOut.write( ' * @return the {0} from object in this {1} object.\n'.format( object, plugin)) fileOut.write(' */\n') fileOut.write(' const {0}* get{0} () const;\n\n\n'.format(object)) fileOut.write(' /**\n') fileOut.write(' * Returns the {0} from this {1} object.\n'.format( object, plugin)) fileOut.write(' *\n') fileOut.write( ' * @return the {0} from object in this {1} object.\n'.format( object, plugin)) fileOut.write(' */\n') fileOut.write(' {0}* get{0} ();\n\n\n'.format(object)) fileOut.write(' /**\n') fileOut.write(' * Predicate returning @c true or @c false depending on ') fileOut.write('whether the\n \"{0}\" '.format(object)) fileOut.write('element has been set.\n *\n') fileOut.write(' * @return @c true if the \"{0}\"'.format(object)) fileOut.write(' element has been set,\n') fileOut.write(' * otherwise @c false is returned.\n') fileOut.write(' */\n') fileOut.write(' bool isSet{0}() const;\n\n\n'.format(object)) fileOut.write(' /**\n') fileOut.write(' * Sets the {0} element in this {1} object.\n'.format( object, plugin)) fileOut.write(' *\n') fileOut.write(' * @param {0} the {0}* to be set.\n'.format( strFunctions.lowerFirst(object), object)) fileOut.write(' *\n') fileOut.write( ' * @return integer value indicating success/failure of the\n') fileOut.write(' * function. @if clike The value is drawn from the\n') fileOut.write( ' * enumeration #OperationReturnValues_t. @endif The possible values\n' ) fileOut.write(' * returned by this function are:\n') fileOut.write(' * @li LIBSBML_OPERATION_SUCCESS\n') fileOut.write(' */\n') fileOut.write(' int set{0} (const {0}* {1});\n\n\n'.format( object, strFunctions.lowerFirst(object))) fileOut.write(' /**\n') fileOut.write( ' * Creates a new {0} object and adds it to the {1} object.\n'. format(object, plugin)) fileOut.write(' *\n') fileOut.write( ' * @return the newly created {0} object.\n'.format(object)) fileOut.write(' */\n') fileOut.write(' {0}* create{0} ();\n\n\n'.format(object))
def writeGetElementNameHeader(outFile, element, isSedListOf): if isSedListOf == True: element = writeListOf(element) outFile.write('\t/**\n') outFile.write('\t * Returns the XML element name of this object, which for {0}, is\n'.format(element)) outFile.write('\t * always @c "{0}".\n'.format(strFunctions.lowerFirst(element))) outFile.write('\t *\n') outFile.write('\t * @return the name of this element, i.e. @c "{0}".\n'.format(strFunctions.lowerFirst(element))) outFile.write('\t */\n') outFile.write('\tvirtual const std::string& getElementName () const;\n\n\n')
def writeCreateObject(fileOut, mem, ifCount, pkg): name = strFunctions.cap(mem['name']) if ifCount == 1: fileOut.write(' if (name == "{0}" ) \n'.format(strFunctions.lowerFirst(name))) else: fileOut.write(' else if (name == "{0}" ) \n'.format(strFunctions.lowerFirst(name))) fileOut.write(' { \n') fileOut.write(' m{0} = new {0}({1}ns);\n\n'.format(name, pkg.lower())) fileOut.write(' object = m{0};\n\n'.format(name)) fileOut.write(' } \n')
def writeGetElementNameHeader(outFile, element, isSedListOf): if isSedListOf == True: element = writeListOf(element) outFile.write(' /**\n') outFile.write(' * Returns the XML element name of this object, which for {0}, is\n'.format(element)) outFile.write(' * always @c "{0}".\n'.format(strFunctions.lowerFirst(element))) outFile.write(' *\n') outFile.write(' * @return the name of this element, i.e. @c "{0}".\n'.format(strFunctions.lowerFirst(element))) outFile.write(' */\n') outFile.write(' virtual const std::string& getElementName () const;\n\n\n')
def writeCreateObject(fileOut, mem, ifCount, pkg): name = strFunctions.cap(mem['name']) if ifCount == 1: fileOut.write(' if (name == "{0}" ) \n'.format( strFunctions.lowerFirst(name))) else: fileOut.write(' else if (name == "{0}" ) \n'.format( strFunctions.lowerFirst(name))) fileOut.write(' { \n') fileOut.write(' m{0} = new {0}({1}ns);\n\n'.format(name, pkg.lower())) fileOut.write(' object = m{0};\n\n'.format(name)) fileOut.write(' } \n')
def writePlugins(fileOut, name, plugins): capName = name.upper() fileOut.write('#ifdef USE_{0}\n'.format(capName)) fileOut.write('if (pkgName == "{0}")\n'.format(name)) fileOut.write('{\n') for i in range(0, len(plugins)): plugin = plugins[i] if (i == 0): fileOut.write(' if ') else: fileOut.write(' else if ') typecode = 'SBML_{0}'.format(createSBase(plugin['sbase'].upper())) if plugin.has_key('typecode') and plugin['typecode'] != None: typecode = plugin['typecode'] fileOut.write('(sb->getTypeCode() == {0})\n'.format(typecode)) fileOut.write(' {\n') if typecode != 'SBML_LIST_OF': fileOut.write(' return SWIGTYPE_p_{0}{1}Plugin;\n'.format( strFunctions.cap(name), plugin['sbase'])) else: fileOut.write(' std::string name = sb->getElementName();\n') fileOut.write(' if(name == "{0}")\n'.format( strFunctions.lowerFirst(plugin['sbase']))) fileOut.write(' return SWIGTYPE_p_{0}{1}Plugin;\n'.format( strFunctions.cap(name), plugin['sbase'])) fileOut.write(' }\n') fileOut.write('}\n') fileOut.write('\n') fileOut.write('#endif // USE_{0} \n\n'.format(capName))
def writePlugins(fileOut, name, plugins): capName = name.upper() fileOut.write('#ifdef USE_{0}\n'.format(capName)) fileOut.write('if (pkgName == "{0}")\n'.format(name)) fileOut.write('{\n') for i in range (0, len(plugins)): plugin = plugins[i] if (i == 0): fileOut.write(' if ') else: fileOut.write(' else if ') typecode = 'SBML_{0}'.format(createSBase(plugin['sbase'].upper())) if plugin.has_key('typecode') and plugin['typecode'] != None: typecode = plugin['typecode'] fileOut.write('(sb->getTypeCode() == {0})\n'.format(typecode)) fileOut.write(' {\n') if typecode != 'SBML_LIST_OF': fileOut.write(' return SWIGTYPE_p_{0}{1}Plugin;\n'.format(strFunctions.cap(name), plugin['sbase'])) else: fileOut.write(' std::string name = sb->getElementName();\n') fileOut.write(' if(name == "{0}")\n'.format(strFunctions.lowerFirst(plugin['sbase']))) fileOut.write(' return SWIGTYPE_p_{0}{1}Plugin;\n'.format(strFunctions.cap(name), plugin['sbase'])) fileOut.write(' }\n') fileOut.write('}\n') fileOut.write('\n') fileOut.write('#endif // USE_{0} \n\n'.format(capName))
def writeMemberFunctions(fileOut, object, plugin): fileOut.write(' /**\n') fileOut.write(' * Returns the {0} from this {1} object.\n'.format(object, plugin)) fileOut.write(' *\n') fileOut.write(' * @return the {0} from object in this {1} object.\n'.format(object, plugin)) fileOut.write(' */\n') fileOut.write(' const {0}* get{0} () const;\n\n\n'.format(object)) fileOut.write(' /**\n') fileOut.write(' * Returns the {0} from this {1} object.\n'.format(object, plugin)) fileOut.write(' *\n') fileOut.write(' * @return the {0} from object in this {1} object.\n'.format(object, plugin)) fileOut.write(' */\n') fileOut.write(' {0}* get{0} ();\n\n\n'.format(object)) fileOut.write(' /**\n') fileOut.write(' * Predicate returning @c true or @c false depending on ') fileOut.write('whether the\n \"{0}\" '.format(object)) fileOut.write('element has been set.\n *\n') fileOut.write(' * @return @c true if the \"{0}\"'.format(object)) fileOut.write(' element has been set,\n') fileOut.write(' * otherwise @c false is returned.\n') fileOut.write(' */\n') fileOut.write(' bool isSet{0}() const;\n\n\n'.format(object)) fileOut.write(' /**\n') fileOut.write(' * Sets the {0} element in this {1} object.\n'.format(object, plugin)) fileOut.write(' *\n') fileOut.write(' * @param {0} the {0}* to be set.\n'.format(strFunctions.lowerFirst(object), object)) fileOut.write(' *\n') fileOut.write(' * @return integer value indicating success/failure of the\n') fileOut.write(' * function. @if clike The value is drawn from the\n') fileOut.write(' * enumeration #OperationReturnValues_t. @endif The possible values\n') fileOut.write(' * returned by this function are:\n') fileOut.write(' * @li LIBSBML_OPERATION_SUCCESS\n') fileOut.write(' */\n') fileOut.write(' int set{0} (const {0}* {1});\n\n\n'.format(object, strFunctions.lowerFirst(object))) fileOut.write(' /**\n') fileOut.write(' * Creates a new {0} object and adds it to the {1} object.\n'.format(object, plugin)) fileOut.write(' *\n') fileOut.write(' * @return the newly created {0} object.\n'.format(object)) fileOut.write(' */\n') fileOut.write(' {0}* create{0} ();\n\n\n'.format(object))
def writeGetElementNameCPPCode(outFile, element, isSedListOf=False, dict=None): outFile.write('/*\n') outFile.write(' * Returns the XML element name of this object\n') outFile.write(' */\n') outFile.write('const std::string&\n{0}::getElementName () const\n'.format(element)) outFile.write('{\n') if dict != None and dict.has_key('elementName'): if isSedListOf: outFile.write('\tstatic const string name = "listOf{0}s";\n'.format(strFunctions.cap(dict['elementName']))) else: outFile.write('\tstatic const string name = "{0}";\n'.format(dict['elementName'])) else: outFile.write('\tstatic const string name = "{0}";\n'.format(strFunctions.lowerFirst(element))) outFile.write('\treturn name;\n') outFile.write('}\n\n\n')
def writeGetElementNameCPPCode(outFile, element, isSedListOf=False, dict=None): outFile.write('/*\n') outFile.write(' * Returns the XML element name of this object\n') outFile.write(' */\n') outFile.write( 'const std::string&\n{0}::getElementName () const\n'.format(element)) outFile.write('{\n') if dict != None and dict.has_key('elementName'): if isSedListOf: outFile.write( '\tstatic const string name = "listOf{0}s";\n'.format( strFunctions.cap(dict['elementName']))) else: outFile.write('\tstatic const string name = "{0}";\n'.format( dict['elementName'])) else: outFile.write('\tstatic const string name = "{0}";\n'.format( strFunctions.lowerFirst(element))) outFile.write('\treturn name;\n') outFile.write('}\n\n\n')
def writeLOFunctions(fileOut, object, nameOfClass, pkg): ob = strFunctions.objAbbrev(object) fileOut.write('/*\n') fileOut.write(' * Returns the ListOf{0}s in this plugin object.\n'.format(object)) fileOut.write(' */\n') fileOut.write('const ListOf{0}s* \n'.format(object)) fileOut.write('{0}::getListOf{1}s () const\n'.format(nameOfClass, object)) fileOut.write('{\n') fileOut.write(' return &this->m{0}s;\n'.format(object)) fileOut.write('}\n\n\n') fileOut.write('/*\n') fileOut.write(' * Returns the ListOf{0}s in this plugin object.\n'.format(object)) fileOut.write(' */\n') fileOut.write('ListOf{0}s* \n'.format(object)) fileOut.write('{0}::getListOf{1}s ()\n'.format(nameOfClass, object)) fileOut.write('{\n') fileOut.write(' return &this->m{0}s;\n'.format(object)) fileOut.write('}\n\n\n') fileOut.write('/*\n') fileOut.write(' * Returns the {0} object that belongs to the given index.\n'.format(object)) fileOut.write(' */\n') fileOut.write('const {0}*\n'.format(object)) fileOut.write('{0}::get{1}(unsigned int n) const\n'.format(nameOfClass, object)) fileOut.write('{\n') fileOut.write(' return static_cast<const {0}*>(m{0}s.get(n));\n'.format(object)) fileOut.write('}\n\n\n') fileOut.write('/*\n') fileOut.write(' * Returns the {0} object that belongs to the given index.\n'.format(object)) fileOut.write(' */\n') fileOut.write('{0}*\n'.format(object)) fileOut.write('{0}::get{1}(unsigned int n)\n'.format(nameOfClass, object)) fileOut.write('{\n') fileOut.write(' return static_cast<{0}*>(m{0}s.get(n));\n'.format(object)) fileOut.write('}\n\n\n') fileOut.write('/*\n') fileOut.write(' * Returns the {0} object based on its identifier.\n'.format(object)) fileOut.write(' */\n') fileOut.write('const {0}*\n'.format(object)) fileOut.write('{0}::get{1}(const std::string& sid) const\n'.format(nameOfClass, object)) fileOut.write('{\n') fileOut.write(' return static_cast<const {0}*>(m{0}s.get(sid));\n'.format(object)) fileOut.write('}\n\n\n') fileOut.write('/*\n') fileOut.write(' * Returns the {0} object based on its identifier.\n'.format(object)) fileOut.write(' */\n') fileOut.write('{0}*\n'.format(object)) fileOut.write('{0}::get{1}(const std::string& sid)\n'.format(nameOfClass, object)) fileOut.write('{\n') fileOut.write(' return static_cast<{0}*>(m{0}s.get(sid));\n'.format(object)) fileOut.write('}\n\n\n') fileOut.write('/*\n') fileOut.write(' * Adds a copy of the given {0} to the ListOf{0}s in this plugin object.\n'.format(object)) fileOut.write(' */\n') fileOut.write('int\n') fileOut.write('{2}::add{0} (const {0}* {1})\n'.format(object, strFunctions.lowerFirst(object), nameOfClass)) fileOut.write('{\n') fileOut.write(' if ({0} == NULL)\n'.format(strFunctions.lowerFirst(object))) fileOut.write(' {\n') fileOut.write(' return LIBSBML_OPERATION_FAILED;\n') fileOut.write(' }\n') fileOut.write(' else if ({0}->hasRequiredElements() == false)\n'.format(strFunctions.lowerFirst(object))) fileOut.write(' {\n') fileOut.write(' return LIBSBML_INVALID_OBJECT;\n') fileOut.write(' }\n') fileOut.write(' else if (getLevel() != {0}->getLevel())\n'.format(strFunctions.lowerFirst(object))) fileOut.write(' {\n') fileOut.write(' return LIBSBML_LEVEL_MISMATCH;\n') fileOut.write(' }\n') fileOut.write(' else if (getVersion() != {0}->getVersion())\n'.format(strFunctions.lowerFirst(object))) fileOut.write(' {\n') fileOut.write(' return LIBSBML_VERSION_MISMATCH;\n') fileOut.write(' }\n') fileOut.write(' else if (getPackageVersion() != {0}->getPackageVersion())\n'.format(strFunctions.lowerFirst(object))) fileOut.write(' {\n') fileOut.write(' return LIBSBML_PKG_VERSION_MISMATCH;\n') fileOut.write(' }\n') fileOut.write(' else\n') fileOut.write(' {\n') fileOut.write(' m{0}s.append({1});\n'.format(object, strFunctions.lowerFirst(object))) fileOut.write(' }\n\n') fileOut.write(' return LIBSBML_OPERATION_SUCCESS;\n\n') fileOut.write('}\n\n\n') fileOut.write('/*\n') fileOut.write(' * Creates a new {0} object and adds it to the ListOf{0}s in this plugin object.\n'.format(object)) fileOut.write(' */\n') fileOut.write('{0}* \n'.format(object)) fileOut.write('{1}::create{0} ()\n'.format(object, nameOfClass)) fileOut.write('{\n') fileOut.write(' {0}* {1} = NULL;\n\n'.format(object, ob)) fileOut.write(' try\n') fileOut.write(' {\n') fileOut.write(' {0}_CREATE_NS({1}ns, getSBMLNamespaces());\n'.format(pkg.upper(), pkg.lower())) fileOut.write(' {0} = new {1}({2}ns);\n'.format(ob, object, pkg.lower())) fileOut.write(' delete {0}ns;\n'.format(pkg.lower())) fileOut.write(' }\n') fileOut.write(' catch(...)\n') fileOut.write(' {\n') fileOut.write(' }\n\n') fileOut.write(' if ({0} != NULL)\n'.format(ob)) fileOut.write(' {\n') fileOut.write(' m{0}s.appendAndOwn({1});\n'.format(object, ob)) fileOut.write(' }\n\n') fileOut.write(' return {0};\n'.format(ob)) fileOut.write('}\n\n\n') fileOut.write('/*\n') fileOut.write(' * Removes the nth {0} object from this plugin object\n'.format(object)) fileOut.write(' */\n') fileOut.write('{0}* \n'.format(object)) fileOut.write('{1}::remove{0}(unsigned int n)\n'.format(object, nameOfClass)) fileOut.write('{\n') fileOut.write(' return static_cast<{0}*>(m{0}s.remove(n));\n'.format(object)) fileOut.write('}\n\n\n') fileOut.write('/*\n') fileOut.write(' * Removes the {0} object with the given id from this plugin object\n'.format(object)) fileOut.write(' */\n') fileOut.write('{0}* \n'.format(object)) fileOut.write('{1}::remove{0}(const std::string& sid)\n'.format(object, nameOfClass)) fileOut.write('{\n') fileOut.write(' return static_cast<{0}*>(m{0}s.remove(sid));\n'.format(object)) fileOut.write('}\n\n\n') fileOut.write('/*\n') fileOut.write(' * Returns the number of {0} objects in this plugin object.\n'.format(object)) fileOut.write(' */\n') fileOut.write('unsigned int \n') fileOut.write('{1}::getNum{0}s () const\n'.format(object, nameOfClass)) fileOut.write('{\n') fileOut.write(' return m{0}s.size();\n'.format(object)) fileOut.write('}\n\n\n')
def writeJava(fileOut, name, plugins, classes): capName = name.upper() fileOut.write('#ifdef USE_{0}\n'.format(capName)) fileOut.write('/**\n') fileOut.write( ' * Adds DownCastBase(long cPtr, boolean owner) method for the {0} package extension\n' .format(name)) fileOut.write(' */\n') fileOut.write('%typemap(javacode) {0}Extension\n'.format( strFunctions.cap(name))) fileOut.write('%{\n') fileOut.write( ' public SBasePlugin DowncastSBasePlugin(long cPtr, boolean owner)\n') fileOut.write(' {\n') fileOut.write(' if (cPtr == 0) return null;\n\n') fileOut.write(' SBasePlugin sbp = new SBasePlugin(cPtr, false);\n') fileOut.write(' SBase sb = sbp.getParentSBMLObject();\n\n') fileOut.write(' switch( sb.getTypeCode() )\n') fileOut.write(' {\n') listOfPlugins = [] for plugin in plugins: typecode = 'SBML_{0}'.format(createSBase(plugin['sbase'].upper())) if plugin.has_key('typecode') and plugin['typecode'] != None: typecode = plugin['typecode'] if typecode != 'SBML_LIST_OF': fileOut.write(' case (int) libsbml.{0}:\n'.format(typecode)) fileOut.write( ' return new {0}{1}Plugin(cPtr, owner);\n\n'.format( strFunctions.cap(name), plugin['sbase'])) else: listOfPlugins.append(plugin) if len(listOfPlugins) > 0: fileOut.write(' case (int) libsbml.SBML_LIST_OF:\n') fileOut.write(' {\n') fileOut.write(' String name = sb.getElementName();\n') for plugin in listOfPlugins: fileOut.write(' if (name.equals("{0}"))\n'.format( strFunctions.lowerFirst(plugin['sbase']))) fileOut.write( ' return new {0}{1}Plugin(cPtr, owner);\n\n'.format( strFunctions.cap(name), plugin['sbase'])) fileOut.write(' return new SBasePlugin(cPtr, owner);\n') fileOut.write(' }\n') fileOut.write(' default:\n') fileOut.write(' return new SBasePlugin(cPtr, owner);\n') fileOut.write(' }\n') fileOut.write(' }\n\n') fileOut.write(' public SBase DowncastSBase(long cPtr, boolean owner)\n') fileOut.write(' {\n') fileOut.write(' if (cPtr == 0) return null;\n\n') fileOut.write(' SBase sb = new SBase(cPtr, false);\n') fileOut.write(' switch( sb.getTypeCode() )\n') fileOut.write(' {\n') fileOut.write(' case (int) libsbml.SBML_LIST_OF:\n') fileOut.write(' String name = sb.getElementName();\n') for i in range(0, len(classes)): if (classes[i]['hasListOf'] == True): loName = strFunctions.listOfName(classes[i]['name']) if classes[i].has_key('lo_elementName'): loName = classes[i]['lo_elementName'] if (i == 0): fileOut.write( ' if (name.equals("{0}"))\n'.format(loName)) else: fileOut.write( ' else if (name.equals("{0}"))\n'.format(loName)) fileOut.write(' {\n') fileOut.write(' return new {0}(cPtr, owner);\n'.format( generalFunctions.getListOfClassName(classes[i], classes[i]['name']))) fileOut.write(' }\n') fileOut.write('\n return new ListOf(cPtr, owner);\n\n') for i in range(0, len(classes)): if classes[i]['typecode'] != 'HACK': fileOut.write(' case (int) libsbml.{0}:\n'.format( classes[i]['typecode'])) fileOut.write(' return new {0}(cPtr, owner);\n\n'.format( classes[i]['name'])) fileOut.write(' default:\n') fileOut.write(' return new SBase(cPtr, owner);\n') fileOut.write(' }\n') fileOut.write(' }\n\n') fileOut.write('%}\n\n') fileOut.write('COVARIANT_RTYPE_CLONE({0}Extension)\n'.format( strFunctions.cap(name))) for i in range(0, len(classes)): if classes[i]['typecode'] != 'HACK': fileOut.write('COVARIANT_RTYPE_CLONE({0})\n'.format( classes[i]['name'])) for i in range(0, len(classes)): if (classes[i]['hasListOf'] == True): loName = generalFunctions.getListOfClassName( classes[i], classes[i]['name']) fileOut.write('COVARIANT_RTYPE_CLONE({0})\n'.format( strFunctions.cap(loName))) fileOut.write('\n') for i in range(0, len(classes)): if (classes[i]['hasListOf'] == True): fileOut.write('COVARIANT_RTYPE_LISTOF_GET_REMOVE({0})\n'.format( classes[i]['name'])) fileOut.write('\n') fileOut.write('SBMLCONSTRUCTOR_EXCEPTION({0}PkgNamespaces)\n'.format( strFunctions.cap(name))) for i in range(0, len(classes)): if classes[i]['typecode'] != 'HACK': fileOut.write('SBMLCONSTRUCTOR_EXCEPTION({0})\n'.format( classes[i]['name'])) for i in range(0, len(classes)): if (classes[i]['hasListOf'] == True): loName = generalFunctions.getListOfClassName( classes[i], classes[i]['name']) fileOut.write('SBMLCONSTRUCTOR_EXCEPTION({0})\n'.format( strFunctions.cap(loName))) fileOut.write('\n') for i in range(0, len(classes)): if (classes[i]['abstract'] == True or isBaseClassForOthers(classes[i], classes)): fileOut.write('//\n') fileOut.write( '// Convert {0} objects into the most specific object possible.\n' .format(classes[i]['name'])) fileOut.write('//\n') fileOut.write('%typemap("javaout") {0}*\n'.format( classes[i]['name'])) fileOut.write('{\n') fileOut.write( ' return ({0}) libsbml.DowncastSBase($jnicall, $owner);\n'. format(classes[i]['name'])) fileOut.write('}\n') fileOut.write('\n') fileOut.write('\n') fileOut.write('#endif /* USE_{0} */\n\n'.format(capName))
def writeConstructors(element, package, output, attrs, hasChildren=False, hasMath=False, elementDict=None, childrenOverwrite=False): baseClass = 'SBase' if elementDict != None and elementDict.has_key('baseClass'): baseClass = elementDict['baseClass'] output.write('/*\n') output.write(' * Creates a new {0}'.format(element)) output.write(' with the given level, version, and package version.\n */\n') output.write('{0}::{0} (unsigned int level, unsigned int version, unsigned int pkgVersion)\n'.format(element)) output.write(' : {0}(level, version)\n'.format(baseClass)) writeAttributes(attrs, output, 1) if childrenOverwrite: output.write(' , mElementName("{0}")\n'.format(strFunctions.lowerFirst(elementDict['name']))) output.write('{\n') output.write(' // set an SBMLNamespaces derived object of this package\n') output.write(' setSBMLNamespacesAndOwn(new {0}PkgNamespaces(level, version, pkgVersion));\n'.format(package)) if hasChildren == True or hasMath == True: output.write('\n // connect to child objects\n') output.write(' connectToChild();\n') output.write('}\n\n\n') output.write('/*\n') output.write(' * Creates a new {0}'.format(element)) output.write(' with the given {0}PkgNamespaces object.\n */\n'.format(package)) output.write('{0}::{0} ({1}PkgNamespaces* {2}ns)\n'.format(element, package, package.lower())) output.write(' : {1}({0}ns)\n'.format(package.lower(), baseClass)) writeAttributes(attrs, output, 2, package.lower()) if childrenOverwrite: output.write(' , mElementName("{0}")\n'.format(strFunctions.lowerFirst(elementDict['name']))) output.write('{\n') output.write(' // set the element namespace of this object\n') output.write(' setElementNamespace({0}ns->getURI());\n'.format(package.lower())) if hasChildren == True: output.write('\n // connect to child objects\n') output.write(' connectToChild();\n') output.write('\n // load package extensions bound with this object (if any) \n') output.write(' loadPlugins({0}ns);\n'.format(package.lower())) output.write('}\n\n\n') output.write('/*\n') output.write(' * Copy constructor for {0}.\n */\n'.format(element)) output.write('{0}::{0} (const {0}& orig)\n'.format(element, package, package.lower())) output.write(' : {0}(orig)\n'.format(baseClass)) output.write('{\n') writeCopyAttributes(attrs, output, ' ', 'orig') if childrenOverwrite: output.write(' mElementName = orig.mElementName;\n') if hasChildren == True: output.write('\n // connect to child objects\n') output.write(' connectToChild();\n') output.write('}\n\n\n') output.write('/*\n') output.write(' * Assignment for {0}.\n */\n'.format(element)) output.write('{0}&\n{0}::operator=(const {0}& rhs)\n'.format(element)) output.write('{\n') output.write(' if (&rhs != this)\n') output.write(' {\n') output.write(' {0}::operator=(rhs);\n'.format(baseClass)) writeCopyAttributes(attrs, output, ' ', 'rhs') if childrenOverwrite: output.write(' mElementName = rhs.mElementName;\n') if hasChildren == True: output.write('\n // connect to child objects\n') output.write(' connectToChild();\n') output.write(' }\n') output.write(' return *this;\n') output.write('}\n\n\n') output.write('/*\n') output.write(' * Clone for {0}.\n */\n'.format(element)) output.write('{0}*\n{0}::clone () const\n'.format(element)) output.write('{\n') output.write(' return new {0}(*this);\n'.format(element)) output.write('}\n\n\n') output.write('/*\n') output.write(' * Destructor for {0}.\n */\n'.format(element)) output.write('{0}::~{0} ()\n'.format(element)) output.write('{\n') if hasMath == True: output.write(' delete mMath;\n') output.write(' mMath = NULL;\n') for i in range (0, len(attrs)): current = attrs[i]; if current['type'] == 'element' and current['name'] != 'math': output.write(' delete m{0};\n'.format(strFunctions.cap(current['name']))) output.write(' m{0} = NULL;\n'.format(strFunctions.cap(current['name']))) elif current['type'] == 'array': output.write(' if (m{0} != NULL)\n'.format(strFunctions.cap(current['name']))) output.write(' delete[] m{0};\n'.format(strFunctions.cap(current['name']))) output.write(' m{0} = NULL;\n'.format(strFunctions.cap(current['name']))) output.write('}\n\n\n')
def writeLOFunctions(fileOut, object, nameOfClass, pkg): ob = strFunctions.objAbbrev(object) fileOut.write('/*\n') fileOut.write( ' * Returns the ListOf{0}s in this plugin object.\n'.format(object)) fileOut.write(' */\n') fileOut.write('const ListOf{0}s* \n'.format(object)) fileOut.write('{0}::getListOf{1}s () const\n'.format(nameOfClass, object)) fileOut.write('{\n') fileOut.write(' return &this->m{0}s;\n'.format(object)) fileOut.write('}\n\n\n') fileOut.write('/*\n') fileOut.write( ' * Returns the ListOf{0}s in this plugin object.\n'.format(object)) fileOut.write(' */\n') fileOut.write('ListOf{0}s* \n'.format(object)) fileOut.write('{0}::getListOf{1}s ()\n'.format(nameOfClass, object)) fileOut.write('{\n') fileOut.write(' return &this->m{0}s;\n'.format(object)) fileOut.write('}\n\n\n') fileOut.write('/*\n') fileOut.write( ' * Returns the {0} object that belongs to the given index.\n'.format( object)) fileOut.write(' */\n') fileOut.write('const {0}*\n'.format(object)) fileOut.write('{0}::get{1}(unsigned int n) const\n'.format( nameOfClass, object)) fileOut.write('{\n') fileOut.write( ' return static_cast<const {0}*>(m{0}s.get(n));\n'.format(object)) fileOut.write('}\n\n\n') fileOut.write('/*\n') fileOut.write( ' * Returns the {0} object that belongs to the given index.\n'.format( object)) fileOut.write(' */\n') fileOut.write('{0}*\n'.format(object)) fileOut.write('{0}::get{1}(unsigned int n)\n'.format(nameOfClass, object)) fileOut.write('{\n') fileOut.write(' return static_cast<{0}*>(m{0}s.get(n));\n'.format(object)) fileOut.write('}\n\n\n') fileOut.write('/*\n') fileOut.write( ' * Returns the {0} object based on its identifier.\n'.format(object)) fileOut.write(' */\n') fileOut.write('const {0}*\n'.format(object)) fileOut.write('{0}::get{1}(const std::string& sid) const\n'.format( nameOfClass, object)) fileOut.write('{\n') fileOut.write( ' return static_cast<const {0}*>(m{0}s.get(sid));\n'.format(object)) fileOut.write('}\n\n\n') fileOut.write('/*\n') fileOut.write( ' * Returns the {0} object based on its identifier.\n'.format(object)) fileOut.write(' */\n') fileOut.write('{0}*\n'.format(object)) fileOut.write('{0}::get{1}(const std::string& sid)\n'.format( nameOfClass, object)) fileOut.write('{\n') fileOut.write( ' return static_cast<{0}*>(m{0}s.get(sid));\n'.format(object)) fileOut.write('}\n\n\n') fileOut.write('/*\n') fileOut.write( ' * Adds a copy of the given {0} to the ListOf{0}s in this plugin object.\n' .format(object)) fileOut.write(' */\n') fileOut.write('int\n') fileOut.write('{2}::add{0} (const {0}* {1})\n'.format( object, strFunctions.lowerFirst(object), nameOfClass)) fileOut.write('{\n') fileOut.write(' if ({0} == NULL)\n'.format( strFunctions.lowerFirst(object))) fileOut.write(' {\n') fileOut.write(' return LIBSBML_OPERATION_FAILED;\n') fileOut.write(' }\n') fileOut.write(' else if ({0}->hasRequiredElements() == false)\n'.format( strFunctions.lowerFirst(object))) fileOut.write(' {\n') fileOut.write(' return LIBSBML_INVALID_OBJECT;\n') fileOut.write(' }\n') fileOut.write(' else if (getLevel() != {0}->getLevel())\n'.format( strFunctions.lowerFirst(object))) fileOut.write(' {\n') fileOut.write(' return LIBSBML_LEVEL_MISMATCH;\n') fileOut.write(' }\n') fileOut.write(' else if (getVersion() != {0}->getVersion())\n'.format( strFunctions.lowerFirst(object))) fileOut.write(' {\n') fileOut.write(' return LIBSBML_VERSION_MISMATCH;\n') fileOut.write(' }\n') fileOut.write( ' else if (getPackageVersion() != {0}->getPackageVersion())\n'.format( strFunctions.lowerFirst(object))) fileOut.write(' {\n') fileOut.write(' return LIBSBML_PKG_VERSION_MISMATCH;\n') fileOut.write(' }\n') fileOut.write(' else\n') fileOut.write(' {\n') fileOut.write(' m{0}s.append({1});\n'.format( object, strFunctions.lowerFirst(object))) fileOut.write(' }\n\n') fileOut.write(' return LIBSBML_OPERATION_SUCCESS;\n\n') fileOut.write('}\n\n\n') fileOut.write('/*\n') fileOut.write( ' * Creates a new {0} object and adds it to the ListOf{0}s in this plugin object.\n' .format(object)) fileOut.write(' */\n') fileOut.write('{0}* \n'.format(object)) fileOut.write('{1}::create{0} ()\n'.format(object, nameOfClass)) fileOut.write('{\n') fileOut.write(' {0}* {1} = NULL;\n\n'.format(object, ob)) fileOut.write(' try\n') fileOut.write(' {\n') fileOut.write(' {0}_CREATE_NS({1}ns, getSBMLNamespaces());\n'.format( pkg.upper(), pkg.lower())) fileOut.write(' {0} = new {1}({2}ns);\n'.format(ob, object, pkg.lower())) fileOut.write(' delete {0}ns;\n'.format(pkg.lower())) fileOut.write(' }\n') fileOut.write(' catch(...)\n') fileOut.write(' {\n') fileOut.write(' }\n\n') fileOut.write(' if ({0} != NULL)\n'.format(ob)) fileOut.write(' {\n') fileOut.write(' m{0}s.appendAndOwn({1});\n'.format(object, ob)) fileOut.write(' }\n\n') fileOut.write(' return {0};\n'.format(ob)) fileOut.write('}\n\n\n') fileOut.write('/*\n') fileOut.write( ' * Removes the nth {0} object from this plugin object\n'.format( object)) fileOut.write(' */\n') fileOut.write('{0}* \n'.format(object)) fileOut.write('{1}::remove{0}(unsigned int n)\n'.format( object, nameOfClass)) fileOut.write('{\n') fileOut.write( ' return static_cast<{0}*>(m{0}s.remove(n));\n'.format(object)) fileOut.write('}\n\n\n') fileOut.write('/*\n') fileOut.write( ' * Removes the {0} object with the given id from this plugin object\n' .format(object)) fileOut.write(' */\n') fileOut.write('{0}* \n'.format(object)) fileOut.write('{1}::remove{0}(const std::string& sid)\n'.format( object, nameOfClass)) fileOut.write('{\n') fileOut.write( ' return static_cast<{0}*>(m{0}s.remove(sid));\n'.format(object)) fileOut.write('}\n\n\n') fileOut.write('/*\n') fileOut.write( ' * Returns the number of {0} objects in this plugin object.\n'.format( object)) fileOut.write(' */\n') fileOut.write('unsigned int \n') fileOut.write('{1}::getNum{0}s () const\n'.format(object, nameOfClass)) fileOut.write('{\n') fileOut.write(' return m{0}s.size();\n'.format(object)) fileOut.write('}\n\n\n')
def writeFunctions(fileOut, object, nameOfClass, pkg): ob = strFunctions.lowerFirst(object) fileOut.write('/*\n') fileOut.write(' * Returns the {0} from this {1} object.\n'.format( object, nameOfClass)) fileOut.write(' */\n') fileOut.write('const {0}* \n'.format(object)) fileOut.write('{0}::get{1} () const\n'.format(nameOfClass, object)) fileOut.write('{\n') fileOut.write(' return m{0};\n'.format(object)) fileOut.write('}\n\n\n') fileOut.write('/*\n') fileOut.write(' * Returns the {0} from this {1} object.\n'.format( object, nameOfClass)) fileOut.write(' */\n') fileOut.write('{0}* \n'.format(object)) fileOut.write('{0}::get{1} ()\n'.format(nameOfClass, object)) fileOut.write('{\n') fileOut.write(' return m{0};\n'.format(object)) fileOut.write('}\n\n\n') fileOut.write('/*\n') fileOut.write(' * @return @c true if the \"{0}\"'.format(object)) fileOut.write(' element has been set,\n') fileOut.write(' */\n') fileOut.write('bool \n'.format(object)) fileOut.write('{0}::isSet{1} () const\n'.format(nameOfClass, object)) fileOut.write('{\n') fileOut.write(' return (m{0} != NULL);\n'.format(object)) fileOut.write('}\n\n\n') fileOut.write('/*\n') fileOut.write(' * Sets the {0} element in this {1} object.\n'.format( object, nameOfClass)) fileOut.write(' */\n') fileOut.write('int\n'.format(object)) fileOut.write('{0}::set{1}(const {1}* {2})\n'.format( nameOfClass, object, ob)) fileOut.write('{\n') fileOut.write(' if ({0} == NULL)\n'.format(ob)) fileOut.write(' {\n') fileOut.write(' return LIBSBML_OPERATION_FAILED;\n') fileOut.write(' }\n') fileOut.write( ' else if ({0}->hasRequiredElements() == false)\n'.format(ob)) fileOut.write(' {\n') fileOut.write(' return LIBSBML_INVALID_OBJECT;\n') fileOut.write(' }\n') fileOut.write(' else if (getLevel() != {0}->getLevel())\n'.format(ob)) fileOut.write(' {\n') fileOut.write(' return LIBSBML_LEVEL_MISMATCH;\n') fileOut.write(' }\n') fileOut.write(' else if (getVersion() != {0}->getVersion())\n'.format(ob)) fileOut.write(' {\n') fileOut.write(' return LIBSBML_VERSION_MISMATCH;\n') fileOut.write(' }\n') fileOut.write( ' else if (getPackageVersion() != {0}->getPackageVersion())\n'.format( ob)) fileOut.write(' {\n') fileOut.write(' return LIBSBML_PKG_VERSION_MISMATCH;\n') fileOut.write(' }\n') fileOut.write(' else\n') fileOut.write(' {\n') fileOut.write(' delete m{0};\n'.format(object)) fileOut.write(' m{0} = static_cast<{0}*>({1}->clone());\n'.format( object, ob)) fileOut.write(' return LIBSBML_OPERATION_SUCCESS;\n') fileOut.write(' }\n') fileOut.write('}\n\n\n') fileOut.write('/*\n') fileOut.write( ' * Creates a new {0} object and adds it to the {1} object.\n'.format( object, nameOfClass)) fileOut.write(' */\n') fileOut.write('{0}*\n'.format(object)) fileOut.write('{0}::create{1}()\n'.format(nameOfClass, object)) fileOut.write('{\n') fileOut.write(' delete m{0};\n'.format(object)) fileOut.write(' {0}_CREATE_NS({1}ns, getSBMLNamespaces());\n'.format( pkg.upper(), pkg.lower())) fileOut.write(' m{0} = new {0}({1}ns);\n\n'.format(object, pkg.lower())) fileOut.write( ' m{0}->setSBMLDocument(this->getSBMLDocument());\n\n'.format(object)) fileOut.write(' delete {0}ns;\n\n'.format(pkg.lower())) fileOut.write(' return m{0};\n'.format(object)) fileOut.write('}\n\n\n')
def writeFunctions(fileOut, object, nameOfClass, pkg): ob = strFunctions.lowerFirst(object) fileOut.write('/*\n') fileOut.write(' * Returns the {0} from this {1} object.\n'.format(object, nameOfClass)) fileOut.write(' */\n') fileOut.write('const {0}* \n'.format(object)) fileOut.write('{0}::get{1} () const\n'.format(nameOfClass, object)) fileOut.write('{\n') fileOut.write(' return m{0};\n'.format(object)) fileOut.write('}\n\n\n') fileOut.write('/*\n') fileOut.write(' * Returns the {0} from this {1} object.\n'.format(object, nameOfClass)) fileOut.write(' */\n') fileOut.write('{0}* \n'.format(object)) fileOut.write('{0}::get{1} ()\n'.format(nameOfClass, object)) fileOut.write('{\n') fileOut.write(' return m{0};\n'.format(object)) fileOut.write('}\n\n\n') fileOut.write('/*\n') fileOut.write(' * @return @c true if the \"{0}\"'.format(object)) fileOut.write(' element has been set,\n') fileOut.write(' */\n') fileOut.write('bool \n'.format(object)) fileOut.write('{0}::isSet{1} () const\n'.format(nameOfClass, object)) fileOut.write('{\n') fileOut.write(' return (m{0} != NULL);\n'.format(object)) fileOut.write('}\n\n\n') fileOut.write('/*\n') fileOut.write(' * Sets the {0} element in this {1} object.\n'.format(object, nameOfClass)) fileOut.write(' */\n') fileOut.write('int\n'.format(object)) fileOut.write('{0}::set{1}(const {1}* {2})\n'.format(nameOfClass, object, ob)) fileOut.write('{\n') fileOut.write(' if ({0} == NULL)\n'.format(ob)) fileOut.write(' {\n') fileOut.write(' return LIBSBML_OPERATION_FAILED;\n') fileOut.write(' }\n') fileOut.write(' else if ({0}->hasRequiredElements() == false)\n'.format(ob)) fileOut.write(' {\n') fileOut.write(' return LIBSBML_INVALID_OBJECT;\n') fileOut.write(' }\n') fileOut.write(' else if (getLevel() != {0}->getLevel())\n'.format(ob)) fileOut.write(' {\n') fileOut.write(' return LIBSBML_LEVEL_MISMATCH;\n') fileOut.write(' }\n') fileOut.write(' else if (getVersion() != {0}->getVersion())\n'.format(ob)) fileOut.write(' {\n') fileOut.write(' return LIBSBML_VERSION_MISMATCH;\n') fileOut.write(' }\n') fileOut.write(' else if (getPackageVersion() != {0}->getPackageVersion())\n'.format(ob)) fileOut.write(' {\n') fileOut.write(' return LIBSBML_PKG_VERSION_MISMATCH;\n') fileOut.write(' }\n') fileOut.write(' else\n') fileOut.write(' {\n') fileOut.write(' delete m{0};\n'.format(object)) fileOut.write(' m{0} = static_cast<{0}*>({1}->clone());\n'.format(object, ob)) fileOut.write(' return LIBSBML_OPERATION_SUCCESS;\n') fileOut.write(' }\n') fileOut.write('}\n\n\n') fileOut.write('/*\n') fileOut.write(' * Creates a new {0} object and adds it to the {1} object.\n'.format(object, nameOfClass)) fileOut.write(' */\n') fileOut.write('{0}*\n'.format(object)) fileOut.write('{0}::create{1}()\n'.format(nameOfClass, object)) fileOut.write('{\n') fileOut.write(' delete m{0};\n'.format(object)) fileOut.write(' {0}_CREATE_NS({1}ns, getSBMLNamespaces());\n'.format(pkg.upper(), pkg.lower())) fileOut.write(' m{0} = new {0}({1}ns);\n\n'.format(object, pkg.lower())) fileOut.write(' m{0}->setSBMLDocument(this->getSBMLDocument());\n\n'.format(object)) fileOut.write(' delete {0}ns;\n\n'.format(pkg.lower())) fileOut.write(' return m{0};\n'.format(object)) fileOut.write('}\n\n\n')
def writeFunctions(fileOut, object): fileOut.write(' /**\n') fileOut.write( ' * Returns the ListOf{0}s in this plugin object.\n'.format(object)) fileOut.write(' *\n') fileOut.write( ' * @return ListOf{0}s object in this plugin object.\n'.format( object)) fileOut.write(' */\n') fileOut.write( ' const ListOf{0}s* getListOf{0}s () const;\n\n\n'.format(object)) fileOut.write(' /**\n') fileOut.write( ' * Returns the ListOf{0}s in this plugin object.\n'.format(object)) fileOut.write(' *\n') fileOut.write( ' * @return ListOf{0}s object in this plugin object.\n'.format( object)) fileOut.write(' */\n') fileOut.write(' ListOf{0}s* getListOf{0}s ();\n\n\n'.format(object)) fileOut.write(' /**\n') fileOut.write( ' * Returns the {0} object that belongs to the given index. If the \n' .format(object)) fileOut.write(' * index is invalid, NULL is returned.\n') fileOut.write(' *\n') fileOut.write( ' * @param n the index number of the {0} to get\n'.format(object)) fileOut.write(' *\n') fileOut.write( ' * @return the nth {0} in the ListOf{0}s\n'.format(object)) fileOut.write(' */\n') fileOut.write( ' const {0}* get{0}(unsigned int n) const;\n\n\n'.format(object)) fileOut.write(' /**\n') fileOut.write( ' * Returns the {0} object that belongs to the given index. If the \n' .format(object)) fileOut.write(' * index is invalid, NULL is returned.\n') fileOut.write(' *\n') fileOut.write( ' * @param n the index number of the {0} to get\n'.format(object)) fileOut.write(' *\n') fileOut.write( ' * @return the nth {0} in the ListOf{0}s\n'.format(object)) fileOut.write(' */\n') fileOut.write(' {0}* get{0}(unsigned int n);\n\n\n'.format(object)) fileOut.write(' /**\n') fileOut.write( ' * Returns the {0} object based on its identifier.\n'.format( object)) fileOut.write(' *\n') fileOut.write( ' * @param sid a string representing the id of the {0} to get\n'. format(object)) fileOut.write(' *\n') fileOut.write( ' * @return {0} in the ListOf{0}s with the given id\n'.format( object)) fileOut.write(' * or NULL if no such {0} exists.\n'.format(object)) fileOut.write(' *\n') fileOut.write(' * @see get(unsigned int n)\n') fileOut.write(' * @see size()\n') fileOut.write(' */\n') fileOut.write( ' const {0}* get{0}(const std::string& sid) const;\n\n\n'.format( object)) fileOut.write(' /**\n') fileOut.write( ' * Returns the {0} object based on its identifier.\n'.format( object)) fileOut.write(' *\n') fileOut.write( ' * @param sid a string representing the id of the {0} to get\n'. format(object)) fileOut.write(' *\n') fileOut.write( ' * @return {0} in the ListOf{0}s with the given id\n'.format( object)) fileOut.write(' * or NULL if no such {0} exists.\n'.format(object)) fileOut.write(' *\n') fileOut.write(' * @see get(unsigned int n)\n') fileOut.write(' * @see size()\n') fileOut.write(' */\n') fileOut.write( ' {0}* get{0}(const std::string& sid);\n\n\n'.format(object)) fileOut.write(' /**\n') fileOut.write( ' * Adds a copy of the given {0} to the ListOf{0}s in this plugin object.\n' .format(object)) fileOut.write(' *\n') fileOut.write(' * @param {0} the {0} to be added.\n'.format( strFunctions.lowerFirst(object), object)) fileOut.write(' *\n') fileOut.write( ' * @return integer value indicating success/failure of the\n') fileOut.write(' * function. @if clike The value is drawn from the\n') fileOut.write( ' * enumeration #OperationReturnValues_t. @endif The possible values\n' ) fileOut.write(' * returned by this function are:\n') fileOut.write(' * @li LIBSBML_OPERATION_SUCCESS\n') fileOut.write(' */\n') fileOut.write(' int add{0} (const {0}* {1});\n\n\n'.format( object, strFunctions.lowerFirst(object))) fileOut.write(' /**\n') fileOut.write( ' * Creates a new {0} object and adds it to the ListOf{0}s in this plugin object.\n' .format(object)) fileOut.write(' *\n') fileOut.write( ' * @return the newly created {0} object.\n'.format(object)) fileOut.write(' */\n') fileOut.write(' {0}* create{0} ();\n\n\n'.format(object)) fileOut.write(' /**\n') fileOut.write( ' * Removes the nth {0} object from this plugin object\n'.format( object)) fileOut.write(' * and returns a pointer to it.\n') fileOut.write(' *\n') fileOut.write( ' * The caller owns the returned object and is responsible for\n') fileOut.write(' * deleting it.\n') fileOut.write(' *\n') fileOut.write( ' * @param n the index of the {0} to remove\n'.format(object)) fileOut.write(' *\n') fileOut.write(' * @return the {0} object removed \n'.format(object)) fileOut.write(' * or NULL index was out of range.\n'.format(object)) fileOut.write(' */\n') fileOut.write(' {0}* remove{0}(unsigned int n);\n\n\n'.format(object)) fileOut.write(' /**\n') fileOut.write( ' * Removes the {0} object with the given id from this plugin object\n' .format(object)) fileOut.write(' * and returns a pointer to it.\n') fileOut.write(' *\n') fileOut.write( ' * The caller owns the returned object and is responsible for\n') fileOut.write(' * deleting it.\n') fileOut.write(' *\n') fileOut.write( ' * @param sid a string representing the id of the {0} to remove\n'. format(object)) fileOut.write(' *\n') fileOut.write(' * @return the {0} object removed \n'.format(object)) fileOut.write(' * or NULL if no such {0} exists.\n'.format(object)) fileOut.write(' */\n') fileOut.write( ' {0}* remove{0}(const std::string& sid);\n\n\n'.format(object)) fileOut.write(' /**\n') fileOut.write( ' * Returns the number of {0} objects in this plugin object.\n'. format(object)) fileOut.write(' *\n') fileOut.write( ' * @return the number of {0} objects in this plugin object.\n'. format(object)) fileOut.write(' */\n') fileOut.write(' unsigned int getNum{0}s () const;\n\n\n'.format(object))
def writeJava(fileOut, name, plugins, classes): capName = name.upper() fileOut.write('#ifdef USE_{0}\n'.format(capName)) fileOut.write('/**\n') fileOut.write(' * Adds DownCastBase(long cPtr, boolean owner) method for the {0} package extension\n'.format(name)) fileOut.write(' */\n') fileOut.write('%typemap(javacode) {0}Extension\n'.format(strFunctions.cap(name))) fileOut.write('%{\n') fileOut.write(' public SBasePlugin DowncastSBasePlugin(long cPtr, boolean owner)\n') fileOut.write(' {\n') fileOut.write(' if (cPtr == 0) return null;\n\n') fileOut.write(' SBasePlugin sbp = new SBasePlugin(cPtr, false);\n') fileOut.write(' SBase sb = sbp.getParentSBMLObject();\n\n') fileOut.write(' switch( sb.getTypeCode() )\n') fileOut.write(' {\n') listOfPlugins = [] for plugin in plugins: typecode = 'SBML_{0}'.format(createSBase(plugin['sbase'].upper())) if plugin.has_key('typecode') and plugin['typecode'] != None: typecode = plugin['typecode'] if typecode != 'SBML_LIST_OF': fileOut.write(' case (int) libsbml.{0}:\n'.format(typecode)) fileOut.write(' return new {0}{1}Plugin(cPtr, owner);\n\n'.format(strFunctions.cap(name), plugin['sbase'])) else: listOfPlugins.append(plugin) if len(listOfPlugins) > 0: fileOut.write(' case (int) libsbml.SBML_LIST_OF:\n') fileOut.write(' {\n') fileOut.write(' String name = sb.getElementName();\n') for plugin in listOfPlugins: fileOut.write(' if (name.equals("{0}"))\n'.format(strFunctions.lowerFirst(plugin['sbase']))) fileOut.write(' return new {0}{1}Plugin(cPtr, owner);\n\n'.format(strFunctions.cap(name), plugin['sbase'])) fileOut.write(' return new SBasePlugin(cPtr, owner);\n') fileOut.write(' }\n') fileOut.write(' default:\n') fileOut.write(' return new SBasePlugin(cPtr, owner);\n') fileOut.write(' }\n') fileOut.write(' }\n\n') fileOut.write(' public SBase DowncastSBase(long cPtr, boolean owner)\n') fileOut.write(' {\n') fileOut.write(' if (cPtr == 0) return null;\n\n') fileOut.write(' SBase sb = new SBase(cPtr, false);\n') fileOut.write(' switch( sb.getTypeCode() )\n') fileOut.write(' {\n') fileOut.write(' case (int) libsbml.SBML_LIST_OF:\n') fileOut.write(' String name = sb.getElementName();\n') for i in range (0, len(classes)): if (classes[i]['hasListOf'] == True): loName = strFunctions.listOfName(classes[i]['name']) if classes[i].has_key('lo_elementName'): loName = classes[i]['lo_elementName'] if (i==0): fileOut.write(' if (name.equals("{0}"))\n'.format(loName)) else : fileOut.write(' else if (name.equals("{0}"))\n'.format(loName)) fileOut.write(' {\n') fileOut.write(' return new {0}(cPtr, owner);\n'.format(generalFunctions.getListOfClassName (classes[i], classes[i]['name']))) fileOut.write(' }\n') fileOut.write('\n return new ListOf(cPtr, owner);\n\n') for i in range (0, len(classes)): if classes[i]['typecode'] != 'HACK': fileOut.write(' case (int) libsbml.{0}:\n'.format(classes[i]['typecode'])) fileOut.write(' return new {0}(cPtr, owner);\n\n'.format(classes[i]['name'])) fileOut.write(' default:\n') fileOut.write(' return new SBase(cPtr, owner);\n') fileOut.write(' }\n') fileOut.write(' }\n\n') fileOut.write('%}\n\n') fileOut.write('COVARIANT_RTYPE_CLONE({0}Extension)\n'.format(strFunctions.cap(name))) for i in range (0, len(classes)): if classes[i]['typecode'] != 'HACK': fileOut.write('COVARIANT_RTYPE_CLONE({0})\n'.format(classes[i]['name'])) for i in range (0, len(classes)): if (classes[i]['hasListOf'] == True): loName = generalFunctions.getListOfClassName (classes[i], classes[i]['name']) fileOut.write('COVARIANT_RTYPE_CLONE({0})\n'.format(strFunctions.cap(loName))) fileOut.write('\n') for i in range (0, len(classes)): if (classes[i]['hasListOf'] == True): fileOut.write('COVARIANT_RTYPE_LISTOF_GET_REMOVE({0})\n'.format(classes[i]['name'])) fileOut.write('\n') fileOut.write('SBMLCONSTRUCTOR_EXCEPTION({0}PkgNamespaces)\n'.format(strFunctions.cap(name))) for i in range (0, len(classes)): if classes[i]['typecode'] != 'HACK': fileOut.write('SBMLCONSTRUCTOR_EXCEPTION({0})\n'.format(classes[i]['name'])) for i in range (0, len(classes)): if (classes[i]['hasListOf'] == True): loName = generalFunctions.getListOfClassName (classes[i], classes[i]['name']) fileOut.write('SBMLCONSTRUCTOR_EXCEPTION({0})\n'.format(strFunctions.cap(loName))) fileOut.write('\n') for i in range (0, len(classes)): if (classes[i]['abstract'] == True or isBaseClassForOthers(classes[i], classes)): fileOut.write('//\n') fileOut.write('// Convert {0} objects into the most specific object possible.\n'.format(classes[i]['name'])) fileOut.write('//\n') fileOut.write('%typemap("javaout") {0}*\n'.format(classes[i]['name'])) fileOut.write('{\n') fileOut.write(' return ({0}) libsbml.DowncastSBase($jnicall, $owner);\n'.format(classes[i]['name'])) fileOut.write('}\n') fileOut.write('\n') fileOut.write('\n') fileOut.write('#endif /* USE_{0} */\n\n'.format(capName))
def writeConstructors(element, package, output, attrs, hasChildren=False, hasMath=False, elementDict=None, childrenOverwrite=False): baseClass = 'SBase' if elementDict != None and elementDict.has_key('baseClass'): baseClass = elementDict['baseClass'] output.write('/*\n') output.write(' * Creates a new {0}'.format(element)) output.write(' with the given level, version, and package version.\n */\n') output.write('{0}::{0} (unsigned int level, unsigned int version, unsigned int pkgVersion)\n'.format(element)) output.write(' : {0}(level, version)\n'.format(baseClass)) writeAttributes(attrs, output, 1) if childrenOverwrite: output.write(' , mElementName("{0}")\n'.format(strFunctions.lowerFirst(elementDict['name']))) output.write('{\n') output.write(' // set an SBMLNamespaces derived object of this package\n') output.write(' setSBMLNamespacesAndOwn(new {0}PkgNamespaces(level, version, pkgVersion));\n'.format(package)) if hasChildren == True or hasMath == True: output.write('\n // connect to child objects\n') output.write(' connectToChild();\n') output.write('}\n\n\n') output.write('/*\n') output.write(' * Creates a new {0}'.format(element)) output.write(' with the given {0}PkgNamespaces object.\n */\n'.format(package)) output.write('{0}::{0} ({1}PkgNamespaces* {2}ns)\n'.format(element, package, package.lower())) output.write(' : {1}({0}ns)\n'.format(package.lower(), baseClass)) writeAttributes(attrs, output, 2, package.lower()) if childrenOverwrite: output.write(' , mElementName("{0}")\n'.format(strFunctions.lowerFirst(elementDict['name']))) output.write('{\n') output.write(' // set the element namespace of this object\n') output.write(' setElementNamespace({0}ns->getURI());\n'.format(package.lower())) if hasChildren == True: output.write('\n // connect to child objects\n') output.write(' connectToChild();\n') output.write('\n // load package extensions bound with this object (if any) \n') output.write(' loadPlugins({0}ns);\n'.format(package.lower())) output.write('}\n\n\n') output.write('/*\n') output.write(' * Copy constructor for {0}.\n */\n'.format(element)) output.write('{0}::{0} (const {0}& orig)\n'.format(element, package, package.lower())) output.write(' : {0}(orig)\n'.format(baseClass)) output.write('{\n') output.write(' if (&orig == NULL)\n') output.write(' {\n') output.write(' throw SBMLConstructorException("Null argument to copy constructor");\n') output.write(' }\n') output.write(' else\n') output.write(' {\n') writeCopyAttributes(attrs, output, ' ', 'orig') if childrenOverwrite: output.write(' mElementName = orig.mElementName;\n') if hasChildren == True: output.write('\n // connect to child objects\n') output.write(' connectToChild();\n') output.write(' }\n') output.write('}\n\n\n') output.write('/*\n') output.write(' * Assignment for {0}.\n */\n'.format(element)) output.write('{0}&\n{0}::operator=(const {0}& rhs)\n'.format(element)) output.write('{\n') output.write(' if (&rhs == NULL)\n') output.write(' {\n') output.write(' throw SBMLConstructorException("Null argument to assignment");\n') output.write(' }\n') output.write(' else if (&rhs != this)\n') output.write(' {\n') output.write(' {0}::operator=(rhs);\n'.format(baseClass)) writeCopyAttributes(attrs, output, ' ', 'rhs') if childrenOverwrite: output.write(' mElementName = rhs.mElementName;\n') if hasChildren == True: output.write('\n // connect to child objects\n') output.write(' connectToChild();\n') output.write(' }\n') output.write(' return *this;\n') output.write('}\n\n\n') output.write('/*\n') output.write(' * Clone for {0}.\n */\n'.format(element)) output.write('{0}*\n{0}::clone () const\n'.format(element)) output.write('{\n') output.write(' return new {0}(*this);\n'.format(element)) output.write('}\n\n\n') output.write('/*\n') output.write(' * Destructor for {0}.\n */\n'.format(element)) output.write('{0}::~{0} ()\n'.format(element)) output.write('{\n') if hasMath == True: output.write(' delete mMath;\n') output.write(' mMath = NULL;\n') for i in range (0, len(attrs)): current = attrs[i]; if current['type'] == 'element' and current['name'] != 'math': output.write(' delete m{0};\n'.format(strFunctions.cap(current['name']))) output.write(' m{0} = NULL;\n'.format(strFunctions.cap(current['name']))) elif current['type'] == 'array': output.write(' if (m{0} != NULL)\n'.format(strFunctions.cap(current['name']))) output.write(' delete[] m{0};\n'.format(strFunctions.cap(current['name']))) output.write(' m{0} = NULL;\n'.format(strFunctions.cap(current['name']))) output.write('}\n\n\n')
def writeFunctions(fileOut, object): fileOut.write(' /**\n') fileOut.write(' * Returns the ListOf{0}s in this plugin object.\n'.format(object)) fileOut.write(' *\n') fileOut.write(' * @return ListOf{0}s object in this plugin object.\n'.format(object)) fileOut.write(' */\n') fileOut.write(' const ListOf{0}s* getListOf{0}s () const;\n\n\n'.format(object)) fileOut.write(' /**\n') fileOut.write(' * Returns the ListOf{0}s in this plugin object.\n'.format(object)) fileOut.write(' *\n') fileOut.write(' * @return ListOf{0}s object in this plugin object.\n'.format(object)) fileOut.write(' */\n') fileOut.write(' ListOf{0}s* getListOf{0}s ();\n\n\n'.format(object)) fileOut.write(' /**\n') fileOut.write(' * Returns the {0} object that belongs to the given index. If the \n'.format(object)) fileOut.write(' * index is invalid, NULL is returned.\n') fileOut.write(' *\n') fileOut.write(' * @param n the index number of the {0} to get\n'.format(object)) fileOut.write(' *\n') fileOut.write(' * @return the nth {0} in the ListOf{0}s\n'.format(object)) fileOut.write(' */\n') fileOut.write(' const {0}* get{0}(unsigned int n) const;\n\n\n'.format(object)) fileOut.write(' /**\n') fileOut.write(' * Returns the {0} object that belongs to the given index. If the \n'.format(object)) fileOut.write(' * index is invalid, NULL is returned.\n') fileOut.write(' *\n') fileOut.write(' * @param n the index number of the {0} to get\n'.format(object)) fileOut.write(' *\n') fileOut.write(' * @return the nth {0} in the ListOf{0}s\n'.format(object)) fileOut.write(' */\n') fileOut.write(' {0}* get{0}(unsigned int n);\n\n\n'.format(object)) fileOut.write(' /**\n') fileOut.write(' * Returns the {0} object based on its identifier.\n'.format(object)) fileOut.write(' *\n') fileOut.write(' * @param sid a string representing the id of the {0} to get\n'.format(object)) fileOut.write(' *\n') fileOut.write(' * @return {0} in the ListOf{0}s with the given id\n'.format(object)) fileOut.write(' * or NULL if no such {0} exists.\n'.format(object)) fileOut.write(' *\n') fileOut.write(' * @see get(unsigned int n)\n') fileOut.write(' * @see size()\n') fileOut.write(' */\n') fileOut.write(' const {0}* get{0}(const std::string& sid) const;\n\n\n'.format(object)) fileOut.write(' /**\n') fileOut.write(' * Returns the {0} object based on its identifier.\n'.format(object)) fileOut.write(' *\n') fileOut.write(' * @param sid a string representing the id of the {0} to get\n'.format(object)) fileOut.write(' *\n') fileOut.write(' * @return {0} in the ListOf{0}s with the given id\n'.format(object)) fileOut.write(' * or NULL if no such {0} exists.\n'.format(object)) fileOut.write(' *\n') fileOut.write(' * @see get(unsigned int n)\n') fileOut.write(' * @see size()\n') fileOut.write(' */\n') fileOut.write(' {0}* get{0}(const std::string& sid);\n\n\n'.format(object)) fileOut.write(' /**\n') fileOut.write(' * Adds a copy of the given {0} to the ListOf{0}s in this plugin object.\n'.format(object)) fileOut.write(' *\n') fileOut.write(' * @param {0} the {0} to be added.\n'.format(strFunctions.lowerFirst(object), object)) fileOut.write(' *\n') fileOut.write(' * @return integer value indicating success/failure of the\n') fileOut.write(' * function. @if clike The value is drawn from the\n') fileOut.write(' * enumeration #OperationReturnValues_t. @endif The possible values\n') fileOut.write(' * returned by this function are:\n') fileOut.write(' * @li LIBSBML_OPERATION_SUCCESS\n') fileOut.write(' */\n') fileOut.write(' int add{0} (const {0}* {1});\n\n\n'.format(object, strFunctions.lowerFirst(object))) fileOut.write(' /**\n') fileOut.write(' * Creates a new {0} object and adds it to the ListOf{0}s in this plugin object.\n'.format(object)) fileOut.write(' *\n') fileOut.write(' * @return the newly created {0} object.\n'.format(object)) fileOut.write(' */\n') fileOut.write(' {0}* create{0} ();\n\n\n'.format(object)) fileOut.write(' /**\n') fileOut.write(' * Removes the nth {0} object from this plugin object\n'.format(object)) fileOut.write(' * and returns a pointer to it.\n') fileOut.write(' *\n') fileOut.write(' * The caller owns the returned object and is responsible for\n') fileOut.write(' * deleting it.\n') fileOut.write(' *\n') fileOut.write(' * @param n the index of the {0} to remove\n'.format(object)) fileOut.write(' *\n') fileOut.write(' * @return the {0} object removed \n'.format(object)) fileOut.write(' * or NULL index was out of range.\n'.format(object)) fileOut.write(' */\n') fileOut.write(' {0}* remove{0}(unsigned int n);\n\n\n'.format(object)) fileOut.write(' /**\n') fileOut.write(' * Removes the {0} object with the given id from this plugin object\n'.format(object)) fileOut.write(' * and returns a pointer to it.\n') fileOut.write(' *\n') fileOut.write(' * The caller owns the returned object and is responsible for\n') fileOut.write(' * deleting it.\n') fileOut.write(' *\n') fileOut.write(' * @param sid a string representing the id of the {0} to remove\n'.format(object)) fileOut.write(' *\n') fileOut.write(' * @return the {0} object removed \n'.format(object)) fileOut.write(' * or NULL if no such {0} exists.\n'.format(object)) fileOut.write(' */\n') fileOut.write(' {0}* remove{0}(const std::string& sid);\n\n\n'.format(object)) fileOut.write(' /**\n') fileOut.write(' * Returns the number of {0} objects in this plugin object.\n'.format(object)) fileOut.write(' *\n') fileOut.write(' * @return the number of {0} objects in this plugin object.\n'.format(object)) fileOut.write(' */\n') fileOut.write(' unsigned int getNum{0}s () const;\n\n\n'.format(object))
def writeProtectedFunctions(output, element, package, elementDict): listOf = generalFunctions.getListOfClassName(elementDict, element) generalFunctions.writeInternalStart(output) output.write('/*\n') output.write(' * Creates a new {0} in this {1}\n'.format(element, listOf)) output.write(' */\n') output.write( 'SBase*\n{0}::createObject(XMLInputStream& stream)\n'.format(listOf)) output.write('{\n') output.write(' const std::string& name = stream.peek().getName();\n') output.write(' SBase* object = NULL;\n\n') name = strFunctions.lowerFirst(element) if elementDict.has_key('elementName'): name = elementDict['elementName'] output.write(' if (name == "{0}")\n'.format(name)) output.write(' {\n') output.write(' {0}_CREATE_NS({1}ns, getSBMLNamespaces());\n'.format( package.upper(), package.lower())) output.write(' object = new {0}({1}ns);\n'.format( element, package.lower())) output.write(' appendAndOwn(object);\n') output.write(' delete {0}ns;\n'.format(package.lower())) output.write(' }\n\n') # need to create concrete objects if elementDict.has_key('concrete'): for elem in generalFunctions.getConcretes(elementDict['root'], elementDict['concrete']): output.write(' if (name == "{0}")\n'.format( strFunctions.lowerFirst(elem['name']))) output.write(' {\n') output.write( ' {0}_CREATE_NS({1}ns, getSBMLNamespaces());\n'.format( package.upper(), package.lower())) output.write(' object = new {0}({1}ns);\n'.format( elem['element'], package.lower())) output.write(' appendAndOwn(object);\n') output.write(' delete {0}ns;\n'.format(package.lower())) output.write(' }\n\n') output.write(' return object;\n') output.write('}\n\n\n') generalFunctions.writeInternalEnd(output) generalFunctions.writeInternalStart(output) output.write('/*\n') output.write( ' * Write the namespace for the {0} package.\n'.format(package)) output.write(' */\n') output.write( 'void\n{0}::writeXMLNS(XMLOutputStream& stream) const\n'.format( listOf)) output.write('{\n') output.write(' XMLNamespaces xmlns;\n\n') output.write(' std::string prefix = getPrefix();\n\n') output.write(' if (prefix.empty())\n') output.write(' {\n') output.write(' XMLNamespaces* thisxmlns = getNamespaces();\n') output.write(' if (thisxmlns && thisxmlns->hasURI({0}'.format(package)) output.write('Extension::getXmlnsL3V1V1()))\n') output.write(' {\n') output.write( ' xmlns.add({0}Extension::getXmlnsL3V1V1(),prefix);\n'.format( package)) output.write(' }\n') output.write(' }\n\n') output.write(' stream << xmlns;\n') output.write('}\n\n\n') generalFunctions.writeInternalEnd(output)