def writeConsistencyHeader(fileOut, element, pkg, type): 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('#ifdef __cplusplus\n\n') fileOut.write('#include <sbml/packages/{0}/validator/{1}Validator.h>\n\n'.format(pkg.lower(), pkg)) fileOut.write('LIBSBML_CPP_NAMESPACE_BEGIN\n\n') fileOut.write('class {0}: public {1}Validator\n'.format(element, pkg)) fileOut.write('{\n') fileOut.write('public:\n\n') fileOut.write(' {0} () :\n'.format(element)) if type == "": fileOut.write(' {0}Validator(LIBSBML_CAT_GENERAL_CONSISTENCY)'.format(pkg)) elif type == "Identifier": fileOut.write(' {0}Validator(LIBSBML_CAT_IDENTIFIER_CONSISTENCY)'.format(pkg)) fileOut.write(' { }\n\n') fileOut.write(' virtual ~{0} () '.format(element)) fileOut.write('{ }\n\n') fileOut.write(' virtual void init ();\n') fileOut.write('};\n\n') fileOut.write('LIBSBML_CPP_NAMESPACE_END\n\n') fileOut.write('#endif /* __cplusplus*/\n') fileOut.write('#endif /* {0}_H__ */\n\n\n'.format(element)) generalFunctions.writeInternalEnd(fileOut) fileOut.close()
def createValidatorHeader(pkg): inputFile = os.path.dirname(__file__) + '/templateValidHead.txt' headerName = pkg + 'Validator.h' header = open(headerName, 'w') nameOfElement = pkg + 'Validator' fileHeaders.addFilename(header, headerName, nameOfElement) fileHeaders.addLicence(header) header.write('\n#ifndef {0}Validator__H\n'.format(pkg)) header.write('#define {0}Validator__H\n\n\n'.format(pkg)) header.write('#ifdef __cplusplus\n\n\n') generalFunctions.writeInternalStart(header) header.write('#include <list>\n') header.write('#include <string>\n') generalFunctions.writeInternalEnd(header) input = open(inputFile, 'r') for line in input: if line[0:13] != 'TEMPLATE_STOP': line = replaceTags(line, pkg) header.write(line) else: break header.write('#endif /* __cplusplus*/\n') header.write('#endif /* {0}Validator__H */\n'.format(pkg)) input.close() header.close()
def writeRequiredMethods(fileOut, attribs): fileOut.write( ' //---------------------------------------------------------------\n' ) fileOut.write(' //\n') fileOut.write(' // overridden virtual functions for read/write/check\n') fileOut.write(' //\n') fileOut.write( ' //---------------------------------------------------------------\n\n' ) generalFunctions.writeInternalStart(fileOut) fileOut.write(' /**\n') fileOut.write( ' * Subclasses must override this method to create, store, and then\n' ) fileOut.write( ' * return an SBML object corresponding to the next XMLToken in the\n' ) fileOut.write( ' * XMLInputStream if they have their specific elements.\n') fileOut.write(' *\n') fileOut.write( ' * @return the SBML object corresponding to next XMLToken in the\n') fileOut.write( ' * XMLInputStream or NULL if the token was not recognized.\n') fileOut.write(' */\n') fileOut.write( ' virtual SBase* createObject (XMLInputStream& stream);\n\n\n') generalFunctions.writeInternalEnd(fileOut) generalFunctions.writeInternalStart(fileOut) fileOut.write(' /**\n') fileOut.write( ' * Subclasses must override this method to write out their contained\n' ) fileOut.write( ' * SBML objects as XML elements if they have their specific elements.\n' ) fileOut.write(' */\n') fileOut.write( ' virtual void writeElements (XMLOutputStream& stream) const;\n\n\n') generalFunctions.writeInternalEnd(fileOut) fileOut.write(' /**\n') fileOut.write( ' * Checks if this plugin object has all the required elements.\n') fileOut.write(' *\n') fileOut.write(' * Subclasses must override this method \n') fileOut.write(' * if they have their specific elements.\n') fileOut.write(' *\n') fileOut.write( ' * @return true if this plugin object has all the required elements\n' ) fileOut.write(' * otherwise false will be returned.\n') fileOut.write(' */\n') fileOut.write(' virtual bool hasRequiredElements () const;\n\n\n') fileOut.write( ' //---------------------------------------------------------------\n\n\n' ) generalFunctions.writeAddExpectedHeader(fileOut) generalFunctions.writeReadAttributesHeader(fileOut) generalFunctions.writeWriteAttributesHeader(fileOut)
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 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 writeReadAttMethods(fileOut): fileOut.write('#ifndef SWIG\n\n') generalFunctions.writeInternalStart(fileOut) fileOut.write(' /**\n') fileOut.write(' * Reads the attributes of corresponding package in SBMLDocument element\n') fileOut.write(' */\n') fileOut.write(' virtual void readAttributes (const XMLAttributes& attributes, \n') fileOut.write(' const ExpectedAttributes& expectedAttributes);\n\n\n') generalFunctions.writeInternalEnd(fileOut) fileOut.write('#endif // SWIG\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 writeProtectedFunctions(output, element, package, elementDict = None): listOf = generalFunctions.getListOfClassName(elementDict, elementDict['name']) generalFunctions.writeInternalStart(output) output.write(' /**\n') output.write(' * Creates a new {0} in this {1}\n'.format(element, listOf)) output.write(' */\n') output.write(' virtual SBase* createObject(XMLInputStream& stream);\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(' virtual void writeXMLNS(XMLOutputStream& stream) const;\n\n\n') generalFunctions.writeInternalEnd(output)
def writeInitFunction(fileOut, pkg): generalFunctions.writeInternalStart(fileOut) fileOut.write('\t/**\n') fileOut.write('\t * Initializes {0} extension by creating an object of this class with \n'.format(pkg.lower())) fileOut.write('\t * required SedBasePlugin derived objects and registering the object \n') fileOut.write('\t * to the SEDMLExtensionRegistry class.\n') fileOut.write('\t *\n') fileOut.write('\t * (NOTE) This function is automatically invoked when creating the following\n') fileOut.write('\t * global object in {0}Extension.cpp\n'.format(pkg)) fileOut.write('\t *\n') fileOut.write('\t * static SEDMLExtensionRegister<{0}Extension> {1}ExtensionRegistry;\n'.format(pkg, pkg.lower())) fileOut.write('\t *\n') fileOut.write('\t */\n') fileOut.write('\tstatic void init();\n\n\n') generalFunctions.writeInternalEnd(fileOut)
def writeConsistencyFile(fileOut, element, pkg, type): fileOut.write('\n\n'); fileOut.write('#ifndef doxygen_ignore\n\n') fileOut.write('#include <sbml/packages/{0}/validator/{1}.h>\n\n'.format(pkg.lower(), element)) fileOut.write('#include "constraints/{0}{1}ConsistencyConstraints.cpp"\n\n'.format(pkg, type)) fileOut.write('LIBSBML_CPP_NAMESPACE_BEGIN\n\n') fileOut.write('void\n') fileOut.write('{0}::init ()\n'.format(element)) fileOut.write('{\n') fileOut.write('#define AddingConstraintsToValidator 1\n') fileOut.write('#include "constraints/{0}{1}ConsistencyConstraints.cpp"\n'.format(pkg, type)) fileOut.write('}\n\n') fileOut.write('LIBSBML_CPP_NAMESPACE_END\n\n') fileOut.write('#endif /* __doxygen_ignore */\n\n') generalFunctions.writeInternalEnd(fileOut) fileOut.close()
def createConstraintsFile(pkg, type): nameOfElement = pkg + type + 'ConsistencyConstraints' fileName = nameOfElement + '.cpp' output = open(fileName, 'w') generalFunctions.writeInternalStart(output) fileHeaders.addFilename(output, fileName, nameOfElement) fileHeaders.addLicence(output) output.write('\n#ifndef AddingConstraintsToValidator\n\n') output.write('#include <sbml/validator/VConstraint.h>\n\n') output.write('#include <sbml/packages/{0}/validator/{1}SBMLError.h>\n\n'.format(pkg.lower(), pkg)) output.write('#endif /* AddingConstrainstToValidator */\n\n') output.write('#include <sbml/validator/ConstraintMacros.h>\n\n') output.write('/** @cond doxygenIgnored */\n\n') output.write('using namespace std;\n\n') output.write('/** @endcond */\n\n') output.write('/** PUT CONSTRAINTS HERE */\n\n') generalFunctions.writeInternalEnd(output)
def writeOtherFunctions(fileOut, nameOfClass, pkg): # indent = strFunctions.getIndent(nameOfClass) generalFunctions.writeInternalStart(fileOut) fileOut.write(' /**\n * ' ) fileOut.write('Returns boolean based on whether flattening of a comp model has been implemented.\n') fileOut.write(' *\n') fileOut.write(' * @returns @c true if flattening for composed models has been implemented,\n') fileOut.write(' * false otherwise.\n') fileOut.write(' */\n') fileOut.write(' virtual bool isCompFlatteningImplemented() const;\n\n\n') generalFunctions.writeInternalEnd(fileOut) generalFunctions.writeInternalStart(fileOut) fileOut.write(' /**\n * ' ) fileOut.write('Check consistency function.\n') fileOut.write(' */\n') fileOut.write(' virtual unsigned int checkConsistency();\n\n\n') generalFunctions.writeInternalEnd(fileOut)
def writeClassEnd(fileOut, members, attribs, plugin): fileOut.write('protected:\n\n') generalFunctions.writeInternalStart(fileOut) for i in range(0, len(members)): mem = members[i] if mem['isListOf'] == True: fileOut.write(' ListOf{0}s m{0}s;\n'.format(mem['name'])) else: fileOut.write(' {0}* m{0};\n'.format(mem['name'])) for i in range(0, len(attribs)): mem = attribs[i] writeHeader.writeAtt(mem, fileOut) fileOut.write('\n') generalFunctions.writeInternalEnd(fileOut) if plugin.has_key('addDecls'): fileOut.write(open(plugin['addDecls'], 'r').read()) fileOut.write('};\n\n\n')
def writeProtectedFunctions(output, element, package, elementDict=None): listOf = generalFunctions.getListOfClassName(elementDict, elementDict['name']) generalFunctions.writeInternalStart(output) output.write(' /**\n') output.write(' * Creates a new {0} in this {1}\n'.format( element, listOf)) output.write(' */\n') output.write( ' virtual SBase* createObject(XMLInputStream& stream);\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( ' virtual void writeXMLNS(XMLOutputStream& stream) const;\n\n\n') generalFunctions.writeInternalEnd(output)
def writeClassEnd(fileOut, members, attribs, plugin): fileOut.write('protected:\n\n') generalFunctions.writeInternalStart(fileOut) for i in range (0, len(members)): mem = members[i] if mem['isListOf'] == True: fileOut.write(' ListOf{0}s m{0}s;\n'.format(mem['name'])) else: fileOut.write(' {0}* m{0};\n'.format(mem['name'])) for i in range (0, len(attribs)): mem = attribs[i] writeHeader.writeAtt(mem, fileOut); fileOut.write('\n') generalFunctions.writeInternalEnd(fileOut) if plugin.has_key('addDecls'): fileOut.write(open(plugin['addDecls'], 'r').read()) fileOut.write('};\n\n\n')
def writeErrorFunction(fileOut, pkg): generalFunctions.writeInternalStart(fileOut) fileOut.write(' /**\n') fileOut.write(' * Return the entry in the error table at this index. \n') fileOut.write(' *\n') fileOut.write(' * @param index an unsigned intgere representing the index of the error in the {0}SBMLErrorTable\n'.format(pkg)) fileOut.write(' *\n') fileOut.write(' * @return packageErrorTableEntry object in the {0}SBMLErrorTable corresponding to the index given.\n'.format(pkg)) fileOut.write(' */\n') fileOut.write(' virtual packageErrorTableEntry getErrorTable(unsigned int index) const;\n\n\n') generalFunctions.writeInternalEnd(fileOut) generalFunctions.writeInternalStart(fileOut) fileOut.write(' /**\n') fileOut.write(' * Return the index in the error table with the given errorId. \n') fileOut.write(' *\n') fileOut.write(' * @param errorId an unsigned intgere representing the errorId of the error in the {0}SBMLErrorTable\n'.format(pkg)) fileOut.write(' *\n') fileOut.write(' * @return unsigned integer representing the index in the {0}SBMLErrorTable corresponding to the errorId given.\n'.format(pkg)) fileOut.write(' */\n') fileOut.write(' virtual unsigned int getErrorTableIndex(unsigned int errorId) const;\n\n\n') generalFunctions.writeInternalEnd(fileOut) generalFunctions.writeInternalStart(fileOut) fileOut.write(' /**\n') fileOut.write(' * Return the offset for the errorId range for the {0} L3 package. \n'.format(pkg.lower())) fileOut.write(' *\n') fileOut.write(' * @return unsigned intege representing the offset for errors {0}SBMLErrorTable.\n'.format(pkg)) fileOut.write(' */\n') fileOut.write(' virtual unsigned int getErrorIdOffset() const;\n\n\n') generalFunctions.writeInternalEnd(fileOut)
def writeRequiredMethods(fileOut, attribs): fileOut.write(' //---------------------------------------------------------------\n') fileOut.write(' //\n') fileOut.write(' // overridden virtual functions for read/write/check\n') fileOut.write(' //\n') fileOut.write(' //---------------------------------------------------------------\n\n') generalFunctions.writeInternalStart(fileOut) fileOut.write(' /**\n') fileOut.write(' * Subclasses must override this method to create, store, and then\n') fileOut.write(' * return an SBML object corresponding to the next XMLToken in the\n') fileOut.write(' * XMLInputStream if they have their specific elements.\n') fileOut.write(' *\n') fileOut.write(' * @return the SBML object corresponding to next XMLToken in the\n') fileOut.write(' * XMLInputStream or NULL if the token was not recognized.\n') fileOut.write(' */\n') fileOut.write(' virtual SBase* createObject (XMLInputStream& stream);\n\n\n') generalFunctions.writeInternalEnd(fileOut) generalFunctions.writeInternalStart(fileOut) fileOut.write(' /**\n') fileOut.write(' * Subclasses must override this method to write out their contained\n') fileOut.write(' * SBML objects as XML elements if they have their specific elements.\n') fileOut.write(' */\n') fileOut.write(' virtual void writeElements (XMLOutputStream& stream) const;\n\n\n') generalFunctions.writeInternalEnd(fileOut) fileOut.write(' /**\n') fileOut.write(' * Checks if this plugin object has all the required elements.\n') fileOut.write(' *\n') fileOut.write(' * Subclasses must override this method \n') fileOut.write(' * if they have their specific elements.\n') fileOut.write(' *\n') fileOut.write(' * @return true if this plugin object has all the required elements\n') fileOut.write(' * otherwise false will be returned.\n') fileOut.write(' */\n') fileOut.write(' virtual bool hasRequiredElements () const;\n\n\n') fileOut.write(' //---------------------------------------------------------------\n\n\n') generalFunctions.writeAddExpectedHeader(fileOut) generalFunctions.writeReadAttributesHeader(fileOut) generalFunctions.writeWriteAttributesHeader(fileOut)
def writeErrorTable(fileOut, element, pkg, offset, classes): 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/packages/{0}/validator/{1}SBMLError.h>\n\n'.format(pkg.lower(), pkg)) fileOut.write('LIBSBML_CPP_NAMESPACE_BEGIN\n\n') generalFunctions.writeInternalStart(fileOut) fileOut.write('static const packageErrorTableEntry {0}ErrorTable[] = \n'.format(pkg.lower())) fileOut.write('{\n') fileOut.write(' //{0}\n'.format(offset+10100)); fileOut.write(' {') fileOut.write(' {0}UnknownError,\n'.format(pkg)); fileOut.write(' "Unknown error from {0}",\n'.format(pkg.lower())) fileOut.write(' LIBSBML_CAT_GENERAL_CONSISTENCY,\n') fileOut.write(' LIBSBML_SEV_ERROR,\n') fileOut.write(' "Unknown error from {0}",\n'.format(pkg.lower())) fileOut.write(' { " "\n') fileOut.write(' }\n') fileOut.write(' }\n\n') fileOut.write('};\n\n') fileOut.write('\nLIBSBML_CPP_NAMESPACE_END\n\n') generalFunctions.writeInternalEnd(fileOut) fileOut.write('#endif /* {0}_h__ */\n\n'.format(element))
def writeInitFunction(fileOut, pkg): generalFunctions.writeInternalStart(fileOut) fileOut.write(' /**\n') fileOut.write( ' * Initializes {0} extension by creating an object of this class with \n' .format(pkg.lower())) fileOut.write( ' * required SBasePlugin derived objects and registering the object \n' ) fileOut.write(' * to the SBMLExtensionRegistry class.\n') fileOut.write(' *\n') fileOut.write( ' * (NOTE) This function is automatically invoked when creating the following\n' ) fileOut.write( ' * global object in {0}Extension.cpp\n'.format(pkg)) fileOut.write(' *\n') fileOut.write( ' * static SBMLExtensionRegister<{0}Extension> {1}ExtensionRegistry;\n' .format(pkg, pkg.lower())) fileOut.write(' *\n') fileOut.write(' */\n') fileOut.write(' static void init();\n\n\n') generalFunctions.writeInternalEnd(fileOut)
def writeErrorFunction(fileOut, pkg, nameOfClass, offset): generalFunctions.writeInternalStart(fileOut) fileOut.write('/*\n') fileOut.write(' * Return error table entry. \n') fileOut.write(' */\n') fileOut.write('packageErrorTableEntry\n') fileOut.write( '{0}::getErrorTable(unsigned int index) const\n'.format(nameOfClass)) fileOut.write('{\n') fileOut.write(' return {0}ErrorTable[index];\n'.format(pkg.lower())) fileOut.write('}\n\n') generalFunctions.writeInternalEnd(fileOut) generalFunctions.writeInternalStart(fileOut) fileOut.write('/*\n') fileOut.write(' * Return error table index for this id. \n') fileOut.write(' */\n') fileOut.write('unsigned int\n') fileOut.write( '{0}::getErrorTableIndex(unsigned int errorId) const\n'.format( nameOfClass)) fileOut.write('{\n') fileOut.write( ' unsigned int tableSize = sizeof({0}ErrorTable)/sizeof({0}ErrorTable[0]);\n' .format(pkg.lower())) fileOut.write(' unsigned int index = 0;\n\n') fileOut.write(' for(unsigned int i = 0; i < tableSize; i++)\n') fileOut.write(' {\n') fileOut.write(' if (errorId == {0}ErrorTable[i].code)\n'.format( pkg.lower())) fileOut.write(' {\n') fileOut.write(' index = i;\n') fileOut.write(' break;\n') fileOut.write(' }\n\n') fileOut.write(' }\n\n') fileOut.write(' return index;\n') fileOut.write('}\n\n') generalFunctions.writeInternalEnd(fileOut) generalFunctions.writeInternalStart(fileOut) fileOut.write('/*\n') fileOut.write(' * Return error offset. \n') fileOut.write(' */\n') fileOut.write('unsigned int\n') fileOut.write('{0}::getErrorIdOffset() const\n'.format(nameOfClass)) fileOut.write('{\n') fileOut.write(' return {0};\n'.format(offset)) fileOut.write('}\n\n') generalFunctions.writeInternalEnd(fileOut)
def writeErrorFunction(fileOut, pkg): generalFunctions.writeInternalStart(fileOut) fileOut.write(' /**\n') fileOut.write(' * Return the entry in the error table at this index. \n') fileOut.write(' *\n') fileOut.write( ' * @param index an unsigned intgere representing the index of the error in the {0}SBMLErrorTable\n' .format(pkg)) fileOut.write(' *\n') fileOut.write( ' * @return packageErrorTableEntry object in the {0}SBMLErrorTable corresponding to the index given.\n' .format(pkg)) fileOut.write(' */\n') fileOut.write( ' virtual packageErrorTableEntry getErrorTable(unsigned int index) const;\n\n\n' ) generalFunctions.writeInternalEnd(fileOut) generalFunctions.writeInternalStart(fileOut) fileOut.write(' /**\n') fileOut.write( ' * Return the index in the error table with the given errorId. \n') fileOut.write(' *\n') fileOut.write( ' * @param errorId an unsigned intgere representing the errorId of the error in the {0}SBMLErrorTable\n' .format(pkg)) fileOut.write(' *\n') fileOut.write( ' * @return unsigned integer representing the index in the {0}SBMLErrorTable corresponding to the errorId given.\n' .format(pkg)) fileOut.write(' */\n') fileOut.write( ' virtual unsigned int getErrorTableIndex(unsigned int errorId) const;\n\n\n' ) generalFunctions.writeInternalEnd(fileOut) generalFunctions.writeInternalStart(fileOut) fileOut.write(' /**\n') fileOut.write( ' * Return the offset for the errorId range for the {0} L3 package. \n' .format(pkg.lower())) fileOut.write(' *\n') fileOut.write( ' * @return unsigned intege representing the offset for errors {0}SBMLErrorTable.\n' .format(pkg)) fileOut.write(' */\n') fileOut.write(' virtual unsigned int getErrorIdOffset() const;\n\n\n') generalFunctions.writeInternalEnd(fileOut)
def writeClassDefn(fileOut, nameOfClass, pkg, members, attribs, plugin): fileOut.write('class LIBSBML_EXTERN {0} : public SBasePlugin\n'.format(nameOfClass)) fileOut.write('{\npublic:\n\n') writeConstructors(fileOut, nameOfClass, pkg) writeRequiredMethods(fileOut, attribs) writeGetFunctions(fileOut, pkg, members, nameOfClass, attribs) generalFunctions.writeSetDocHeader(fileOut) # TO DO - these properly generalFunctions.writeInternalStart(fileOut) fileOut.write(' virtual void connectToParent (SBase* sbase);\n\n\n') generalFunctions.writeInternalEnd(fileOut) generalFunctions.writeInternalStart(fileOut) fileOut.write(' virtual void enablePackageInternal(const std::string& pkgURI,\n') fileOut.write(' const std::string& pkgPrefix, bool flag);\n\n\n') generalFunctions.writeInternalEnd(fileOut) generalFunctions.writeInternalStart(fileOut) fileOut.write(' virtual bool accept (SBMLVisitor& v) const;\n\n') generalFunctions.writeInternalEnd(fileOut) writeClassEnd(fileOut, members, attribs, plugin)
def writeErrorFunction(fileOut, pkg, nameOfClass, offset): generalFunctions.writeInternalStart(fileOut) fileOut.write('/*\n') fileOut.write(' * Return error table entry. \n') fileOut.write(' */\n') fileOut.write('packageErrorTableEntry\n') fileOut.write('{0}::getErrorTable(unsigned int index) const\n'.format(nameOfClass)) fileOut.write('{\n') fileOut.write(' return {0}ErrorTable[index];\n'.format(pkg.lower())) fileOut.write('}\n\n') generalFunctions.writeInternalEnd(fileOut) generalFunctions.writeInternalStart(fileOut) fileOut.write('/*\n') fileOut.write(' * Return error table index for this id. \n') fileOut.write(' */\n') fileOut.write('unsigned int\n') fileOut.write('{0}::getErrorTableIndex(unsigned int errorId) const\n'.format(nameOfClass)) fileOut.write('{\n') fileOut.write(' unsigned int tableSize = sizeof({0}ErrorTable)/sizeof({0}ErrorTable[0]);\n'.format(pkg.lower())) fileOut.write(' unsigned int index = 0;\n\n') fileOut.write(' for(unsigned int i = 0; i < tableSize; i++)\n') fileOut.write(' {\n') fileOut.write(' if (errorId == {0}ErrorTable[i].code)\n'.format(pkg.lower())) fileOut.write(' {\n') fileOut.write(' index = i;\n') fileOut.write(' break;\n') fileOut.write(' }\n\n') fileOut.write(' }\n\n') fileOut.write(' return index;\n') fileOut.write('}\n\n') generalFunctions.writeInternalEnd(fileOut) generalFunctions.writeInternalStart(fileOut) fileOut.write('/*\n') fileOut.write(' * Return error offset. \n') fileOut.write(' */\n') fileOut.write('unsigned int\n') fileOut.write('{0}::getErrorIdOffset() const\n'.format(nameOfClass)) fileOut.write('{\n') fileOut.write(' return {0};\n'.format(offset)) fileOut.write('}\n\n') generalFunctions.writeInternalEnd(fileOut)
def writeClassDefn(fileOut, nameOfClass, pkg, members, attribs, plugin): fileOut.write( 'class LIBSBML_EXTERN {0} : public SBasePlugin\n'.format(nameOfClass)) fileOut.write('{\npublic:\n\n') writeConstructors(fileOut, nameOfClass, pkg) writeRequiredMethods(fileOut, attribs) writeGetFunctions(fileOut, pkg, members, nameOfClass, attribs) generalFunctions.writeSetDocHeader(fileOut) # TO DO - these properly generalFunctions.writeInternalStart(fileOut) fileOut.write(' virtual void connectToParent (SBase* sbase);\n\n\n') generalFunctions.writeInternalEnd(fileOut) generalFunctions.writeInternalStart(fileOut) fileOut.write( ' virtual void enablePackageInternal(const std::string& pkgURI,\n') fileOut.write( ' const std::string& pkgPrefix, bool flag);\n\n\n' ) generalFunctions.writeInternalEnd(fileOut) generalFunctions.writeInternalStart(fileOut) fileOut.write(' virtual bool accept (SBMLVisitor& v) const;\n\n') generalFunctions.writeInternalEnd(fileOut) writeClassEnd(fileOut, members, attribs, plugin)
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 createValidatorFile(pkg, classes): inputFile = os.path.dirname(__file__) + '/templateValidCPP.txt' fileName = pkg + 'Validator.cpp' output = open(fileName, 'w') nameOfElement = pkg + 'Validator' fileHeaders.addFilename(output, fileName, nameOfElement) fileHeaders.addLicence(output) output.write('#include <sbml/validator/VConstraint.h>\n\n') output.write('#include <sbml/packages/{0}/common/{1}ExtensionTypes.h>\n'.format(pkg.lower(), pkg)) output.write('#include <sbml/packages/{0}/validator/{1}Validator.h>\n\n'.format(pkg.lower(), pkg)) generalFunctions.writeInternalStart(output) output.write('using namespace std;\n\n') generalFunctions.writeInternalEnd(output) output.write('LIBSBML_CPP_NAMESPACE_BEGIN\n\n') input = open(inputFile, 'r') for line in input: if line[0:13] != 'TEMPLATE_STOP': line = replaceTags(line, pkg) output.write(line) else: break for i in range (0, len(classes)): if classes[i]['typecode'] != 'HACK': output.write(' ConstraintSet<{0}> m{0};\n'.format(classes[i]['name'])) for line in input: if line[0:13] != 'TEMPLATE_STOP': line = replaceTags(line, pkg) output.write(line) else: break for i in range (0, len(classes)): if classes[i]['typecode'] != 'HACK': output.write(' if (dynamic_cast< TConstraint<{0}>* >(c) != NULL)\n'.format(classes[i]['name'])) output.write(' {\n') output.write(' m{0}.add( static_cast< TConstraint<{0}>* >(c) );\n'.format(classes[i]['name'])) output.write(' return;\n }\n\n') for line in input: if line[0:13] != 'TEMPLATE_STOP': line = replaceTags(line, pkg) output.write(line) else: break for i in range (0, len(classes)): if classes[i]['typecode'] != 'HACK': output.write(' bool visit (const {0} &x)\n'.format(classes[i]['name'])) output.write(' {\n') output.write(' v.m{0}Constraints->m{1}.applyTo(m, x);\n'.format(pkg, classes[i]['name'])) output.write(' return !v.m{0}Constraints->m{1}.empty();\n'.format(pkg, classes[i]['name'])) output.write(' }\n\n') output.write(' virtual bool visit(const SBase &x)\n') output.write(' {\n') output.write(' if (x.getPackageName() != "{0}")\n'.format(pkg.lower())) output.write(' {\n return SBMLVisitor::visit(x);\n }\n\n') output.write(' int code = x.getTypeCode();\n\n') output.write(' const ListOf* list = dynamic_cast<const ListOf*>(&x);\n\n') output.write(' if (list != NULL)\n') output.write(' {\n') output.write(' return SBMLVisitor::visit(x);\n') output.write(' }\n') output.write(' else\n') output.write(' {\n') order = 0 for i in range (0, len(classes)): if classes[i]['typecode'] != 'HACK': if order == 0: output.write(' if (code == {0})\n'.format(classes[i]['typecode'])) order = order + 1 else: output.write(' else if (code == {0})\n'.format(classes[i]['typecode'])) output.write(' {\n') output.write(' return visit((const {0}&)x);\n'.format(classes[i]['name'])) output.write(' }\n') for line in input: if line[0:13] != 'TEMPLATE_STOP': line = replaceTags(line, pkg) output.write(line) else: break input.close() output.close()
def writeClassEnd(fileOut): fileOut.write('protected:\n\n') generalFunctions.writeInternalStart(fileOut) generalFunctions.writeInternalEnd(fileOut) fileOut.write('};\n\n\n')
def writeErrorTableEnd(fileOut, element): fileOut.write('};\n\n') fileOut.write('\nLIBSBML_CPP_NAMESPACE_END\n\n') generalFunctions.writeInternalEnd(fileOut) fileOut.write('#endif /* {0}_h__ */\n\n'.format(element))