def writeSwigHeader(fileOut, name, plugins, classes): capName = strFunctions.cap(name) fileOut.write('#ifdef USE_{0}\n\n'.format(name.upper())) fileOut.write( '#include <sbml/packages/{0}/extension/{1}Extension.h>\n'.format( name, capName)) alreadyIncluded = [] for plugin in plugins: package = name if plugin.has_key('package') and plugin['package'] != None: package = plugin['package'] capPackageName = strFunctions.cap(package) if package != name and alreadyIncluded.count(package) == 0: alreadyIncluded.append(package) fileOut.write( '#include <sbml/packages/{0}/extension/{1}Extension.h>\n'. format(package, capPackageName)) fileOut.write( '#include <sbml/packages/{0}/common/{1}ExtensionTypes.h>\n'. format(package, capPackageName)) fileOut.write( '#include <sbml/packages/{0}/extension/{1}{2}Plugin.h>\n'.format( name, capName, plugin['sbase'])) fileOut.write( '#include <sbml/packages/{0}/common/{1}ExtensionTypes.h>\n'.format( name, capName)) for clazz in classes: if clazz['typecode'] != 'HACK': fileOut.write('#include <sbml/packages/{0}/sbml/{1}.h>\n'.format( name, clazz['name'])) fileOut.write('\n') fileOut.write('#endif // USE_{0} \n\n'.format(name.upper()))
def writeGetFunction(attrib, output, element): att = generalFunctions.parseAttributeForC(attrib) attName = att[0] capAttName = att[1] attType = att[2] if att[3] == 'const char *': attTypeCode = 'char *' else: attTypeCode = att[3] num = att[4] if attrib['type'] != 'element' and attrib['type'] != 'lo_element': output.write('LIBSEDML_EXTERN\n') output.write('{0}\n'.format(attTypeCode)) output.write('{0}_get{1}'.format(element, capAttName)) output.write('({0}_t * {1});\n\n\n'.format(element, strFunctions.objAbbrev(element))) elif attrib['type'] == 'element': if attrib['name'] == 'Math' or attrib['name'] == 'math': output.write('LIBSEDML_EXTERN\n') output.write('ASTNode_t*\n') output.write('{0}_getMath'.format(element)) output.write('({0}_t * {1});\n\n\n'.format(element, strFunctions.objAbbrev(element))) else: output.write('LIBSEDML_EXTERN\n') output.write('{0}_t*\n'.format(strFunctions.cap(attrib['element']))) output.write('{0}_get{1}'.format(element, capAttName)) output.write('({0}_t * {1});\n\n\n'.format(element, strFunctions.objAbbrev(element))) output.write('LIBSEDML_EXTERN\n') output.write('{0}_t*\n'.format(strFunctions.cap(attrib['element']))) output.write('{0}_create{1}'.format(element, capAttName)) output.write('({0}_t * {1});\n\n\n'.format(element, strFunctions.objAbbrev(element)))
def writeCreateObject(outFile, element, sbmltypecode, attribs, isSedListOf, hasChildren=False, hasMath=False,baseClass='SedBase'): if (isSedListOf == True or hasChildren == False) and baseClass == 'SedBase': return; outFile.write('/**\n') outFile.write(' * return the SEDML object corresponding to next XMLToken.\n') outFile.write(' */\n') outFile.write('SedBase*\n{0}::createObject(XMLInputStream& stream)\n'.format(element)) outFile.write('{\n') if baseClass == 'SedBase': outFile.write(' SedBase* object = NULL;\n\n') else: outFile.write(' SedBase* object = {0}::createObject(stream);\n\n'.format(baseClass)) if hasChildren or hasMath: outFile.write(' const string& name = stream.peek().getName();\n\n') for i in range (0, len(attribs)): current = attribs[i] if current.has_key('lo_elementName'): outFile.write(' if (name == "{0}")\n'.format(current['lo_elementName'])) outFile.write(' {\n') outFile.write(' object = &m{0};\n'.format(strFunctions.capp(current['name']))) outFile.write(' }\n\n') elif current['type'] == 'lo_element': outFile.write(' if (name == "listOf{0}")\n'.format(strFunctions.capp(current['name']))) outFile.write(' {\n') outFile.write(' object = &m{0};\n'.format(strFunctions.capp(current['name']))) outFile.write(' }\n\n') elif current['type'] == 'element' and (current['name'] !='Math' and current['name'] != 'math'): outFile.write(' if (name == "{0}")\n'.format(current['name'])) outFile.write(' {\n') outFile.write(' m{0}= new {1}();\n'.format(strFunctions.cap(current['name']), current['element'])) outFile.write(' object = m{0};\n'.format(strFunctions.cap(current['name']))) outFile.write(' }\n\n') outFile.write(' connectToChild();\n\n') outFile.write(' return object;\n') outFile.write('}\n\n\n')
def writeWriteElementsCPPCode(outFile, element, attributes, hasChildren=False, hasMath=False, baseClass='SedBase'): writeInternalStart(outFile) outFile.write('/*\n') outFile.write(' * write contained elements\n') outFile.write(' */\n') outFile.write('void\n{0}::writeElements (XMLOutputStream& stream) const\n'.format(element)) outFile.write('{\n') outFile.write('\t{0}::writeElements(stream);\n'.format(baseClass)) if hasChildren == True: for i in range(0, len(attributes)): if attributes[i]['type'] == 'element' and (attributes[i]['name'] != 'Math' and attributes[i]['name'] != 'math'): outFile.write('\tif (isSet{0}() == true)\n'.format(strFunctions.cap(attributes[i]['name']))) outFile.write('\t{\n\t\t') outFile.write('m{0}->write(stream);'.format(strFunctions.cap(attributes[i]['name']))) outFile.write('\n\t}\n') if attributes[i]['type'] == 'lo_element': outFile.write('\tif (getNum{0}s() > 0)\n'.format(strFunctions.cap(attributes[i]['name']))) outFile.write('\t{\n\t\t') outFile.write('m{0}.write(stream);'.format(strFunctions.cap(attributes[i]['name']))) outFile.write('\n\t}\n') if hasMath == True: for i in range(0, len(attributes)): if attributes[i]['type'] == 'element' and attributes[i]['name'] == 'Math' or attributes[i]['name'] == 'math': outFile.write('\tif (isSet{0}() == true)\n'.format('Math')) outFile.write('\t{\n\t\twriteMathML(getMath(), stream, NULL);\n\t}\n') outFile.write('}\n\n\n') writeInternalEnd(outFile)
def writeCopyAttributes(attrs, output, tabs, name): for i in range(0, len(attrs)): attName = strFunctions.cap(attrs[i]['name']) atttype = attrs[i]['type'] if atttype == 'array': output.write('{0}m{1} = NULL;\n'.format(tabs, attName, name)) output.write('{0}set{1}({2}.m{1}, {2}.m{1}Length);\n'.format(tabs, attName, name)) elif atttype != 'lo_element' and atttype != 'inline_lo_element': if atttype != 'element': output.write('{0}m{1} = {2}.m{1};\n'.format(tabs, attName, name)) else: output.write('{0}if ({2}.m{1} != NULL)\n'.format(tabs, strFunctions.cap(attrs[i]['name']), name)) output.write('{0}'.format(tabs)) output.write('{\n') if attrs[i]['name'] != 'math': output.write('{0} m{1} = {2}.m{1}->clone();\n'.format(tabs, strFunctions.cap(attrs[i]['name']), name)) else: output.write('{0} m{1} = {2}.m{1}->deepCopy();\n'.format(tabs, strFunctions.cap(attrs[i]['name']), name)) output.write('{0}'.format(tabs)) output.write('}\n') output.write('{0}else\n'.format(tabs)) output.write('{0}'.format(tabs)) output.write('{\n') output.write('{0} m{1} = NULL;\n'.format(tabs, strFunctions.cap(attrs[i]['name']))) output.write('{0}'.format(tabs)) output.write('}\n') else: if attName.endswith('x'): output.write('{0}m{1}es = {2}.m{1}es;\n'.format(tabs, attName, name)) elif attName.endswith('s'): output.write('{0}m{1} = {2}.m{1};\n'.format(tabs, attName, name)) else: output.write('{0}m{1}s = {2}.m{1}s;\n'.format(tabs, attName, name)) if atttype == 'double' or atttype == 'int' or atttype == 'uint' or atttype == 'bool': output.write('{0}mIsSet{1} = {2}.mIsSet{1};\n'.format(tabs, attName, name))
def writeLocal(fileOut, name, classes): capName = name.upper() fileOut.write('#ifdef USE_{0}\n\n'.format(capName)) 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 = strFunctions.listOfName(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(out) {0}*\n'.format(classes[i]['name'])) fileOut.write('{\n') fileOut.write(' $result = SWIG_NewPointerObj($1, GetDowncastSwigTypeForPackage($1, "{0}"), $owner | %newpointer_flags);\n'.format(name)) fileOut.write('}\n') fileOut.write('\n') fileOut.write('\n') fileOut.write('#endif // USE_{0} \n\n'.format(capName))
def writeCreateObject(outFile, element, sbmltypecode, attribs, isSedListOf, hasChildren=False, hasMath=False,baseClass='SedBase'): if (isSedListOf == True or hasChildren == False) and baseClass == 'SedBase': return; outFile.write('/**\n') outFile.write(' * return the SEDML object corresponding to next XMLToken.\n') outFile.write(' */\n') outFile.write('SedBase*\n{0}::createObject(XMLInputStream& stream)\n'.format(element)) outFile.write('{\n') if baseClass == 'SedBase': outFile.write('\tSedBase* object = NULL;\n\n') else: outFile.write('\tSedBase* object = {0}::createObject(stream);\n\n'.format(baseClass)) if hasChildren or hasMath: outFile.write('\tconst string& name = stream.peek().getName();\n\n') for i in range (0, len(attribs)): current = attribs[i] if current.has_key('lo_elementName'): outFile.write('\tif (name == "{0}")\n'.format(current['lo_elementName'])) outFile.write('\t{\n') outFile.write('\t\tobject = &m{0};\n'.format(strFunctions.capp(current['name']))) outFile.write('\t}\n\n') elif current['type'] == 'lo_element': outFile.write('\tif (name == "listOf{0}")\n'.format(strFunctions.capp(current['name']))) outFile.write('\t{\n') outFile.write('\t\tobject = &m{0};\n'.format(strFunctions.capp(current['name']))) outFile.write('\t}\n\n') elif current['type'] == 'element' and (current['name'] !='Math' and current['name'] != 'math'): outFile.write('\tif (name == "{0}")\n'.format(current['name'])) outFile.write('\t{\n') outFile.write('\t\tm{0}= new {1}();\n'.format(strFunctions.cap(current['name']), current['element'])) outFile.write('\t\tobject = m{0};\n'.format(strFunctions.cap(current['name']))) outFile.write('\t}\n\n') outFile.write('\tconnectToChild();\n\n') outFile.write('\treturn object;\n') outFile.write('}\n\n\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 parseAttribute(attrib): attName = attrib['name'] capAttName = strFunctions.cap(attName) reqd = attrib['reqd'] if attrib['type'] == 'SId': attType = 'string' attTypeCode = 'std::string&' num = False elif attrib['type'] == 'SIdRef': attType = 'string' attTypeCode = 'std::string&' num = False elif attrib['type'] == 'UnitSIdRef': attType = 'string' attTypeCode = 'std::string&' num = False elif attrib['type'] == 'UnitSId': attType = 'string' attTypeCode = 'std::string&' num = False elif attrib['type'] == 'string': attType = 'string' attTypeCode = 'std::string&' num = False elif attrib['type'] == 'double': attType = 'double' attTypeCode = 'double' num = True elif attrib['type'] == 'int': attType = 'integer' attTypeCode = 'int' num = True elif attrib['type'] == 'uint': attType = 'unsigned integer' attTypeCode = 'unsigned int' num = True elif attrib['type'] == 'bool': attType = 'boolean' attTypeCode = 'bool' num = False elif attrib['type'] == 'element': attType = 'element' if attrib['name'] == 'math' or attrib['name'] == 'Math': attTypeCode = 'ASTNode*' else: #attTypeCode = 'element-not-done' if attrib.has_key('element'): attTypeCode = '{0}*'.format(attrib['element']) else: attTypeCode = '{0}*'.format(strFunctions.cap(attrib['name'])) num = False elif attrib['type'] == 'lo_element': attType = 'lo_element' attTypeCode = attrib['element'] num = False else: attType = 'FIX ME' attTypeCode = 'FIX ME' num = False return [attName, capAttName, attType, attTypeCode, num, reqd]
def writeIncludes(fileOut, pkg, element, members, attribs): fileOut.write('\n\n') fileOut.write('#ifndef {0}_H__\n'.format(element)) fileOut.write('#define {0}_H__\n'.format(element)) fileOut.write('\n\n') fileOut.write('#include <sbml/common/extern.h>\n') fileOut.write('\n\n') fileOut.write('#ifdef __cplusplus\n') fileOut.write('\n\n') fileOut.write('#include <sbml/extension/SBasePlugin.h>\n') for i in range(0, len(members)): mem = members[i] fileOut.write('#include <sbml/packages/{0}/sbml/{1}.h>\n'.format( pkg.lower(), mem['name'])) if len(members) == 0: fileOut.write( '#include <sbml/packages/{0}/extension/{1}Extension.h>\n'.format( pkg.lower(), pkg)) for i in range(0, len(attribs)): if (attribs[i]['type'] == 'element' or attribs[i]['type'] == 'lo_element' or attribs[i]['type'] == 'inline_lo_element') and attribs[i]['name'] != 'math': if (attribs[i]['element'] == None): fileOut.write( '#include <sbml/packages/{0}/sbml/{1}.h>\n'.format( pkg.lower(), strFunctions.cap(attribs[i]['name']))) else: fileOut.write( '#include <sbml/packages/{0}/sbml/{1}.h>\n'.format( pkg.lower(), strFunctions.cap(attribs[i]['element']))) fileOut.write('\n\n') fileOut.write('LIBSBML_CPP_NAMESPACE_BEGIN\n') fileOut.write('\n\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 writeLocal(fileOut, name, classes): capName = name.upper() fileOut.write('#ifdef USE_{0}\n\n'.format(capName)) 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 = strFunctions.listOfName(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(out) {0}*\n'.format(classes[i]['name'])) fileOut.write('{\n') fileOut.write( ' $result = SWIG_NewPointerObj($1, GetDowncastSwigTypeForPackage($1, "{0}"), $owner | %newpointer_flags);\n' .format(name)) fileOut.write('}\n') fileOut.write('\n') fileOut.write('\n') fileOut.write('#endif // USE_{0} \n\n'.format(capName))
def writeCopyAttributes(attrs, output, tabs, name): for i in range(0, len(attrs)): attName = strFunctions.cap(attrs[i]['name']) atttype = attrs[i]['type'] if atttype == 'element' and attName == 'Math': output.write('{0}m{1} = {2}.m{1} != NULL ? {2}.m{1}->deepCopy() : NULL;\n'.format(tabs, strFunctions.cap(attrs[i]['name']), name)) else: output.write('{0}m{1} = {2}.m{1};\n'.format(tabs, strFunctions.cap(attrs[i]['name']), name)) if atttype == 'double' or atttype == 'int' or atttype == 'uint' or atttype == 'bool': output.write('{0}mIsSet{1} = {2}.mIsSet{1};\n'.format(tabs, strFunctions.cap(attrs[i]['name']), name))
def writeAtt(atttype, name, output, constType, pkg): if atttype == 'SId' or atttype == 'SIdRef' or atttype == 'UnitSId' or atttype == 'UnitSIdRef' or atttype == 'string': output.write('\t, m{0} ("")\n'.format(strFunctions.cap(name))) elif atttype == 'element': output.write('\t, m{0} (NULL)\n'.format(strFunctions.cap(name))) elif atttype == 'lo_element': output.write('\t, m{0} ('.format(strFunctions.cap(name))) if constType == 0: output.write(')\n') elif constType == 1: output.write('level, version)\n') elif constType == 2: output.write('{0}ns)\n'.format(pkg)) elif atttype == 'double': output.write('\t, m{0} (numeric_limits<double>::quiet_NaN())\n'.format( strFunctions.cap(name))) output.write('\t, mIsSet{0} (false)\n'.format(strFunctions.cap(name))) elif atttype == 'int' or atttype == 'uint': output.write('\t, m{0} (SEDML_INT_MAX)\n'.format( strFunctions.cap(name))) output.write('\t, mIsSet{0} (false)\n'.format(strFunctions.cap(name))) elif atttype == 'bool': output.write('\t, m{0} (false)\n'.format(strFunctions.cap(name))) output.write('\t, mIsSet{0} (false)\n'.format(strFunctions.cap(name))) else: output.write('\tFIX ME {0};\n'.format(name))
def writeListOfSubElements(attrib, output, element): loname = generalFunctions.writeListOf(strFunctions.cap(attrib['name'])) output.write('LIBSEDML_EXTERN\n') output.write('int\n') output.write('{0}_add{1}({0}_t * {2}, '.format( element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write('{0}_t * {1});\n\n\n'.format( attrib['element'], strFunctions.objAbbrev(attrib['element']))) if attrib.has_key('abstract') == False or (attrib.has_key('abstract') and attrib['abstract'] == False): output.write('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(attrib['element'])) output.write('{0}_create{1}({0}_t * {2}'.format( element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write(');\n\n\n') elif attrib.has_key('concrete'): for elem in attrib['concrete']: output.write('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(elem['element'])) output.write('{0}_create{1}({0}_t * {2}'.format( element, strFunctions.cap(elem['name']), strFunctions.objAbbrev(element))) output.write(');\n\n\n') output.write('LIBSEDML_EXTERN\n') output.write('SedListOf_t *\n') output.write('{0}_get{1}({0}_t * {2})'.format( element, loname, strFunctions.objAbbrev(element))) output.write(';\n\n\n') output.write('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(attrib['element'])) output.write('{0}_get{1}({0}_t * {2}, '.format( element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write('unsigned int n);\n\n\n') output.write('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(attrib['element'])) output.write('{0}_get{1}ById({0}_t * {2}, '.format( element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write('const char * sid);\n\n\n') output.write('LIBSEDML_EXTERN\n') output.write('unsigned int\n') output.write('{0}_getNum{1}s({0}_t * {2}'.format( element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write(');\n\n\n') output.write('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(attrib['element'])) output.write('{0}_remove{1}({0}_t * {2}, '.format( element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write('unsigned int n);\n\n\n') output.write('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(attrib['element'])) output.write('{0}_remove{1}ById({0}_t * {2}, '.format( element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write('const char * sid);\n\n\n')
def writeReadOtherXMLCPPCode(outFile, element, hasMath = True, attribs = None, baseClass='SedBase'): writeInternalStart(outFile) outFile.write('bool\n{0}::readOtherXML (XMLInputStream& stream)\n'.format(element)) outFile.write('{\n') outFile.write(' bool read = false;\n') outFile.write(' const string& name = stream.peek().getName();\n\n') if hasMath == True: outFile.write(' if (name == "math")\n {\n') outFile.write(' const XMLToken elem = stream.peek();\n') outFile.write(' const std::string prefix = checkMathMLNamespace(elem);\n\n') #outFile.write(' if (stream.getSedNamespaces() == NULL)\n {\n') #outFile.write(' stream.setSedNamespaces(new SedNamespaces(getLevel(), getVersion()));\n }\n\n') outFile.write(' delete mMath;\n') outFile.write(' mMath = readMathML(stream, prefix);\n') #outFile.write(' if (mMath != NULL)\n {\n mMath->setParentSEDMLObject(this);\n }\n') outFile.write(' read = true;\n }\n\n') elif containsType(attribs, 'XMLNode*'): node = getByType(attribs, 'XMLNode*') outFile.write(' if (name == "{0}")\n'.format(node['name'])) outFile.write(' {\n') outFile.write(' const XMLToken& token = stream.next();\n') outFile.write(' stream.skipText();\n') outFile.write(' m{0} = new XMLNode(stream);\n'.format(strFunctions.cap(node['name']))) outFile.write(' stream.skipPastEnd(token);\n') outFile.write(' read = true;\n }\n\n') elif containsType(attribs, 'DimensionDescription*'): node = getByType(attribs, 'DimensionDescription*') outFile.write(' if (name == "{0}")\n'.format(node['name'])) outFile.write(' {\n') outFile.write(' const XMLToken& token = stream.next();\n') outFile.write(' m{0} = new DimensionDescription();\n'.format(strFunctions.cap(node['name']))) outFile.write(' m{0}->read(stream);\n'.format(strFunctions.cap(node['name']))) outFile.write(' stream.skipPastEnd(token);\n') outFile.write(' read = true;\n }\n\n') elif containsType(attribs, 'std::vector<double>'): elem = getByType(attribs, 'std::vector<double>') outFile.write(' while (stream.peek().getName() == "{0}")\n'.format(elem['name'])) outFile.write(' {\n') outFile.write(' stream.next(); // consume start\n') outFile.write(' stringstream text;\n') outFile.write(' while(stream.isGood() && stream.peek().isText())\n') outFile.write(' text << stream.next().getCharacters();\n') outFile.write(' double value; text >> value;\n') outFile.write(' if (!text.fail())\n') outFile.write(' m{0}.push_back(value);\n'.format(strFunctions.capp(elem['name']))) outFile.write(' stream.next(); // consume end\n') outFile.write(' read = true;\n') outFile.write(' }\n') outFile.write(' if ({0}::readOtherXML(stream))\n'.format(baseClass)) outFile.write(' {\n read = true;\n }\n') outFile.write(' return read;\n') outFile.write('}\n\n\n') writeInternalEnd(outFile)
def writeCopyAttributes(attrs, output, tabs, name): for i in range(0, len(attrs)): attName = strFunctions.cap(attrs[i]['name']) atttype = attrs[i]['type'] if atttype == 'element' and attName == 'Math': output.write('{0}m{1} = {2}.m{1} != NULL ? {2}.m{1}->deepCopy() : NULL;\n'.format(tabs, strFunctions.cap(attrs[i]['name']), name)) elif atttype == 'XMLNode*' or atttype == 'DimensionDescription*': output.write('{0}m{1} = {2}.m{1} != NULL ? {2}.m{1}->clone() : NULL;\n'.format(tabs, strFunctions.cap(attrs[i]['name']), name)) else: output.write('{0}m{1} = {2}.m{1};\n'.format(tabs, strFunctions.capp(attrs[i]['name'], atttype == 'lo_element' or atttype == 'std::vector<double>'), name)) if atttype == 'double' or atttype == 'int' or atttype == 'uint' or atttype == 'bool': output.write('{0}mIsSet{1} = {2}.mIsSet{1};\n'.format(tabs, strFunctions.cap(attrs[i]['name']), name))
def writeJavaNS(fileOut, name): capName = name.upper() fileOut.write('/**\n') fileOut.write(' * casting to most specific SBMLNamespaces object\n */\n\n') fileOut.write('#ifdef USE_{0}\n'.format(capName)) fileOut.write('%pragma(java) modulecode =\n') fileOut.write('%{\n') fileOut.write(' if (ns.hasURI({0}Extension.getXmlnsL3V1V1()))\n'.format(strFunctions.cap(name))) fileOut.write(' {\n') fileOut.write(' return new {0}PkgNamespaces(cPtr, owner);\n'.format(strFunctions.cap(name))) fileOut.write(' }\n') fileOut.write('%}\n') fileOut.write('#endif /* USE_{0} */\n\n'.format(capName))
def writeCopyAttributes(attrs, output, tabs, name): for i in range(0, len(attrs)): attName = strFunctions.cap(attrs[i]['name']) atttype = attrs[i]['type'] if atttype == 'element' and attName == 'Math': output.write( '{0}m{1} = {2}.m{1} != NULL ? {2}.m{1}->deepCopy() : NULL;\n'. format(tabs, strFunctions.cap(attrs[i]['name']), name)) else: output.write('{0}m{1} = {2}.m{1};\n'.format( tabs, strFunctions.cap(attrs[i]['name']), name)) if atttype == 'double' or atttype == 'int' or atttype == 'uint' or atttype == 'bool': output.write('{0}mIsSet{1} = {2}.mIsSet{1};\n'.format( tabs, strFunctions.cap(attrs[i]['name']), name))
def writeAtt(atttype, name, output, constType, pkg): if atttype == 'SId' or atttype == 'SIdRef' or atttype == 'UnitSId' or atttype == 'UnitSIdRef' or atttype == 'string': output.write('\t, m{0} ("")\n'.format(strFunctions.cap(name))) elif atttype == 'element' or atttype == 'XMLNode*': output.write('\t, m{0} (NULL)\n'.format(strFunctions.cap(name))) elif atttype == 'lo_element': output.write('\t, m{0} ('.format(strFunctions.capp(name))) if constType == 0: output.write(')\n') elif constType == 1: output.write('level, version)\n') elif constType == 2: output.write('{0}ns)\n'.format(pkg)) elif atttype == 'double': output.write('\t, m{0} (numeric_limits<double>::quiet_NaN())\n'.format(strFunctions.cap(name))) output.write('\t, mIsSet{0} (false)\n'.format(strFunctions.cap(name))) elif atttype == 'int' or atttype == 'uint': output.write('\t, m{0} (SEDML_INT_MAX)\n'.format(strFunctions.cap(name))) output.write('\t, mIsSet{0} (false)\n'.format(strFunctions.cap(name))) elif atttype == 'bool': output.write('\t, m{0} (false)\n'.format(strFunctions.cap(name))) output.write('\t, mIsSet{0} (false)\n'.format(strFunctions.cap(name))) elif atttype == 'std::vector<double>': output.write('\t, m{0} ()\n'.format(strFunctions.capp(name))) else: output.write('\tFIX ME {0};\n'.format(name))
def writeJavaNS(fileOut, name): capName = name.upper() fileOut.write('/**\n') fileOut.write(' * casting to most specific SBMLNamespaces object\n */\n\n') fileOut.write('#ifdef USE_{0}\n'.format(capName)) fileOut.write('%pragma(java) modulecode =\n') fileOut.write('%{\n') fileOut.write(' if (ns.hasURI({0}Extension.getXmlnsL3V1V1()))\n'.format( strFunctions.cap(name))) fileOut.write(' {\n') fileOut.write(' return new {0}PkgNamespaces(cPtr, owner);\n'.format( strFunctions.cap(name))) fileOut.write(' }\n') fileOut.write('%}\n') fileOut.write('#endif /* USE_{0} */\n\n'.format(capName))
def writeListOfSubFunctions(attrib, output, element, elementDict): loname = generalFunctions.writeListOf(strFunctions.cap(attrib['name'])) output.write(' /**\n') output.write(' * Returns the \"{0}\"'.format(loname)) output.write(' in this {0} object.\n'.format(element)) output.write(' *\n') output.write(' * @return the \"{0}\"'.format(loname)) output.write(' attribute of this {0}.\n'.format(element)) output.write(' */\n') output.write(' const {0}*'.format(loname)) output.write(' getListOf{0}s() const;\n\n\n'.format(strFunctions.cap(attrib['name']))) writeListOfHeader.writeGetFunctions(output, strFunctions.cap(attrib['name']), attrib['element'], True, element) output.write(' /**\n') output.write(' * Adds a copy the given \"{0}\" to this {1}.\n'.format(attrib['element'], element)) output.write(' *\n') output.write(' * @param {0}; the {1} object to add\n'.format(strFunctions.objAbbrev(attrib['element']), attrib['element'])) output.write(' *\n') output.write(' * @return integer value indicating success/failure of the\n') output.write(' * function. @if clike The value is drawn from the\n') output.write(' * enumeration #OperationReturnValues_t. @endif The possible values\n') output.write(' * returned by this function are:\n') output.write(' * @li LIBSEDML_OPERATION_SUCCESS\n') output.write(' * @li LIBSEDML_INVALID_ATTRIBUTE_VALUE\n') output.write(' */\n') output.write(' int add{0}(const {1}* {2});\n\n\n'.format(strFunctions.cap(attrib['name']), attrib['element'], strFunctions.objAbbrev(attrib['element']))) output.write(' /**\n') output.write(' * Get the number of {0} objects in this {1}.\n'.format(attrib['element'], element)) output.write(' *\n') output.write(' * @return the number of {0} objects in this {1}\n'.format(attrib['element'], element)) output.write(' */\n') output.write(' unsigned int getNum{0}s() const;\n\n\n'.format(strFunctions.cap(attrib['name']))) if attrib.has_key('abstract') == False or (attrib.has_key('abstract') and attrib['abstract'] == False): output.write(' /**\n') output.write(' * Creates a new {0} object, adds it to this {1}s\n'.format(attrib['element'], element)) output.write(' * {0} and returns the {1} object created.\n'.format(loname, attrib['element'])) output.write(' *\n') output.write(' * @return a new {0} object instance\n'.format(attrib['element'])) output.write(' *\n') output.write(' * @see add{0}(const {1}* {2})\n'.format(strFunctions.cap(attrib['name']), attrib['element'], strFunctions.objAbbrev(attrib['element']))) output.write(' */\n') output.write(' {0}* create{1}();\n\n\n'.format(attrib['element'], strFunctions.cap(attrib['name']))) elif attrib.has_key('concrete'): for elem in attrib['concrete']: output.write(' /**\n') output.write(' * Creates a new {0} object, adds it to this {1}s\n'.format(elem['element'], element)) output.write(' * {0} and returns the {1} object created.\n'.format(loname, elem['element'])) output.write(' *\n') output.write(' * @return a new {0} object instance\n'.format(elem['element'])) output.write(' *\n') output.write(' * @see add{0}(const {0}* {1})\n'.format(attrib['element'], strFunctions.objAbbrev(attrib['element']))) output.write(' */\n') output.write(' {0}* create{1}();\n\n\n'.format(elem['element'], strFunctions.cap(elem['name']))) writeListOfHeader.writeRemoveFunctions(output, strFunctions.cap(attrib['name']), attrib['element'], True, element)
def writeUnsetFunction(attrib, output, element): attName = attrib['name'] capAttName = strFunctions.cap(attName) if attrib['type'] == 'lo_element' or attrib['type'] == 'inline_lo_element': return elif attrib['type'] == 'element': output.write(' /**\n') output.write(' * Unsets the \"{0}\"'.format(attName)) output.write(' element of this {0}.\n'.format(element)) output.write(' *\n') output.write(' * @return integer value indicating success/failure of the\n') output.write(' * function. @if clike The value is drawn from the\n') output.write(' * enumeration #OperationReturnValues_t. @endif The possible values\n') output.write(' * returned by this function are:\n') output.write(' * @li LIBSBML_OPERATION_SUCCESS\n') output.write(' * @li LIBSBML_OPERATION_FAILED\n') output.write(' */\n') output.write(' virtual int unset{0}();\n\n\n'.format(capAttName)) else: output.write(' /**\n') output.write(' * Unsets the value of the \"{0}\"'.format(attName)) output.write(' attribute of this {0}.\n'.format(element)) output.write(' *\n') output.write(' * @return integer value indicating success/failure of the\n') output.write(' * function. @if clike The value is drawn from the\n') output.write(' * enumeration #OperationReturnValues_t. @endif The possible values\n') output.write(' * returned by this function are:\n') output.write(' * @li LIBSBML_OPERATION_SUCCESS\n') output.write(' * @li LIBSBML_OPERATION_FAILED\n') output.write(' */\n') output.write(' virtual int unset{0}();\n\n\n'.format(capAttName))
def writeConnectToParent(outFile, element, sbmltypecode, attribs, isSedListOf, hasChildren=False, hasMath=False, baseClass='SedBase'): #print 'isSedListOf={0} hasChildren={1} hasMath={2}'.format(isSedListOf, hasChildren, hasMath) if isSedListOf or hasChildren == False: return outFile.write('/*\n') outFile.write( ' * Read values from the given XMLAttributes set into their specific fields.\n' ) outFile.write(' */\n') outFile.write('void\n{0}::connectToChild ()\n'.format(element)) outFile.write('{\n') outFile.write('\t{0}::connectToChild();\n\n'.format(baseClass)) for i in range(0, len(attribs)): current = attribs[i] if current['type'] == 'lo_element': outFile.write('\tm{0}.connectToParent(this);\n'.format( strFunctions.cap(current['name']))) outFile.write('}\n\n\n')
def writeCommonCPPCode(outFile, element, sbmltypecode, attribs, isSedListOf, hasChildren=False, hasMath=False, elementDict=None, baseClass='SedBase'): type = elementDict['name'] name = elementDict['name'] if elementDict.has_key('elementName'): name = strFunctions.cap(elementDict['elementName']) if elementDict.has_key('element'): type = elementDict['element'] if isSedListOf == True: element = writeListOf(name) writeGetElementNameCPPCode(outFile, element, isSedListOf, elementDict) if hasChildren or baseClass != 'SedBase': writeCreateObject(outFile, element, sbmltypecode, attribs, isSedListOf, hasChildren, hasMath, baseClass) writeConnectToParent(outFile, element, sbmltypecode, attribs, isSedListOf, hasChildren, hasMath, baseClass) writeGetTypeCodeCPPCode(outFile, element, sbmltypecode, isSedListOf) if isSedListOf == False: writeHasReqdAttribCPPCode(outFile, element, attribs, baseClass) if hasChildren == True or hasMath == True: writeHasReqdElementsCPPCode(outFile, element, attribs, baseClass)
def writeProtectedFunctions(output, element, package, name, elementDict): type = elementDict['name'] elName = elementDict['name'] if elementDict.has_key('elementName'): elName = strFunctions.cap(elementDict['elementName']) if elementDict.has_key('element'): type = elementDict['element'] listOf = generalFunctions.writeListOf(elName) generalFunctions.writeInternalStart(output) output.write('/*\n') output.write(' * Creates a new {0} in this {1}\n'.format(element, listOf)) output.write(' */\n') output.write( 'SedBase*\n{0}::createObject(XMLInputStream& stream)\n'.format(listOf)) output.write('{\n') output.write('\tconst std::string& name = stream.peek().getName();\n') output.write('\tSedBase* object = NULL;\n\n') if elementDict == None or elementDict.has_key('abstract') == False or ( elementDict.has_key('abstract') and elementDict['abstract'] == False): output.write('\tif (name == "{0}")\n'.format(name)) output.write('\t{\n') output.write( '\t\tobject = new {0}(getSedNamespaces());\n'.format(element)) output.write('\t\tappendAndOwn(object);\n\t}\n\n') elif elementDict != None and elementDict.has_key('concrete'): for elem in elementDict['concrete']: output.write('\tif (name == "{0}")\n'.format(elem['name'])) output.write('\t{\n') output.write('\t\tobject = new {0}(getSedNamespaces());\n'.format( elem['element'])) output.write('\t\tappendAndOwn(object);\n\t}\n\n') output.write('\treturn 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('\tXMLNamespaces xmlns;\n\n') output.write('\tstd::string prefix = getPrefix();\n\n') output.write('\tif (prefix.empty())\n') output.write('\t{\n') output.write( '\t\tif (getNamespaces() != NULL && !getNamespaces()->hasURI(SEDML_XMLNS_L1))\n' ) output.write('\t\t{\n') output.write('\t\t\txmlns.add(SEDML_XMLNS_L1,prefix);\n') output.write('\t\t}\n') output.write('\t}\n\n') output.write('\tstream << xmlns;\n') output.write('}\n\n\n') generalFunctions.writeInternalEnd(output)
def writeSetDocCPPCode(outFile, element,attribs, baseClass='SedBase'): writeInternalStart(outFile) outFile.write('/*\n') outFile.write(' * Sets the parent SedDocument.\n') outFile.write(' */\n') outFile.write('void\n{0}::setSedDocument (SedDocument* d)\n'.format(element)) outFile.write('{\n') outFile.write('\t{0}::setSedDocument(d);\n'.format(baseClass)) for i in range (0, len(attribs)): if attribs[i]['type'] == 'lo_element' or ( attribs[i]['type'] == 'element' and attribs[i]['name'] != 'math'): if attribs[i]['reqd'] == True or attribs[i]['type'] == 'lo_element': outFile.write('\tm{0}.setSedDocument(d);\n'.format(strFunctions.capp(attribs[i]['name'], attribs[i]['type'] == 'lo_element'))) else: outFile.write('\tif (m{0} != NULL)\n'.format(strFunctions.cap(attribs[i]['name']))) outFile.write('\t\tm{0}->setSedDocument(d);\n'.format(strFunctions.cap(attribs[i]['name']))) outFile.write('}\n\n\n') writeInternalEnd(outFile)
def writeSetDocCPPCode(outFile, element,attribs, baseClass='SedBase'): writeInternalStart(outFile) outFile.write('/*\n') outFile.write(' * Sets the parent SedDocument.\n') outFile.write(' */\n') outFile.write('void\n{0}::setSedDocument (SedDocument* d)\n'.format(element)) outFile.write('{\n') outFile.write(' {0}::setSedDocument(d);\n'.format(baseClass)) for i in range (0, len(attribs)): if attribs[i]['type'] == 'lo_element' or ( attribs[i]['type'] == 'element' and attribs[i]['name'] != 'math'): if attribs[i]['reqd'] == True or attribs[i]['type'] == 'lo_element': outFile.write(' m{0}.setSedDocument(d);\n'.format(strFunctions.capp(attribs[i]['name'], attribs[i]['type'] == 'lo_element'))) else: outFile.write(' if (m{0} != NULL)\n'.format(strFunctions.cap(attribs[i]['name']))) outFile.write(' m{0}->setSedDocument(d);\n'.format(strFunctions.cap(attribs[i]['name']))) outFile.write('}\n\n\n') writeInternalEnd(outFile)
def createHeader(element, header): type = element['name'] name = element['name'] if element.has_key('elementName'): name = strFunctions.cap(element['elementName']) if element.has_key('element'): type = element['element'] writeClass(header, name, type, element['package'], element)
def writeExt(fileOut, name): capName = name.upper() fileOut.write('#ifdef USE_{0}\n'.format(capName)) fileOut.write('if (pkgName == "{0}")\n'.format(name)) fileOut.write('{\n') fileOut.write(' return SWIGTYPE_p_{0}Extension;\n'.format(strFunctions.cap(name))) fileOut.write('}\n') fileOut.write('#endif // USE_{0} \n\n'.format(capName))
def addCMakeFilename(outFile, filename, element): outFile.write( '#################################################################################\n' ) outFile.write('#\n') outFile.write('# @file: {0}\n'.format(filename)) outFile.write('# @brief: CMake configuration for L3 {0} package\n'.format( strFunctions.cap(element))) outFile.write('# @author: Generated by autocreate code\n#\n')
def writeConnectToParent(outFile, element, sbmltypecode, attribs, isSedListOf, hasChildren=False, hasMath=False, baseClass='SedBase'): #print 'isSedListOf={0} hasChildren={1} hasMath={2}'.format(isSedListOf, hasChildren, hasMath) if isSedListOf or hasChildren == False: return; outFile.write('/*\n') outFile.write(' * Read values from the given XMLAttributes set into their specific fields.\n') outFile.write(' */\n') outFile.write('void\n{0}::connectToChild ()\n'.format(element)) outFile.write('{\n') outFile.write('\t{0}::connectToChild();\n\n'.format(baseClass)) for i in range (0, len(attribs)): if attribs[i]['type'] == 'lo_element' or ( attribs[i]['type'] == 'element' and attribs[i]['name'] != 'math'): if attribs[i]['reqd'] == True or attribs[i]['type'] == 'lo_element': outFile.write('\tm{0}.connectToParent(this);\n'.format(strFunctions.capp(attribs[i]['name'],attribs[i]['type'] == 'lo_element'))) else: outFile.write('\tif (m{0} != NULL)\n'.format(strFunctions.cap(attribs[i]['name']))) outFile.write('\t\tm{0}->connectToParent(this);\n'.format(strFunctions.cap(attribs[i]['name']))) outFile.write('}\n\n\n')
def writeExt(fileOut, name): capName = name.upper() fileOut.write('#ifdef USE_{0}\n'.format(capName)) fileOut.write('if (pkgName == "{0}")\n'.format(name)) fileOut.write('{\n') fileOut.write(' return SWIGTYPE_p_{0}Extension;\n'.format( strFunctions.cap(name))) fileOut.write('}\n') fileOut.write('#endif // USE_{0} \n\n'.format(capName))
def writeConnectToParent(outFile, element, sbmltypecode, attribs, isSedListOf, hasChildren=False, hasMath=False, baseClass='SedBase'): #print 'isSedListOf={0} hasChildren={1} hasMath={2}'.format(isSedListOf, hasChildren, hasMath) if isSedListOf or hasChildren == False: return; outFile.write('/*\n') outFile.write(' * Read values from the given XMLAttributes set into their specific fields.\n') outFile.write(' */\n') outFile.write('void\n{0}::connectToChild ()\n'.format(element)) outFile.write('{\n') outFile.write(' {0}::connectToChild();\n\n'.format(baseClass)) for i in range (0, len(attribs)): if attribs[i]['type'] == 'lo_element' or ( attribs[i]['type'] == 'element' and attribs[i]['name'] != 'math'): if attribs[i]['reqd'] == True or attribs[i]['type'] == 'lo_element': outFile.write(' m{0}.connectToParent(this);\n'.format(strFunctions.capp(attribs[i]['name'],attribs[i]['type'] == 'lo_element'))) else: outFile.write(' if (m{0} != NULL)\n'.format(strFunctions.cap(attribs[i]['name']))) outFile.write(' m{0}->connectToParent(this);\n'.format(strFunctions.cap(attribs[i]['name']))) outFile.write('}\n\n\n')
def writeCode(name): capName = name.upper() codeName = name + '-register.cxx' fileOut = open(codeName, 'w') fileHeaders.addFilename(fileOut, codeName, name) fileHeaders.addLicence(fileOut) fileOut.write('\n') fileOut.write('#ifdef USE_{0}\n'.format(capName)) fileOut.write(' {0}Extension::init();\n'.format(strFunctions.cap(name))) fileOut.write('#endif\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 writeWriteElementsCPPCode(outFile, element, attributes, hasChildren=False, hasMath=False, baseClass='SedBase'): writeInternalStart(outFile) outFile.write('/*\n') outFile.write(' * write contained elements\n') outFile.write(' */\n') outFile.write( 'void\n{0}::writeElements (XMLOutputStream& stream) const\n'.format( element)) outFile.write('{\n') outFile.write('\t{0}::writeElements(stream);\n'.format(baseClass)) if hasChildren == True: for i in range(0, len(attributes)): if attributes[i]['type'] == 'element' and ( attributes[i]['name'] != 'Math' and attributes[i]['name'] != 'math'): outFile.write('\tif (isSet{0}() == true)\n'.format( strFunctions.cap(attributes[i]['name']))) outFile.write('\t{\n\t\t') outFile.write('m{0}->write(stream);'.format( strFunctions.cap(attributes[i]['name']))) outFile.write('\n\t}\n') if attributes[i]['type'] == 'lo_element': outFile.write('\tif (getNum{0}s() > 0)\n'.format( strFunctions.cap(attributes[i]['name']))) outFile.write('\t{\n\t\t') outFile.write('m{0}.write(stream);'.format( strFunctions.cap(attributes[i]['name']))) outFile.write('\n\t}\n') if hasMath == True: for i in range(0, len(attributes)): if attributes[i]['type'] == 'element' and attributes[i][ 'name'] == 'Math' or attributes[i]['name'] == 'math': outFile.write('\tif (isSet{0}() == true)\n'.format('Math')) outFile.write( '\t{\n\t\twriteMathML(getMath(), stream, NULL);\n\t}\n') outFile.write('}\n\n\n') writeInternalEnd(outFile)
def writeCopyAttributes(attrs, output, tabs, name): for i in range(0, len(attrs)): attName = strFunctions.cap(attrs[i]['name']) atttype = attrs[i]['type'] if atttype == 'element' and attName == 'Math': output.write( '{0}m{1} = {2}.m{1} != NULL ? {2}.m{1}->deepCopy() : NULL;\n'. format(tabs, strFunctions.cap(attrs[i]['name']), name)) elif atttype == 'XMLNode*' or atttype == 'DimensionDescription*': output.write( '{0}m{1} = {2}.m{1} != NULL ? {2}.m{1}->clone() : NULL;\n'. format(tabs, strFunctions.cap(attrs[i]['name']), name)) else: output.write('{0}m{1} = {2}.m{1};\n'.format( tabs, strFunctions.capp( attrs[i]['name'], atttype == 'lo_element' or atttype == 'std::vector<double>'), name)) if atttype == 'double' or atttype == 'int' or atttype == 'uint' or atttype == 'bool': output.write('{0}mIsSet{1} = {2}.mIsSet{1};\n'.format( tabs, strFunctions.cap(attrs[i]['name']), name))
def writeSwigHeader(fileOut, name, plugins, classes): capName = strFunctions.cap(name) fileOut.write('#ifdef USE_{0}\n\n'.format(name.upper())) fileOut.write('#include <sbml/packages/{0}/extension/{1}Extension.h>\n'.format(name, capName)) alreadyIncluded = [] for plugin in plugins: package = name if plugin.has_key('package') and plugin['package'] != None: package = plugin['package'] capPackageName = strFunctions.cap(package) if package != name and alreadyIncluded.count(package) == 0: alreadyIncluded.append(package) fileOut.write('#include <sbml/packages/{0}/extension/{1}Extension.h>\n'.format(package, capPackageName)) fileOut.write('#include <sbml/packages/{0}/common/{1}ExtensionTypes.h>\n'.format(package, capPackageName)) fileOut.write('#include <sbml/packages/{0}/extension/{1}{2}Plugin.h>\n'.format(name, capName, plugin['sbase'])) fileOut.write('#include <sbml/packages/{0}/common/{1}ExtensionTypes.h>\n'.format(name, capName)) for clazz in classes: if clazz['typecode'] != 'HACK': fileOut.write('#include <sbml/packages/{0}/sbml/{1}.h>\n'.format(name, clazz['name'])) fileOut.write('\n') fileOut.write('#endif // USE_{0} \n\n'.format(name.upper()))
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 writeHeader(name): capName = name.upper() codeName = name + '-register.h' fileOut = open(codeName, 'w') fileHeaders.addFilename(fileOut, codeName, name) fileHeaders.addLicence(fileOut) fileOut.write('\n') fileOut.write('#ifdef USE_{0}\n'.format(capName)) fileOut.write( ' #include <sbml/packages/{0}/extension/{1}Extension.h>\n'.format( name, strFunctions.cap(name))) fileOut.write('#endif\n\n')
def writeAddFunction(code, type, listOf, name): code.write('/**\n') code.write(' * Adds a copy the given \"{0}\" to this {1}.\n'.format( type, listOf)) code.write(' *\n') code.write(' * @param {0}; the {1} object to add\n'.format( strFunctions.objAbbrev(type), type)) code.write(' *\n') code.write(' * @return integer value indicating success/failure of the\n') code.write(' * function. @if clike The value is drawn from the\n') code.write( ' * enumeration #OperationReturnValues_t. @endif The possible values\n' ) code.write(' * returned by this function are:\n') code.write(' * @li LIBSBML_OPERATION_SUCCESS\n') code.write(' * @li LIBSBML_INVALID_ATTRIBUTE_VALUE\n') code.write(' */\n') code.write('int\n') code.write('{0}::add{1}(const {2}* {3})\n'.format( listOf, strFunctions.cap(name), type, strFunctions.objAbbrev(type))) code.write('{\n') code.write(' if ({0} == NULL)\n'.format(strFunctions.objAbbrev(type))) code.write(' {\n') code.write(' return LIBSBML_OPERATION_FAILED;\n') code.write(' }\n') code.write(' else if ({0}->hasRequiredAttributes() == false)\n'.format( strFunctions.objAbbrev(type))) code.write(' {\n') code.write(' return LIBSBML_INVALID_OBJECT;\n') code.write(' }\n') code.write(' else if (getLevel() != {0}->getLevel())\n'.format( strFunctions.objAbbrev(type))) code.write(' {\n') code.write(' return LIBSBML_LEVEL_MISMATCH;\n') code.write(' }\n') code.write(' else if (getVersion() != {0}->getVersion())\n'.format( strFunctions.objAbbrev(type))) code.write(' {\n') code.write(' return LIBSBML_VERSION_MISMATCH;\n') code.write(' }\n') code.write( ' else if (matchesRequiredSBMLNamespacesForAddition(static_cast<const SBase *>({0})) == false)\n' .format(strFunctions.objAbbrev(type))) code.write(' {\n') code.write(' return LIBSBML_NAMESPACES_MISMATCH;\n') code.write(' }\n') code.write(' else\n') code.write(' {\n') code.write('\tappend({0});\n'.format(strFunctions.objAbbrev(type))) code.write(' return LIBSBML_OPERATION_SUCCESS;\n') code.write(' }\n') code.write('}\n\n\n')
def writeWriteElementsCPPCode(outFile, element, attributes, hasChildren=False, hasMath=False, baseClass='SedBase'): writeInternalStart(outFile) outFile.write('/*\n') outFile.write(' * write contained elements\n') outFile.write(' */\n') outFile.write('void\n{0}::writeElements (XMLOutputStream& stream) const\n'.format(element)) outFile.write('{\n') outFile.write('\t{0}::writeElements(stream);\n'.format(baseClass)) if hasChildren == True: for i in range(0, len(attributes)): if attributes[i]['type'] == 'element' and (attributes[i]['name'] != 'Math' and attributes[i]['name'] != 'math'): outFile.write('\tif (isSet{0}() == true)\n'.format(strFunctions.cap(attributes[i]['name']))) outFile.write('\t{\n\t\t') outFile.write('m{0}->write(stream);'.format(strFunctions.cap(attributes[i]['name']))) outFile.write('\n\t}\n') if attributes[i]['type'] == 'lo_element': outFile.write('\tif (getNum{0}() > 0)\n'.format(strFunctions.capp(attributes[i]['name']))) outFile.write('\t{\n\t\t') outFile.write('m{0}.write(stream);'.format(strFunctions.capp(attributes[i]['name']))) outFile.write('\n\t}\n') if containsType(attributes, 'std::vector<double>'): vector = getByType(attributes, 'std::vector<double>') outFile.write('\tif(has{0}())\n'.format(strFunctions.capp(vector['name']))) outFile.write('\t{\n') outFile.write('\t\tfor (std::vector<double>::const_iterator it = m{0}.begin(); it != m{0}.end(); ++it)\n'.format(strFunctions.capp(vector['name']))) outFile.write('\t\t{\n') outFile.write('\t\t\tstream.startElement("{0}");\n'.format(vector['name'])) outFile.write('\t\t\tstream.setAutoIndent(false);\n') outFile.write('\t\t\tstream << " " << *it << " ";\n') outFile.write('\t\t\tstream.endElement("{0}");\n'.format(vector['name'])) outFile.write('\t\t\tstream.setAutoIndent(true);\n') outFile.write('\t\t}\n') outFile.write('\t}\n') if hasMath == True: for i in range(0, len(attributes)): if attributes[i]['type'] == 'element' and attributes[i]['name'] == 'Math' or attributes[i]['name'] == 'math': outFile.write('\tif (isSet{0}() == true)\n'.format('Math')) outFile.write('\t{\n\t\twriteMathML(getMath(), stream, NULL);\n\t}\n') outFile.write('}\n\n\n') writeInternalEnd(outFile)
def writeJavaExt(fileOut, name): capName = name.upper() fileOut.write('/**\n') fileOut.write(' * casting to most specific SBMLExtension object\n */\n\n') fileOut.write('#ifdef USE_{0}\n'.format(capName)) fileOut.write('%pragma(java) modulecode =\n') fileOut.write('%{\n') fileOut.write(' if (pkgName.equals("{0}"))\n'.format(name)) fileOut.write(' {\n') fileOut.write(' return new {0}Extension(cPtr, owner);\n'.format(strFunctions.cap(name))) fileOut.write(' }\n') fileOut.write('%}\n') fileOut.write('#endif // USE_{0}\n\n'.format(capName))
def writeCreateLOObject(fileOut, mem, ifCount): name = strFunctions.cap(mem['name']) if ifCount == 1: fileOut.write(' if (name == "listOf{0}s" ) \n'.format(name)) else: fileOut.write(' else if (name == "listOf{0}s" ) \n'.format(name)) fileOut.write(' { \n') fileOut.write(' object = &m{0}s;\n\n'.format(name)) fileOut.write(' if (targetPrefix.empty() == true) \n') fileOut.write(' { \n') fileOut.write(' m{0}s.getSBMLDocument()->enableDefaultNS(mURI, true); \n'.format(name)) fileOut.write(' } \n') fileOut.write(' } \n')
def writeClass(header, nameOfElement, typeOfElement, nameOfPackage, elementDict): header.write('class LIBSEDML_EXTERN {0} :'.format(generalFunctions.writeListOf(nameOfElement))) header.write(' public SedListOf\n{0}\n\n'.format('{')) header.write('public:\n\n') writeConstructors(nameOfElement, typeOfElement, nameOfPackage, header) writeGetFunctions(header, nameOfElement, typeOfElement) header.write('\t/**\n') header.write('\t * Adds a copy the given \"{0}\" to this {1}.\n'.format(nameOfElement, generalFunctions.writeListOf(nameOfElement))) header.write('\t *\n') header.write('\t * @param {0}; the {1} object to add\n'.format(strFunctions.objAbbrev(nameOfElement), nameOfElement)) header.write('\t *\n') header.write('\t * @return integer value indicating success/failure of the\n') header.write('\t * function. @if clike The value is drawn from the\n') header.write('\t * enumeration #OperationReturnValues_t. @endif The possible values\n') header.write('\t * returned by this function are:\n') header.write('\t * @li LIBSEDML_OPERATION_SUCCESS\n') header.write('\t * @li LIBSEDML_INVALID_ATTRIBUTE_VALUE\n') header.write('\t */\n') header.write('\tint add{0}(const {1}* {2});\n\n\n'.format(nameOfElement, typeOfElement, strFunctions.objAbbrev(nameOfElement))) header.write('\t/**\n') header.write('\t * Get the number of {0} objects in this {1}.\n'.format(nameOfElement, generalFunctions.writeListOf(nameOfElement))) header.write('\t *\n') header.write('\t * @return the number of {0} objects in this {1}\n'.format(nameOfElement, generalFunctions.writeListOf(nameOfElement))) header.write('\t */\n') header.write('\tunsigned int getNum{0}s() const;\n\n\n'.format(nameOfElement)) if elementDict.has_key('abstract') == False or (elementDict.has_key('abstract') and elementDict['abstract'] == False): header.write('\t/**\n') header.write('\t * Creates a new {0} object, adds it to the\n'.format(nameOfElement)) header.write('\t * {0} and returns the {1} object created. \n'.format(generalFunctions.writeListOf(nameOfElement), nameOfElement)) header.write('\t *\n') header.write('\t * @return a new {0} object instance\n'.format(nameOfElement)) header.write('\t *\n') header.write('\t * @see add{0}(const {1}* {2})\n'.format(nameOfElement, typeOfElement, strFunctions.objAbbrev(nameOfElement))) header.write('\t */\n') header.write('\t{0}* create{1}();\n\n\n'.format(typeOfElement, nameOfElement)) elif elementDict.has_key('concrete'): for elem in elementDict['concrete']: header.write('\t/**\n') header.write('\t * Creates a new {0} object, adds it to the\n'.format(nameOfElement)) header.write('\t * {0} and returns the {1} object created. \n'.format(generalFunctions.writeListOf(nameOfElement), nameOfElement)) header.write('\t *\n') header.write('\t * @return a new {0} object instance\n'.format(nameOfElement)) header.write('\t *\n') header.write('\t * @see add{0}(const {1}* {2})\n'.format(nameOfElement, typeOfElement, strFunctions.objAbbrev(nameOfElement))) header.write('\t */\n') header.write('\t{0}* create{1}();\n\n\n'.format(elem['element'], strFunctions.cap(elem['name']))) writeRemoveFunctions(header, nameOfElement, typeOfElement) generalFunctions.writeCommonHeaders(header, nameOfElement, None, True) header.write('protected:\n\n') writeProtectedFunctions(header, nameOfElement, nameOfPackage) header.write('\n};\n\n')
def writeClass(header, nameOfElement, typeOfElement, nameOfPackage, elementDict): header.write('class LIBSEDML_EXTERN {0} :'.format(generalFunctions.writeListOf(nameOfElement))) header.write(' public SedListOf\n{0}\n\n'.format('{')) header.write('public:\n\n') writeConstructors(nameOfElement, typeOfElement, nameOfPackage, header) writeGetFunctions(header, nameOfElement, typeOfElement) header.write(' /**\n') header.write(' * Adds a copy the given \"{0}\" to this {1}.\n'.format(nameOfElement, generalFunctions.writeListOf(nameOfElement))) header.write(' *\n') header.write(' * @param {0}; the {1} object to add\n'.format(strFunctions.objAbbrev(nameOfElement), nameOfElement)) header.write(' *\n') header.write(' * @return integer value indicating success/failure of the\n') header.write(' * function. @if clike The value is drawn from the\n') header.write(' * enumeration #OperationReturnValues_t. @endif The possible values\n') header.write(' * returned by this function are:\n') header.write(' * @li LIBSEDML_OPERATION_SUCCESS\n') header.write(' * @li LIBSEDML_INVALID_ATTRIBUTE_VALUE\n') header.write(' */\n') header.write(' int add{0}(const {1}* {2});\n\n\n'.format(nameOfElement, typeOfElement, strFunctions.objAbbrev(nameOfElement))) header.write(' /**\n') header.write(' * Get the number of {0} objects in this {1}.\n'.format(nameOfElement, generalFunctions.writeListOf(nameOfElement))) header.write(' *\n') header.write(' * @return the number of {0} objects in this {1}\n'.format(nameOfElement, generalFunctions.writeListOf(nameOfElement))) header.write(' */\n') header.write(' unsigned int getNum{0}s() const;\n\n\n'.format(nameOfElement)) if elementDict.has_key('abstract') == False or (elementDict.has_key('abstract') and elementDict['abstract'] == False): header.write(' /**\n') header.write(' * Creates a new {0} object, adds it to the\n'.format(nameOfElement)) header.write(' * {0} and returns the {1} object created.\n'.format(generalFunctions.writeListOf(nameOfElement), nameOfElement)) header.write(' *\n') header.write(' * @return a new {0} object instance\n'.format(nameOfElement)) header.write(' *\n') header.write(' * @see add{0}(const {1}* {2})\n'.format(nameOfElement, typeOfElement, strFunctions.objAbbrev(nameOfElement))) header.write(' */\n') header.write(' {0}* create{1}();\n\n\n'.format(typeOfElement, nameOfElement)) elif elementDict.has_key('concrete'): for elem in elementDict['concrete']: header.write(' /**\n') header.write(' * Creates a new {0} object, adds it to the\n'.format(nameOfElement)) header.write(' * {0} and returns the {1} object created.\n'.format(generalFunctions.writeListOf(nameOfElement), nameOfElement)) header.write(' *\n') header.write(' * @return a new {0} object instance\n'.format(nameOfElement)) header.write(' *\n') header.write(' * @see add{0}(const {1}* {2})\n'.format(nameOfElement, typeOfElement, strFunctions.objAbbrev(nameOfElement))) header.write(' */\n') header.write(' {0}* create{1}();\n\n\n'.format(elem['element'], strFunctions.cap(elem['name']))) writeRemoveFunctions(header, nameOfElement, typeOfElement) generalFunctions.writeCommonHeaders(header, nameOfElement, None, True) header.write('protected:\n\n') writeProtectedFunctions(header, nameOfElement, nameOfPackage) header.write('\n};\n\n')
def writeProtectedFunctions(output, element, package, name, elementDict): type = elementDict['name'] elName = elementDict['name'] if elementDict.has_key('elementName'): elName = strFunctions.cap(elementDict['elementName']) if elementDict.has_key('element'): type = elementDict['element'] listOf = generalFunctions.writeListOf(elName) generalFunctions.writeInternalStart(output) output.write('/*\n') output.write(' * Creates a new {0} in this {1}\n'.format(element, listOf)) output.write(' */\n') output.write('SedBase*\n{0}::createObject(XMLInputStream& stream)\n'.format(listOf)) output.write('{\n' ) output.write(' const std::string& name = stream.peek().getName();\n') output.write(' SedBase* object = NULL;\n\n') if elementDict == None or elementDict.has_key('abstract') == False or (elementDict.has_key('abstract') and elementDict['abstract'] == False): output.write(' if (name == "{0}")\n'.format(name)) output.write(' {\n') output.write(' object = new {0}(getSedNamespaces());\n'.format(element)) output.write(' appendAndOwn(object);\n }\n\n') elif elementDict != None and elementDict.has_key('concrete'): for elem in elementDict['concrete']: output.write(' if (name == "{0}")\n'.format(elem['name'])) output.write(' {\n') output.write(' object = new {0}(getSedNamespaces());\n'.format(elem['element'])) output.write(' appendAndOwn(object);\n }\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(' if (getNamespaces() != NULL && !getNamespaces()->hasURI(SEDML_XMLNS_L1) && !getNamespaces()->hasURI(SEDML_XMLNS_L1V2) && !getNamespaces()->hasURI(SEDML_XMLNS_L1V3))\n') output.write(' {\n') output.write(' if (getVersion() == 2) xmlns.add(SEDML_XMLNS_L1V2,prefix);\n') output.write(' else if (getVersion() == 3) xmlns.add(SEDML_XMLNS_L1V3,prefix);\n') output.write(' else xmlns.add(SEDML_XMLNS_L1V2,prefix);\n') output.write(' }\n') output.write(' }\n\n') output.write(' stream << xmlns;\n') output.write('}\n\n\n') generalFunctions.writeInternalEnd(output)
def writeWriteAttributesCPPCode(outFile, element, attribs, baseClass='SedBase'): writeInternalStart(outFile) outFile.write('/*\n') outFile.write(' * Write values of XMLAttributes to the output stream.\n') outFile.write(' */\n') outFile.write('\tvoid\n{0}::writeAttributes (XMLOutputStream& stream) const\n'.format(element)) outFile.write('{\n') outFile.write('\t{0}::writeAttributes(stream);\n\n'.format(baseClass)) for i in range (0, len(attribs)): if attribs[i]['type'] != 'element' and attribs[i]['type'] != 'lo_element': outFile.write('\tif (isSet{0}() == true)\n'.format(strFunctions.cap(attribs[i]['name']))) outFile.write('\t\tstream.writeAttribute("{0}", getPrefix(), m{1});\n\n'.format(attribs[i]['name'], strFunctions.cap(attribs[i]['name']))) outFile.write('}\n\n\n') writeInternalEnd(outFile)
def writeGetFunction(attrib, output, element): att = generalFunctions.parseAttributeForC(attrib) attName = att[0] capAttName = att[1] attType = att[2] if att[3] == 'const char *': attTypeCode = 'char *' else: attTypeCode = att[3] num = att[4] if attrib['type'] == 'std::vector<double>': return elif attrib['type'] != 'element' and attrib['type'] != 'lo_element' and attrib['type'] != 'XMLNode*': output.write('LIBSEDML_EXTERN\n') output.write('{0}\n'.format(attTypeCode)) output.write('{0}_get{1}'.format(element, capAttName)) output.write('({0}_t * {1});\n\n\n'.format(element, strFunctions.objAbbrev(element))) elif attrib['type'] == 'XMLNode*': output.write('LIBSEDML_EXTERN\n') output.write('XMLNode_t*\n') output.write('{0}_get{1}'.format(element, capAttName)) output.write('({0}_t * {1});\n\n\n'.format(element, strFunctions.objAbbrev(element))) elif attrib['type'] == 'element': if attrib['name'] == 'Math' or attrib['name'] == 'math': output.write('LIBSEDML_EXTERN\n') output.write('ASTNode_t*\n') output.write('{0}_getMath'.format(element)) output.write('({0}_t * {1});\n\n\n'.format(element, strFunctions.objAbbrev(element))) else: output.write('LIBSEDML_EXTERN\n') output.write('{0}_t*\n'.format(strFunctions.cap(attrib['element']))) output.write('{0}_get{1}'.format(element, capAttName)) output.write('({0}_t * {1});\n\n\n'.format(element, strFunctions.objAbbrev(element))) output.write('LIBSEDML_EXTERN\n') output.write('{0}_t*\n'.format(strFunctions.cap(attrib['element']))) output.write('{0}_create{1}'.format(element, capAttName)) output.write('({0}_t * {1});\n\n\n'.format(element, strFunctions.objAbbrev(element)))
def writeListOfSubElements(attrib, output, element): loname = generalFunctions.writeListOf(strFunctions.cap(attrib['name'])) output.write('LIBSEDML_EXTERN\n') output.write('int\n') output.write('{0}_add{1}({0}_t * {2}, '.format(element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write('{0}_t * {1});\n\n\n'.format(attrib['element'], strFunctions.objAbbrev(attrib['element']))) if attrib.has_key('abstract') == False or (attrib.has_key('abstract') and attrib['abstract'] == False): output.write('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(attrib['element'])) output.write('{0}_create{1}({0}_t * {2}' .format(element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write(');\n\n\n') elif attrib.has_key('concrete'): for elem in attrib['concrete']: output.write('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(elem['element'])) output.write('{0}_create{1}({0}_t * {2}' .format(element, strFunctions.cap(elem['name']), strFunctions.objAbbrev(element))) output.write(');\n\n\n') output.write('LIBSEDML_EXTERN\n') output.write('SedListOf_t *\n') output.write('{0}_get{1}({0}_t * {2})'.format(element, loname, strFunctions.objAbbrev(element))) output.write(';\n\n\n') output.write('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(attrib['element'])) output.write('{0}_get{1}({0}_t * {2}, '.format(element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write('unsigned int n);\n\n\n') output.write('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(attrib['element'])) output.write('{0}_get{1}ById({0}_t * {2}, '.format(element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write('const char * sid);\n\n\n') output.write('LIBSEDML_EXTERN\n') output.write('unsigned int\n') output.write('{0}_getNum{1}s({0}_t * {2}' .format(element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write(');\n\n\n') output.write('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(attrib['element'])) output.write('{0}_remove{1}({0}_t * {2}, '.format(element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write('unsigned int n);\n\n\n') output.write('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(attrib['element'])) output.write('{0}_remove{1}ById({0}_t * {2}, '.format(element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write('const char * sid);\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 createHeader(element, header): type = element["name"] name = element["name"] if element.has_key("elementName"): name = strFunctions.cap(element["elementName"]) if element.has_key("element"): type = element["element"] writeConstructors(element["name"], element["package"], header) writeAttributeFunctions(element["attribs"], header, element["name"], element) writeHasReqdAttrFunction(header, element["name"]) if element["hasChildren"] == True or element["hasMath"] == True: writeHasReqdElementsFunction(header, element["name"]) if element["hasListOf"] == True: writeListOfHeaders(header, name, type, element)