def writeAttributeFunctions(attrs, output, element, elementDict): for i in range(0, len(attrs)): writeGetFunction(attrs[i], output, element) for i in range(0, len(attrs)): writeIsSetFunction(attrs[i], output, element) for i in range(0, len(attrs)): writeSetFunction(attrs[i], output, element) for i in range(0, len(attrs)): writeUnsetFunction(attrs[i], output, element) for i in range(0, len(attrs)): if attrs[i]['type'] == 'lo_element' or attrs[i]['type'] == 'inline_lo_element': writeListOfSubFunctions(attrs[i], output, element, elementDict) if elementDict.has_key('abstract'): if elementDict['abstract']: concretes = generalFunctions.getConcretes(elementDict['root'], elementDict['concrete']) for i in range(0, len(concretes)): concrete = concretes[i] # write output.write(' /**\n') output.write(' * Returns @c true, if this abstract \"{0}\"'.format(element)) output.write(' is of type {0}.\n'.format(concrete['element'])) output.write(' *\n') output.write(' * @return @c true, if this abstract \"{0}\"'.format(element)) output.write(' is of type {0}.\n'.format(concrete['element'])) output.write(' *\n') output.write(' */\n') output.write(' virtual bool is{0}() const;\n\n\n'.format(concrete['element']))
def writeAttributeCode(attrs, output, element, pkgName, elementDict): for i in range(0, len(attrs)): if attrs[i]['type'] != 'lo_element' and attrs[i]['type'] != 'inline_lo_element': writeGetCode(attrs[i], output, element) for i in range(0, len(attrs)): if attrs[i]['type'] != 'lo_element' and attrs[i]['type'] != 'inline_lo_element': writeIsSetCode(attrs[i], output, element) for i in range(0, len(attrs)): if attrs[i]['type'] != 'lo_element' and attrs[i]['type'] != 'inline_lo_element': writeSetCode(attrs[i], output, element) for i in range(0, len(attrs)): writeUnsetCode(attrs[i], output, element) for i in range(0, len(attrs)): if attrs[i]['type'] == 'lo_element' or attrs[i]['type'] == 'inline_lo_element': writeListOfSubFunctions(attrs[i], output, element, pkgName) if elementDict.has_key('abstract'): if elementDict['abstract']: concretes = generalFunctions.getConcretes(elementDict['root'], elementDict['concrete']) for i in range(0, len(concretes)): concrete = concretes[i] output.write('/*\n') output.write(' * Return @c true if of type {0}.\n'.format(concrete['element'])) output.write(' */\n') output.write('bool\n') output.write('{0}::is{1}() const\n'.format(element, concrete['element'])) output.write('{\n') output.write(' return dynamic_cast<const {0}*>(this) != NULL;\n'.format(concrete['element'])) output.write('}\n\n\n')
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 writeIncludesForDict(fileOut, pkg, elementDict): if elementDict.has_key('concrete'): fileOut.write('\n') for elem in generalFunctions.getConcretes(elementDict['root'], elementDict['concrete']): fileOut.write('#include <sbml/packages/{0}/sbml/{1}.h>\n'.format(pkg.lower(), elem['element'])) fileOut.write('\n') if elementDict.has_key('attribs'): attribs = elementDict['attribs'] for i in range(0, len(attribs)): writeIncludesForDict(fileOut, pkg, attribs[i])
def writeIncludes(fileOut, element, pkg, attribs, elementDict): baseClass = 'SBase' if elementDict.has_key('baseClass') and elementDict['baseClass'] != None: baseClass = elementDict['baseClass'] 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('#include <sbml/common/sbmlfwd.h>\n') fileOut.write('#include <sbml/packages/{0}/common/{0}fwd.h>\n'.format(pkg.lower())) fileOut.write('\n\n'); fileOut.write('#ifdef __cplusplus\n') fileOut.write('\n\n'); fileOut.write('#include <string>\n') fileOut.write('\n\n'); fileOut.write('#include <sbml/SBase.h>\n') fileOut.write('#include <sbml/ListOf.h>\n') fileOut.write('#include <sbml/packages/{0}/extension/{1}Extension.h>\n'.format(pkg.lower(), pkg)) if baseClass != 'SBase': fileOut.write('#include <sbml/packages/{0}/sbml/{1}.h>\n'.format(pkg.lower(), baseClass)) fileOut.write('\n') for i in range (0, len(attribs)): current = attribs[i] if (current['type'] == 'element' or current['type'] == 'lo_element' or current['type'] == 'inline_lo_element') and current['name'] != 'math': if current['type'] != 'element': fileOut.write('#include <sbml/packages/{0}/sbml/{1}.h>\n'.format(pkg.lower(), strFunctions.cap(attribs[i]['element']))) else: fileOut.write('#include <sbml/packages/{0}/sbml/{1}.h>\n'.format(pkg.lower(), strFunctions.cap(attribs[i]['element']))) fileOut.write('\nLIBSBML_CPP_NAMESPACE_BEGIN\n\n') if elementDict.has_key('concrete'): for elem in generalFunctions.getConcretes(elementDict['root'], elementDict['concrete']): fileOut.write('class {0};\n'.format(elem['element'])) fileOut.write('\n') fileOut.write('\n\n');
def writeListOfSubElements(attrib, output, element): loname = generalFunctions.getListOfClassName(attrib,strFunctions.cap(attrib['element'])) output.write('LIBSBML_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'.format(attrib['element'], strFunctions.objAbbrev(attrib['element']))) output.write('{\n') output.write('\treturn ({0} != NULL) ? {0}->add{1}({2}) : LIBSBML_INVALID_OBJECT;\n'.format(strFunctions.objAbbrev(element),strFunctions.cap(attrib['name']),strFunctions.objAbbrev(attrib['element']))) output.write('}\n\n') if attrib.has_key('abstract') == False or (attrib.has_key('abstract') and attrib['abstract'] == False): output.write('LIBSBML_EXTERN\n') output.write('{0}_t *\n'.format(attrib['element'])) output.write('{0}_create{1}({0}_t * {2})\n' .format(element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write('{\n') output.write('\treturn ({0} != NULL) ? {0}->create{1}() : NULL;\n'.format(strFunctions.objAbbrev(element),strFunctions.cap(attrib['name']))) output.write('}\n\n') elif attrib.has_key('concrete') and attrib.has_key('root'): for elem in generalFunctions.getConcretes(attrib['root'], attrib['concrete']): output.write('LIBSBML_EXTERN\n') output.write('{0}_t *\n'.format(elem['element'])) output.write('{0}_create{1}({0}_t * {2})\n' .format(element, strFunctions.cap(elem['name']), strFunctions.objAbbrev(element))) output.write('{\n') output.write('\treturn ({0} != NULL) ? {0}->create{1}() : NULL;\n'.format(strFunctions.objAbbrev(element),strFunctions.cap(elem['name']))) output.write('}\n\n') output.write('LIBSBML_EXTERN\n') output.write('ListOf_t *\n') output.write('{0}_get{1}({0}_t * {2})\n'.format(element, loname, strFunctions.objAbbrev(element))) output.write('{\n') output.write('\treturn ({0} != NULL) ? (ListOf_t *){0}->getListOf{1}() : NULL;\n'.format(strFunctions.objAbbrev(element),strFunctions.capp(attrib['name']))) output.write('}\n\n') output.write('LIBSBML_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') output.write('{\n') output.write('\treturn ({0} != NULL) ? {0}->get{1}(n) : NULL;\n'.format(strFunctions.objAbbrev(element),strFunctions.cap(attrib['name']))) output.write('}\n\n') output.write('LIBSBML_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') output.write('{\n') output.write('\treturn ({0} != NULL) ? {0}->get{1}(sid) : NULL;\n'.format(strFunctions.objAbbrev(element),strFunctions.cap(attrib['name']))) output.write('}\n\n') output.write('LIBSBML_EXTERN\n') output.write('unsigned int\n') output.write('{0}_getNum{1}({0}_t * {2})\n' .format(element, strFunctions.capp(attrib['name']), strFunctions.objAbbrev(element))) output.write('{\n') output.write('\treturn ({0} != NULL) ? {0}->getNum{1}() : SBML_INT_MAX;\n'.format(strFunctions.objAbbrev(element),strFunctions.capp(attrib['name']))) output.write('}\n\n') output.write('LIBSBML_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') output.write('{\n') output.write('\treturn ({0} != NULL) ? {0}->remove{1}(n) : NULL;\n'.format(strFunctions.objAbbrev(element),strFunctions.cap(attrib['name']))) output.write('}\n\n') output.write('LIBSBML_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') output.write('{\n') output.write('\treturn ({0} != NULL) ? {0}->remove{1}(sid) : NULL;\n'.format(strFunctions.objAbbrev(element),strFunctions.cap(attrib['name']))) output.write('}\n\n')
def writeGetFunction(attrib, output, element): att = generalFunctions.parseAttributeForC(attrib) attName = att[0] capAttName = att[1] attType = att[2] if att[3] == 'const char *': attTypeCode = 'const char *' else: attTypeCode = att[3] num = att[4] if attrib['type'] == 'lo_element' or attrib['type'] == 'inline_lo_element': return if attrib['type'] == 'array': return varname = strFunctions.objAbbrev(element) if attrib['type'] == 'std::vector<double>': return elif attrib['type'] != 'element' and attrib['type'] != 'lo_element' and attrib['type'] != 'inline_lo_element' and attrib['type'] != 'XMLNode*': output.write('LIBSBML_EXTERN\n') output.write('{0}\n'.format(attTypeCode)) output.write('{0}_get{1}'.format(element, capAttName)) output.write('(const {0}_t * {1})\n'.format(element, varname)) output.write('{\n') if attType == 'string': output.write('\treturn ({0} != NULL && {0}->isSet{1}()) ? {0}->get{1}().c_str() : NULL;\n'.format(varname, capAttName)) # output.write('\tif ({0} == NULL)\n'.format(varname)) # output.write('\t\treturn NULL;\n\n') # output.write('\treturn {0}->get{1}().empty() ? NULL : safe_strdup({0}->get{1}().c_str());\n'.format(varname, capAttName)) elif attType == 'boolean': output.write('\treturn ({0} != NULL) ? static_cast<int>({0}->get{1}()) : 0;\n'.format(varname, capAttName)) elif num == True: if attTypeCode == 'double': output.write('\treturn ({0} != NULL) ? {0}->get{1}() : numeric_limits<double>::quiet_NaN();\n'.format(varname, capAttName)) else: output.write('\treturn ({0} != NULL) ? {0}->get{1}() : SBML_INT_MAX;\n'.format(varname, capAttName)) elif attrib['type'] == 'array': output.write('\treturn ({0} != NULL) ? {0}->get{1}() : NULL;\n'.format(varname, capAttName)) elif attrib['type'] == 'enum': output.write('\treturn ({0} != NULL) ? {0}->get{1}() : {2}_UNKNOWN;\n'.format(varname, capAttName, attrib['element'].upper())) output.write('}\n\n\n') elif attrib['type'] == 'XMLNode*': output.write('LIBSBML_EXTERN\n') output.write('XMLNode_t*\n') output.write('{0}_get{1}'.format(element, capAttName)) output.write('({0}_t * {1})\n'.format(element, varname)) output.write('{\n') output.write('\tif ({0} == NULL)\n'.format(varname)) output.write('\t\treturn NULL;\n\n') output.write('\treturn ({0}_t*){1}->get{2}();\n'.format('XMLNode',varname, capAttName)) output.write('}\n\n\n') elif attrib['type'] == 'element': if attrib['name'] == 'Math' or attrib['name'] == 'math': output.write('LIBSBML_EXTERN\n') output.write('const ASTNode_t*\n') output.write('{0}_get{1}'.format(element, capAttName)) output.write('(const {0}_t * {1})\n'.format(element, varname)) output.write('{\n') output.write('\tif ({0} == NULL)\n'.format(varname)) output.write('\t\treturn NULL;\n\n') output.write('\treturn (ASTNode_t*)({0}->get{1}());\n'.format(varname, capAttName)) output.write('}\n\n\n') else: output.write('LIBSBML_EXTERN\n') output.write('{0}_t*\n'.format(attrib['element'])) output.write('{0}_get{1}'.format(element, capAttName)) output.write('({0}_t * {1})\n'.format(element, varname)) output.write('{\n') output.write('\tif ({0} == NULL)\n'.format(varname)) output.write('\t\treturn NULL;\n\n') output.write('\treturn ({0}_t*){1}->get{2}();\n'.format(attrib['element'],varname, capAttName)) output.write('}\n\n\n') if attrib.has_key('abstract') == False or (attrib.has_key('abstract') and attrib['abstract'] == False): output.write('LIBSBML_EXTERN\n') output.write('{0}_t*\n'.format(attrib['element'])) output.write('{0}_create{1}'.format(element, capAttName)) output.write('({0}_t * {1})\n'.format(element, varname)) output.write('{\n') output.write('\tif ({0} == NULL)\n'.format(varname)) output.write('\t\treturn NULL;\n\n') output.write('\treturn ({0}_t*){1}->create{2}();\n'.format(attrib['element'],varname, capAttName)) output.write('}\n\n\n') elif attrib.has_key('concrete') and attrib.has_key('root'): for elem in generalFunctions.getConcretes(attrib['root'], attrib['concrete']): output.write('LIBSBML_EXTERN\n') output.write('{0}_t *\n'.format(elem['element'])) output.write('{0}_create{1}({0}_t * {2})\n' .format(element, strFunctions.cap(elem['name']), strFunctions.objAbbrev(element))) output.write('{\n') output.write('\treturn ({0} != NULL) ? {0}->create{1}() : NULL;\n'.format(strFunctions.objAbbrev(element),strFunctions.cap(elem['name']))) output.write('}\n\n')
def writeGetFunction(attrib, output, element): att = generalFunctions.parseAttributeForC(attrib) attName = att[0] capAttName = att[1] attType = att[2] if att[3] == "const char *": attTypeCode = "const char *" else: attTypeCode = att[3] num = att[4] type = attrib["type"] if type != "element" and type != "lo_element" and type != "XMLNode*" and type != "inline_lo_element": output.write("/**\n") output.write(' * Returns the value of the "{0}" attribute of the given {1}_t\n'.format(attName, element)) output.write(" * structure.\n *\n") output.write(" * @param {0} the {1}_t structure.\n *\n".format(strFunctions.objAbbrev(element), element)) output.write(" * @return the {0} of this structure.\n *\n".format(attName)) output.write(" * @member of {0}_t\n".format(element)) output.write(" */\n") output.write("LIBSBML_EXTERN\n") output.write("{0}\n".format(attTypeCode)) output.write("{0}_get{1}".format(element, capAttName)) output.write("(const {0}_t * {1});\n\n\n".format(element, strFunctions.objAbbrev(element))) elif type == "XMLNode*": output.write("LIBSBML_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 type == "element": if attrib["name"] == "Math" or attrib["name"] == "math": output.write("/**\n") output.write(" * Gets the mathematical expression of this {0}_t structure as an\n".format(element)) output.write(" * ASTNode_t structure.\n *\n") output.write(" * @param {0} the {1}_t structure.\n *\n".format(strFunctions.objAbbrev(element), element)) output.write(" * @return the math for this {0}_t, as an ASTNode_t.\n *\n".format(element)) output.write(" * @member of {0}_t\n".format(element)) output.write(" */\n") output.write("LIBSBML_EXTERN\n") output.write("const ASTNode_t*\n") output.write("{0}_getMath".format(element)) output.write("(const {0}_t * {1});\n\n\n".format(element, strFunctions.objAbbrev(element))) else: output.write("LIBSBML_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))) if attrib.has_key("abstract") == False or (attrib.has_key("abstract") and attrib["abstract"] == False): output.write("LIBSBML_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))) else: for elem in generalFunctions.getConcretes(attrib["root"], attrib["concrete"]): output.write("LIBSBML_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")
def writeListOfSubElements(attrib, output, element): loname = generalFunctions.getListOfClassName(attrib, strFunctions.cap(attrib["element"])) output.write("LIBSBML_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("LIBSBML_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") and attrib.has_key("root"): for elem in generalFunctions.getConcretes(attrib["root"], attrib["concrete"]): output.write("LIBSBML_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("LIBSBML_EXTERN\n") output.write("ListOf_t *\n") output.write("{0}_get{1}({0}_t * {2}) ".format(element, loname, strFunctions.objAbbrev(element))) output.write(";\n\n\n") output.write("LIBSBML_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("LIBSBML_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("LIBSBML_EXTERN\n") output.write("unsigned int\n") output.write( "{0}_getNum{1}({0}_t * {2}".format(element, strFunctions.capp(attrib["name"]), strFunctions.objAbbrev(element)) ) output.write(");\n\n\n") output.write("LIBSBML_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("LIBSBML_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 writeListOfSubFunctions(attrib, output, element, pkgName): lotype = generalFunctions.getListOfClassName(attrib, strFunctions.cap(attrib['element'])) loname = generalFunctions.writeListOf(strFunctions.cap(attrib['name'])) att = generalFunctions.parseAttribute(attrib) attName = att[0] capAttName = att[1] attType = att[2] attTypeCode = att[3] num = att[4] output.write('/*\n') output.write(' * Returns the \"{0}\"'.format(lotype)) output.write(' in this {0} object.\n'.format(element)) output.write(' */\n') output.write('const {0}*\n'.format(lotype)) output.write('{0}::get{1}() const\n'.format(element, loname)) output.write('{\n') output.write(' return &m{0};\n'.format(strFunctions.capp(attName))) output.write('}\n\n\n') output.write('/*\n') output.write(' * Returns the \"{0}\"'.format(lotype)) output.write(' in this {0} object.\n'.format(element)) output.write(' */\n') output.write('{0}*\n'.format(lotype)) output.write('{0}::get{1}()\n'.format(element, loname)) output.write('{\n') output.write(' return &m{0};\n'.format(strFunctions.capp(attName))) output.write('}\n\n\n') writeListOfCode.writeRemoveFunctions(output, strFunctions.cap(attrib['name']), attrib['element'], True, element, capAttName, attrib) writeListOfCode.writeGetFunctions(output, strFunctions.cap(attrib['name']), attrib['element'], True, element, capAttName, attrib) 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 LIBSBML_OPERATION_SUCCESS\n') output.write(' * @li LIBSBML_INVALID_ATTRIBUTE_VALUE\n') output.write(' */\n') output.write('int\n') output.write('{0}::add{1}(const {2}* {3})\n'.format(element, strFunctions.cap(attrib['name']), attrib['element'], strFunctions.objAbbrev(attrib['element']))) output.write('{\n') output.write(' if ({0} == NULL)\n'.format(strFunctions.objAbbrev(attrib['element']))) output.write(' {\n') output.write(' return LIBSBML_OPERATION_FAILED;\n') output.write(' }\n') output.write(' else if ({0}->hasRequiredAttributes() == false)\n'.format(strFunctions.objAbbrev(attrib['element']))) output.write(' {\n') output.write(' return LIBSBML_INVALID_OBJECT;\n') output.write(' }\n') output.write(' else if (getLevel() != {0}->getLevel())\n'.format(strFunctions.objAbbrev(attrib['element']))) output.write(' {\n') output.write(' return LIBSBML_LEVEL_MISMATCH;\n') output.write(' }\n') output.write(' else if (getVersion() != {0}->getVersion())\n'.format(strFunctions.objAbbrev(attrib['element']))) output.write(' {\n') output.write(' return LIBSBML_VERSION_MISMATCH;\n') output.write(' }\n') if not element.endswith('Plugin'): output.write( ' else if (matchesRequiredSBMLNamespacesForAddition(static_cast<const SBase *>({0})) == false)\n'.format( strFunctions.objAbbrev(attrib['element']))) output.write(' {\n') output.write(' return LIBSBML_NAMESPACES_MISMATCH;\n') output.write(' }\n') output.write(' else\n'.format(strFunctions.objAbbrev(attrib['element']))) output.write(' {\n') output.write(' m{0}.append({1});\n'.format(strFunctions.capp(attrib['name']),strFunctions.objAbbrev(attrib['element']))) output.write(' return LIBSBML_OPERATION_SUCCESS;\n') output.write(' }\n') output.write('}\n\n\n') 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\n') output.write('{0}::getNum{1}() const\n'.format(element, strFunctions.capp(attrib['name']))) output.write('{\n') output.write(' return m{0}.size();\n'.format(strFunctions.capp(attrib['name']))) output.write('}\n\n\n') 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(element, 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 {0}* {1})\n'.format(attrib['element'], strFunctions.objAbbrev(attrib['element']))) output.write(' */\n') output.write('{0}*\n'.format(attrib['element'])) output.write('{0}::create{1}()\n'.format(element, strFunctions.cap(attrib['name']))) output.write('{\n') output.write(' {0}* {1} = NULL;\n\n'.format(attrib['element'], strFunctions.objAbbrev(attrib['element']))) output.write(' try\n') output.write(' {\n') output.write(' {0}_CREATE_NS({1}ns, getSBMLNamespaces());\n'.format(pkgName.upper(), pkgName.lower())) output.write( ' {0} = new {1}({2}ns);\n'.format(strFunctions.objAbbrev(attrib['element']), attrib['element'], pkgName.lower())) output.write(' delete {0}ns;\n'.format(pkgName.lower())) output.write(' }\n') output.write(' catch (...)\n') output.write(' {\n') output.write(' /* here we do not create a default object as the level/version must\n') output.write(' * match the parent object\n') output.write(' *\n') output.write(' * do nothing\n') output.write(' */\n') output.write(' }\n\n') output.write(' if({0} != NULL)\n'.format(strFunctions.objAbbrev(attrib['element']))) output.write(' {\n') output.write(' m{0}.appendAndOwn({1});\n'.format(strFunctions.capp(attrib['name']), strFunctions.objAbbrev(attrib['element']))) output.write(' }\n\n') output.write(' return {0};\n'.format(strFunctions.objAbbrev(attrib['element']))) output.write('}\n\n\n') elif attrib.has_key('concrete'): for elem in generalFunctions.getConcretes(attrib['root'], 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(lotype, 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}*)\n'.format(strFunctions.cap(attrib['element']))) output.write(' */\n') output.write('{0}* \n'.format(elem['element'])) output.write('{0}::create{1}()\n'.format(element, strFunctions.cap(elem['name']))) output.write('{\n') output.write(' {0}* {1} = NULL;\n\n'.format(elem['element'], strFunctions.objAbbrev(elem['element']))) output.write(' try\n') output.write(' {\n') output.write(' {0}_CREATE_NS({1}ns, getSBMLNamespaces());\n'.format(pkgName.upper(), pkgName.lower())) output.write( ' {0} = new {1}({2}ns);\n'.format(strFunctions.objAbbrev(elem['element']), elem['element'], pkgName.lower())) output.write(' delete {0}ns;\n'.format(pkgName.lower())) output.write(' }\n') output.write(' catch (...)\n') output.write(' {\n') output.write(' /* here we do not create a default object as the level/version must\n') output.write(' * match the parent object\n') output.write(' *\n') output.write(' * do nothing\n') output.write(' */\n') output.write(' }\n\n') output.write(' if({0} != NULL)\n'.format(strFunctions.objAbbrev(elem['element']))) output.write(' {\n') output.write(' m{0}.appendAndOwn({1});\n'.format(strFunctions.capp(attrib['name']), strFunctions.objAbbrev(elem['element']))) output.write(' }\n\n') output.write(' return {0};\n'.format(strFunctions.objAbbrev(elem['element']))) output.write('}\n\n\n')
def writeCreateObject(code, element, listOf, type, name, pkgName): if element.has_key('abstract') == False or (element.has_key('abstract') and element['abstract'] == False): code.write('/**\n') code.write(' * Creates a new {0} object, adds it to this {1}\n'.format(type, listOf)) code.write(' * {0} and returns the {1} object created. \n'.format(element['name'], type)) code.write(' *\n') code.write(' * @return a new {0} object instance\n'.format(type)) code.write(' *\n') code.write(' * @see add{0}(const {0}* {1})\n'.format(type, strFunctions.objAbbrev(type))) code.write(' */\n') code.write('{0}* \n'.format(type)) code.write('{0}::create{1}()\n'.format(listOf, strFunctions.cap(name))) code.write('{\n') code.write(' {0}* {1} = NULL;\n\n'.format(type, strFunctions.objAbbrev(type))) code.write(' try\n') code.write(' {\n') code.write(' {0}_CREATE_NS({1}ns, getSBMLNamespaces());\n'.format(pkgName.upper(), pkgName.lower())) code.write( ' {0} = new {1}({2}ns);\n'.format(strFunctions.objAbbrev(type), type, pkgName.lower())) code.write(' delete {0}ns;\n'.format(pkgName.lower())) code.write(' }\n') code.write(' catch (...)\n') code.write(' {\n') code.write(' /* here we do not create a default object as the level/version must\n') code.write(' * match the parent object\n') code.write(' *\n') code.write(' * do nothing\n') code.write(' */\n') code.write(' }\n\n') code.write(' if({0} != NULL)\n'.format(strFunctions.objAbbrev(type))) code.write(' {\n') code.write(' appendAndOwn({0});\n'.format(strFunctions.objAbbrev(type))) code.write(' }\n\n') code.write(' return {0};\n'.format(strFunctions.objAbbrev(type))) code.write('}\n\n') elif element.has_key('concrete'): for elem in generalFunctions.getConcretes(element['root'], element['concrete']): code.write('/**\n') code.write(' * Creates a new {0} object, adds it to this {1}\n'.format(elem['element'], listOf)) code.write(' * {0} and returns the {1} object created. \n'.format(elem['name'], elem['element'])) code.write(' *\n') code.write(' * @return a new {0} object instance\n'.format(elem['element'])) code.write(' *\n') code.write(' * @see add{0}(const {1}* {2})\n'.format(strFunctions.cap(elem['name']), type, strFunctions.objAbbrev(type))) code.write(' */\n') code.write('{0}* \n'.format(elem['element'])) code.write('{0}::create{1}()\n'.format(listOf, strFunctions.cap(elem['name']))) code.write('{\n') code.write(' {0}* {1} = NULL;\n\n'.format(elem['element'], strFunctions.objAbbrev(elem['element']))) code.write(' try\n') code.write(' {\n') code.write(' {0}_CREATE_NS({1}ns, getSBMLNamespaces());\n'.format(pkgName.upper(), pkgName.lower())) code.write( ' {0} = new {1}({2}ns);\n'.format(strFunctions.objAbbrev(elem['element']), elem['element'], pkgName.lower())) code.write(' delete {0}ns;\n'.format(pkgName.lower())) code.write(' }\n') code.write(' catch (...)\n') code.write(' {\n') code.write(' /* here we do not create a default object as the level/version must\n') code.write(' * match the parent object\n') code.write(' *\n') code.write(' * do nothing\n') code.write(' */\n') code.write(' }\n\n') code.write(' if({0} != NULL)\n'.format(strFunctions.objAbbrev(elem['element']))) code.write(' {\n') code.write(' appendAndOwn({0});\n'.format(strFunctions.objAbbrev(elem['element']))) code.write(' }\n\n') code.write(' return {0};\n'.format(strFunctions.objAbbrev(elem['element']))) code.write('}\n\n')
def writeListOfSubFunctions(attrib, output, element, elementDict): lotype = generalFunctions.getListOfClassName(attrib,strFunctions.cap(attrib['element'])) loname = generalFunctions.writeListOf(strFunctions.cap(attrib['name'])) output.write(' /**\n') output.write(' * Returns the \"{0}\"'.format(lotype)) output.write(' in this {0} object.\n'.format(element)) output.write(' *\n') output.write(' * @return the \"{0}\"'.format(lotype)) output.write(' attribute of this {0}.\n'.format(element)) output.write(' */\n') output.write(' const {0}*'.format(lotype)) output.write(' get{0}() const;\n\n\n'.format(loname)) output.write(' /**\n') output.write(' * Returns the \"{0}\"'.format(lotype)) output.write(' in this {0} object.\n'.format(element)) output.write(' *\n') output.write(' * @return the \"{0}\"'.format(lotype)) output.write(' attribute of this {0}.\n'.format(element)) output.write(' */\n') output.write(' {0}*'.format(lotype)) output.write(' get{0}();\n\n\n'.format(loname)) writeListOfHeader.writeGetFunctions(output, strFunctions.cap(attrib['name']), attrib['element'], True, element, attrib) 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 LIBSBML_OPERATION_SUCCESS\n') output.write(' * @li LIBSBML_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}() const;\n\n\n'.format(strFunctions.capp(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(lotype, 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 generalFunctions.getConcretes(attrib['root'], 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(lotype, 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,attrib)
def writeGetCode(attrib, output, element): att = generalFunctions.parseAttribute(attrib) attName = att[0] capAttName = att[1] attType = att[2] attTypeCode = att[3] if attType == 'lo_element' or attType == 'inline_lo_element': return if attrib['type'] == 'array': output.write('/*\n'); output.write(' * The "{0}" attribute of this {1} is returned in an {2} array (pointer)\n'.format(attName, element, attTypeCode)); output.write(' * that is passed as argument to the method (this is needed while using SWIG to\n'); output.write(' * convert int[] from C++ to Java). The method itself has a return type void.\n'); output.write(' *\n'); output.write(' * NOTE: you have to pre-allocate the array with the correct length!'); output.write(' *\n'); output.write(' * @return void.\n'); output.write(' */\n'); output.write('void\n{0}::get{1}({2} outArray) const\n'.format(element,capAttName, attTypeCode)); output.write('{\n'); output.write(' if (outArray == NULL || m{0} == NULL) return;\n\n'.format(capAttName)) output.write(' memcpy(outArray , m{0}, sizeof({1})*m{0}Length);\n'.format(capAttName, attrib['element'])); output.write('}\n\n\n'); return output.write('/*\n') output.write(' * Returns the value of the \"{0}\"'.format(attName)) output.write(' attribute of this {0}.\n'.format(element)) output.write(' */\n') if attType == 'element' and attTypeCode != 'const ASTNode*': output.write('const {0}\n'.format(attTypeCode)) else: output.write('{0}\n'.format(attTypeCode)) output.write('{0}::get{1}() const\n'.format(element, capAttName)) output.write('{\n') output.write(' return m{0};\n'.format(capAttName)) output.write('}\n\n\n') if attType == 'element' and attName != 'math': # return non-const elements as well output.write('/*\n') output.write(' * Returns the value of the \"{0}\"'.format(attName)) output.write(' attribute of this {0}.\n'.format(element)) output.write(' */\n') output.write('{0}\n'.format(attTypeCode)) output.write('{0}::get{1}()\n'.format(element, capAttName)) output.write('{\n') output.write(' return m{0};\n'.format(capAttName)) output.write('}\n\n\n') pkgName = attrib['root']['name'] if attrib['abstract'] == False: output.write('/*\n') output.write(' * Creates a new \"{0}\"'.format(attName)) output.write(' element of this {0} and returns it.\n'.format(element)) output.write(' */\n') output.write('{0}\n'.format(attTypeCode)) output.write('{0}::create{1}()\n'.format(element, capAttName)) output.write('{\n') if attName == 'math' or attName == 'Math' or attType == 'XMLNode*': output.write(' if (m{0} != NULL) delete m{0};\n'.format(capAttName)) output.write(' m{0} = new {1}();\n'.format(capAttName, attrib['element'])) output.write(' return m{0};\n'.format(capAttName)) else: output.write(' if (m{0} != NULL) delete m{0};\n'.format(capAttName)) output.write(' {0}_CREATE_NS({1}ns, getSBMLNamespaces());\n'.format(pkgName.upper(), pkgName.lower())) output.write(' m{0} = new {1}({2}ns);\n'.format(capAttName, attrib['element'], pkgName.lower())) if generalFunctions.overridesElementName(attrib): output.write(' m{0}->setElementName("{1}");\n'.format(capAttName, attrib['name'])); output.write(' delete {0}ns;\n'.format(pkgName.lower())) output.write(' connectToChild();\n'.format(pkgName.lower())) output.write(' return m{0};\n'.format(capAttName)) output.write('}\n\n\n') else: for concrete in generalFunctions.getConcretes(attrib['root'], attrib['concrete']): output.write('/*\n') output.write(' * Creates a new \"{0}\"'.format(attName)) output.write(' element of this {0} and returns it.\n'.format(element)) output.write(' */\n') output.write('{0}*\n'.format(concrete['element'])) output.write('{0}::create{1}()\n'.format(element, strFunctions.cap(concrete['name']))) output.write('{\n') output.write(' if (m{0} != NULL) delete m{0};\n'.format(capAttName)) output.write(' {0}_CREATE_NS({1}ns, getSBMLNamespaces());\n'.format(pkgName.upper(), pkgName.lower())) output.write(' m{0} = new {1}({2}ns);\n'.format(capAttName, concrete['element'], pkgName.lower())) if generalFunctions.overridesElementName(concrete): output.write(' m{0}->setElementName("{1}");\n'.format(capAttName, attrib['name'])); output.write(' delete {0}ns;\n'.format(pkgName.lower())) output.write(' connectToChild();\n'.format(pkgName.lower())) output.write(' return static_cast<{0}*>(m{1});\n'.format(concrete['element'], capAttName)) output.write('}\n\n\n')
def writeCreateObject(code, element, listOf, type, name, pkgName): if element.has_key('abstract') == False or (element.has_key('abstract') and element['abstract'] == False): code.write('/**\n') code.write(' * Creates a new {0} object, adds it to this {1}\n'.format( type, listOf)) code.write(' * {0} and returns the {1} object created. \n'.format( element['name'], type)) code.write(' *\n') code.write(' * @return a new {0} object instance\n'.format(type)) code.write(' *\n') code.write(' * @see add{0}(const {0}* {1})\n'.format( type, strFunctions.objAbbrev(type))) code.write(' */\n') code.write('{0}* \n'.format(type)) code.write('{0}::create{1}()\n'.format(listOf, strFunctions.cap(name))) code.write('{\n') code.write(' {0}* {1} = NULL;\n\n'.format( type, strFunctions.objAbbrev(type))) code.write(' try\n') code.write(' {\n') code.write(' {0}_CREATE_NS({1}ns, getSBMLNamespaces());\n'.format( pkgName.upper(), pkgName.lower())) code.write(' {0} = new {1}({2}ns);\n'.format( strFunctions.objAbbrev(type), type, pkgName.lower())) code.write(' delete {0}ns;\n'.format(pkgName.lower())) code.write(' }\n') code.write(' catch (...)\n') code.write(' {\n') code.write( ' /* here we do not create a default object as the level/version must\n' ) code.write(' * match the parent object\n') code.write(' *\n') code.write(' * do nothing\n') code.write(' */\n') code.write(' }\n\n') code.write(' if({0} != NULL)\n'.format(strFunctions.objAbbrev(type))) code.write(' {\n') code.write(' appendAndOwn({0});\n'.format( strFunctions.objAbbrev(type))) code.write(' }\n\n') code.write(' return {0};\n'.format(strFunctions.objAbbrev(type))) code.write('}\n\n') elif element.has_key('concrete'): for elem in generalFunctions.getConcretes(element['root'], element['concrete']): code.write('/**\n') code.write( ' * Creates a new {0} object, adds it to this {1}\n'.format( elem['element'], listOf)) code.write(' * {0} and returns the {1} object created. \n'.format( elem['name'], elem['element'])) code.write(' *\n') code.write(' * @return a new {0} object instance\n'.format( elem['element'])) code.write(' *\n') code.write(' * @see add{0}(const {1}* {2})\n'.format( strFunctions.cap(elem['name']), type, strFunctions.objAbbrev(type))) code.write(' */\n') code.write('{0}* \n'.format(elem['element'])) code.write('{0}::create{1}()\n'.format( listOf, strFunctions.cap(elem['name']))) code.write('{\n') code.write(' {0}* {1} = NULL;\n\n'.format( elem['element'], strFunctions.objAbbrev(elem['element']))) code.write(' try\n') code.write(' {\n') code.write( ' {0}_CREATE_NS({1}ns, getSBMLNamespaces());\n'.format( pkgName.upper(), pkgName.lower())) code.write(' {0} = new {1}({2}ns);\n'.format( strFunctions.objAbbrev(elem['element']), elem['element'], pkgName.lower())) code.write(' delete {0}ns;\n'.format(pkgName.lower())) code.write(' }\n') code.write(' catch (...)\n') code.write(' {\n') code.write( ' /* here we do not create a default object as the level/version must\n' ) code.write(' * match the parent object\n') code.write(' *\n') code.write(' * do nothing\n') code.write(' */\n') code.write(' }\n\n') code.write(' if({0} != NULL)\n'.format( strFunctions.objAbbrev(elem['element']))) code.write(' {\n') code.write(' appendAndOwn({0});\n'.format( strFunctions.objAbbrev(elem['element']))) code.write(' }\n\n') code.write(' return {0};\n'.format( strFunctions.objAbbrev(elem['element']))) code.write('}\n\n')
def writeGetFunction(attrib, output, element): att = generalFunctions.parseAttributeForC(attrib) attName = att[0] capAttName = att[1] attType = att[2] if att[3] == 'const char *': attTypeCode = 'const char *' else: attTypeCode = att[3] num = att[4] type = attrib['type'] if type != 'element' and type != 'lo_element' and type != 'XMLNode*' and type != 'inline_lo_element': output.write('/**\n') output.write( ' * Returns the value of the \"{0}\" attribute of the given {1}_t\n' .format(attName, element)) output.write(' * structure.\n *\n') output.write(' * @param {0} the {1}_t structure.\n *\n'.format( strFunctions.objAbbrev(element), element)) output.write( ' * @return the {0} of this structure.\n *\n'.format(attName)) output.write(' * @member of {0}_t\n'.format(element)) output.write(' */\n') output.write('LIBSBML_EXTERN\n') output.write('{0}\n'.format(attTypeCode)) output.write('{0}_get{1}'.format(element, capAttName)) output.write('(const {0}_t * {1});\n\n\n'.format( element, strFunctions.objAbbrev(element))) elif type == 'XMLNode*': output.write('LIBSBML_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 type == 'element': if attrib['name'] == 'Math' or attrib['name'] == 'math': output.write('/**\n') output.write( ' * Gets the mathematical expression of this {0}_t structure as an\n' .format(element)) output.write(' * ASTNode_t structure.\n *\n') output.write(' * @param {0} the {1}_t structure.\n *\n'.format( strFunctions.objAbbrev(element), element)) output.write( ' * @return the math for this {0}_t, as an ASTNode_t.\n *\n'. format(element)) output.write(' * @member of {0}_t\n'.format(element)) output.write(' */\n') output.write('LIBSBML_EXTERN\n') output.write('const ASTNode_t*\n') output.write('{0}_getMath'.format(element)) output.write('(const {0}_t * {1});\n\n\n'.format( element, strFunctions.objAbbrev(element))) else: output.write('LIBSBML_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))) if attrib.has_key('abstract') == False or ( attrib.has_key('abstract') and attrib['abstract'] == False): output.write('LIBSBML_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))) else: for elem in generalFunctions.getConcretes( attrib['root'], attrib['concrete']): output.write('LIBSBML_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')
def writeListOfSubElements(attrib, output, element): loname = generalFunctions.getListOfClassName( attrib, strFunctions.cap(attrib['element'])) output.write('LIBSBML_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('LIBSBML_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') and attrib.has_key('root'): for elem in generalFunctions.getConcretes(attrib['root'], attrib['concrete']): output.write('LIBSBML_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('LIBSBML_EXTERN\n') output.write('ListOf_t *\n') output.write('{0}_get{1}({0}_t * {2}) '.format( element, loname, strFunctions.objAbbrev(element))) output.write(';\n\n\n') output.write('LIBSBML_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('LIBSBML_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('LIBSBML_EXTERN\n') output.write('unsigned int\n') output.write('{0}_getNum{1}({0}_t * {2}'.format( element, strFunctions.capp(attrib['name']), strFunctions.objAbbrev(element))) output.write(');\n\n\n') output.write('LIBSBML_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('LIBSBML_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 writeGetFunction(attrib, output, element): att = generalFunctions.parseAttribute(attrib) attName = att[0] capAttName = att[1] attType = att[2] attTypeCode = att[3] num = att[4] if attrib['type'] == 'lo_element' or attrib['type'] == 'inline_lo_element': return elif attrib['type'] == 'array': output.write(' /**\n'); output.write(' * The "{0}" attribute of this {1} is returned in an {2} array (pointer)\n'.format(attName, element, attTypeCode)); output.write(' * that is passed as argument to the method (this is needed while using SWIG to\n'); output.write(' * convert int[] from C++ to Java). The method itself has a return type void.\n'); output.write(' *\n'); output.write(' * NOTE: you have to pre-allocate the array with the correct length!'); output.write(' *\n'); output.write(' * @return void.\n'); output.write(' */\n'); output.write(' void get{0}({1} outArray) const;\n\n\n'.format(capAttName, attTypeCode)); elif attrib['type'] == 'element': if attrib['name'] == 'Math' or attrib['name'] == 'math': output.write(' /**\n') output.write(' * Returns the \"{0}\"'.format(attName)) output.write(' element of this {0}.\n'.format(element)) output.write(' *\n') output.write(' * @return the \"{0}\"'.format(attName)) output.write(' element of this {0}.\n'.format(element)) output.write(' */\n') output.write(' virtual const ASTNode*') output.write(' get{0}() const;\n\n\n'.format(capAttName)) else: output.write(' /**\n') output.write(' * Returns the \"{0}\"'.format(attName)) output.write(' element of this {0}.\n'.format(element)) output.write(' *\n') output.write(' * @return the \"{0}\"'.format(attName)) output.write(' element of this {0}.\n'.format(element)) output.write(' */\n') output.write(' virtual const {0}*'.format(attrib['element'])) output.write(' get{0}() const;\n\n\n'.format(capAttName)) output.write(' /**\n') output.write(' * Returns the \"{0}\"'.format(attName)) output.write(' element of this {0}.\n'.format(element)) output.write(' *\n') output.write(' * @return the \"{0}\"'.format(attName)) output.write(' element of this {0}.\n'.format(element)) output.write(' */\n') output.write(' virtual {0}*'.format(attrib['element'])) output.write(' get{0}();\n\n\n'.format(capAttName)) if attrib['abstract'] == False: output.write(' /**\n') output.write(' * Creates a new \"{0}\"'.format(attrib['element'])) output.write(' and sets it for this {0}.\n'.format(element)) output.write(' *\n') output.write(' * @return the created \"{0}\"'.format(attrib['element'])) output.write(' element of this {0}.\n'.format(element)) output.write(' */\n') output.write(' virtual {0}*'.format(attrib['element'])) output.write(' create{0}();\n\n\n'.format(capAttName)) else: for concrete in generalFunctions.getConcretes(attrib['root'], attrib['concrete']): output.write(' /**\n') output.write(' * Creates a new \"{0}\"'.format(attName)) output.write(' and sets it for this {0}.\n'.format(element)) output.write(' */\n') output.write(' virtual {0}*'.format(concrete['element'])) output.write(' create{0}();\n\n\n'.format(strFunctions.cap(concrete['name']))) else: output.write(' /**\n') output.write(' * Returns the value of the \"{0}\"'.format(attName)) output.write(' attribute of this {0}.\n'.format(element)) output.write(' *\n') output.write(' * @return the value of the \"{0}\"'.format(attName)) output.write(' attribute of this {0} as a {1}.\n'.format(element, attType)) output.write(' */\n') output.write(' virtual {0}'.format(attTypeCode)) output.write(' get{0}() const;\n\n\n'.format(capAttName))
def writeClass(header, nameOfElement, typeOfElement, nameOfPackage, elementDict): listOf = generalFunctions.getListOfClassName(elementDict, typeOfElement) header.write('class LIBSBML_EXTERN {0} :'.format(listOf)) header.write(' public ListOf\n{0}\n\n'.format('{')) header.write('public:\n\n') writeConstructors(nameOfElement, typeOfElement, nameOfPackage, header,elementDict) writeGetFunctions(header, nameOfElement, typeOfElement, False, "", elementDict) header.write('\t/**\n') header.write('\t * Adds a copy the given \"{0}\" to this {1}.\n'.format(nameOfElement, listOf)) 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, listOf)) header.write('\t *\n') header.write('\t * @return the number of {0} objects in this {1}\n'.format(nameOfElement, listOf)) header.write('\t */\n') header.write('\tunsigned int getNum{0}() const;\n\n\n'.format(strFunctions.capp(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(listOf, 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 generalFunctions.getConcretes(elementDict['root'], 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(listOf, 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, False, "", elementDict) generalFunctions.writeCommonHeaders(header, typeOfElement, None, True, False, False, elementDict) header.write('protected:\n\n') writeProtectedFunctions(header, nameOfElement, nameOfPackage, elementDict) if elementDict.has_key('concrete'): header.write('\tvirtual bool isValidTypeForList(SBase * item) {\n') header.write('\t\tint code = item->getTypeCode();\n') header.write('\t\treturn code == getItemTypeCode() ') for elem in generalFunctions.getConcretes(elementDict['root'], elementDict['concrete']): typecode = 'SBML_{0}_{1}'.format(nameOfPackage.upper(),elem['element'].upper()) if elem.has_key('root'): concrete = generalFunctions.getElement(elem['root'], elem['element']) if (concrete != None): typecode = concrete['typecode'] header.write('|| code == {0} '.format(typecode)) header.write(';\n') header.write('\t}\n\n\n'); friends = getInlineListOfClasses(elementDict, typeOfElement) for friend in friends: header.write('\tfriend class {0};\n'.format(friend)) header.write('\n};\n\n')
def writeClass(header, nameOfElement, typeOfElement, nameOfPackage, elementDict): listOf = generalFunctions.getListOfClassName(elementDict, typeOfElement) header.write('class LIBSBML_EXTERN {0} :'.format(listOf)) header.write(' public ListOf\n{0}\n\n'.format('{')) header.write('public:\n\n') writeConstructors(nameOfElement, typeOfElement, nameOfPackage, header, elementDict) writeGetFunctions(header, nameOfElement, typeOfElement, False, "", elementDict) header.write('\t/**\n') header.write('\t * Adds a copy the given \"{0}\" to this {1}.\n'.format( nameOfElement, listOf)) 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, listOf)) header.write('\t *\n') header.write('\t * @return the number of {0} objects in this {1}\n'.format( nameOfElement, listOf)) header.write('\t */\n') header.write('\tunsigned int getNum{0}() const;\n\n\n'.format( strFunctions.capp(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( listOf, 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 generalFunctions.getConcretes(elementDict['root'], 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( listOf, 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, False, "", elementDict) generalFunctions.writeCommonHeaders(header, typeOfElement, None, True, False, False, elementDict) header.write('protected:\n\n') writeProtectedFunctions(header, nameOfElement, nameOfPackage, elementDict) if elementDict.has_key('concrete'): header.write('\tvirtual bool isValidTypeForList(SBase * item) {\n') header.write('\t\tint code = item->getTypeCode();\n') header.write('\t\treturn code == getItemTypeCode() ') for elem in generalFunctions.getConcretes(elementDict['root'], elementDict['concrete']): typecode = 'SBML_{0}_{1}'.format(nameOfPackage.upper(), elem['element'].upper()) if elem.has_key('root'): concrete = generalFunctions.getElement(elem['root'], elem['element']) if (concrete != None): typecode = concrete['typecode'] header.write('|| code == {0} '.format(typecode)) header.write(';\n') header.write('\t}\n\n\n') friends = getInlineListOfClasses(elementDict, typeOfElement) for friend in friends: header.write('\tfriend class {0};\n'.format(friend)) header.write('\n};\n\n')
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)