def writeClass(header, nameOfElement, typeOfElement, nameOfPackage, elementDict): header.write('class LIBSEDML_EXTERN {0} :'.format(generalFunctions.writeListOf(nameOfElement))) header.write(' public SedListOf\n{0}\n\n'.format('{')) header.write('public:\n\n') writeConstructors(nameOfElement, typeOfElement, nameOfPackage, header) writeGetFunctions(header, nameOfElement, typeOfElement) header.write(' /**\n') header.write(' * Adds a copy the given \"{0}\" to this {1}.\n'.format(nameOfElement, generalFunctions.writeListOf(nameOfElement))) header.write(' *\n') header.write(' * @param {0}; the {1} object to add\n'.format(strFunctions.objAbbrev(nameOfElement), nameOfElement)) header.write(' *\n') header.write(' * @return integer value indicating success/failure of the\n') header.write(' * function. @if clike The value is drawn from the\n') header.write(' * enumeration #OperationReturnValues_t. @endif The possible values\n') header.write(' * returned by this function are:\n') header.write(' * @li LIBSEDML_OPERATION_SUCCESS\n') header.write(' * @li LIBSEDML_INVALID_ATTRIBUTE_VALUE\n') header.write(' */\n') header.write(' int add{0}(const {1}* {2});\n\n\n'.format(nameOfElement, typeOfElement, strFunctions.objAbbrev(nameOfElement))) header.write(' /**\n') header.write(' * Get the number of {0} objects in this {1}.\n'.format(nameOfElement, generalFunctions.writeListOf(nameOfElement))) header.write(' *\n') header.write(' * @return the number of {0} objects in this {1}\n'.format(nameOfElement, generalFunctions.writeListOf(nameOfElement))) header.write(' */\n') header.write(' unsigned int getNum{0}s() const;\n\n\n'.format(nameOfElement)) if elementDict.has_key('abstract') == False or (elementDict.has_key('abstract') and elementDict['abstract'] == False): header.write(' /**\n') header.write(' * Creates a new {0} object, adds it to the\n'.format(nameOfElement)) header.write(' * {0} and returns the {1} object created.\n'.format(generalFunctions.writeListOf(nameOfElement), nameOfElement)) header.write(' *\n') header.write(' * @return a new {0} object instance\n'.format(nameOfElement)) header.write(' *\n') header.write(' * @see add{0}(const {1}* {2})\n'.format(nameOfElement, typeOfElement, strFunctions.objAbbrev(nameOfElement))) header.write(' */\n') header.write(' {0}* create{1}();\n\n\n'.format(typeOfElement, nameOfElement)) elif elementDict.has_key('concrete'): for elem in elementDict['concrete']: header.write(' /**\n') header.write(' * Creates a new {0} object, adds it to the\n'.format(nameOfElement)) header.write(' * {0} and returns the {1} object created.\n'.format(generalFunctions.writeListOf(nameOfElement), nameOfElement)) header.write(' *\n') header.write(' * @return a new {0} object instance\n'.format(nameOfElement)) header.write(' *\n') header.write(' * @see add{0}(const {1}* {2})\n'.format(nameOfElement, typeOfElement, strFunctions.objAbbrev(nameOfElement))) header.write(' */\n') header.write(' {0}* create{1}();\n\n\n'.format(elem['element'], strFunctions.cap(elem['name']))) writeRemoveFunctions(header, nameOfElement, typeOfElement) generalFunctions.writeCommonHeaders(header, nameOfElement, None, True) header.write('protected:\n\n') writeProtectedFunctions(header, nameOfElement, nameOfPackage) header.write('\n};\n\n')
def writeClass(header, nameOfElement, typeOfElement, nameOfPackage, elementDict): header.write('class LIBSEDML_EXTERN {0} :'.format(generalFunctions.writeListOf(nameOfElement))) header.write(' public SedListOf\n{0}\n\n'.format('{')) header.write('public:\n\n') writeConstructors(nameOfElement, typeOfElement, nameOfPackage, header) writeGetFunctions(header, nameOfElement, typeOfElement) header.write('\t/**\n') header.write('\t * Adds a copy the given \"{0}\" to this {1}.\n'.format(nameOfElement, generalFunctions.writeListOf(nameOfElement))) header.write('\t *\n') header.write('\t * @param {0}; the {1} object to add\n'.format(strFunctions.objAbbrev(nameOfElement), nameOfElement)) header.write('\t *\n') header.write('\t * @return integer value indicating success/failure of the\n') header.write('\t * function. @if clike The value is drawn from the\n') header.write('\t * enumeration #OperationReturnValues_t. @endif The possible values\n') header.write('\t * returned by this function are:\n') header.write('\t * @li LIBSEDML_OPERATION_SUCCESS\n') header.write('\t * @li LIBSEDML_INVALID_ATTRIBUTE_VALUE\n') header.write('\t */\n') header.write('\tint add{0}(const {1}* {2});\n\n\n'.format(nameOfElement, typeOfElement, strFunctions.objAbbrev(nameOfElement))) header.write('\t/**\n') header.write('\t * Get the number of {0} objects in this {1}.\n'.format(nameOfElement, generalFunctions.writeListOf(nameOfElement))) header.write('\t *\n') header.write('\t * @return the number of {0} objects in this {1}\n'.format(nameOfElement, generalFunctions.writeListOf(nameOfElement))) header.write('\t */\n') header.write('\tunsigned int getNum{0}s() const;\n\n\n'.format(nameOfElement)) if elementDict.has_key('abstract') == False or (elementDict.has_key('abstract') and elementDict['abstract'] == False): header.write('\t/**\n') header.write('\t * Creates a new {0} object, adds it to the\n'.format(nameOfElement)) header.write('\t * {0} and returns the {1} object created. \n'.format(generalFunctions.writeListOf(nameOfElement), nameOfElement)) header.write('\t *\n') header.write('\t * @return a new {0} object instance\n'.format(nameOfElement)) header.write('\t *\n') header.write('\t * @see add{0}(const {1}* {2})\n'.format(nameOfElement, typeOfElement, strFunctions.objAbbrev(nameOfElement))) header.write('\t */\n') header.write('\t{0}* create{1}();\n\n\n'.format(typeOfElement, nameOfElement)) elif elementDict.has_key('concrete'): for elem in elementDict['concrete']: header.write('\t/**\n') header.write('\t * Creates a new {0} object, adds it to the\n'.format(nameOfElement)) header.write('\t * {0} and returns the {1} object created. \n'.format(generalFunctions.writeListOf(nameOfElement), nameOfElement)) header.write('\t *\n') header.write('\t * @return a new {0} object instance\n'.format(nameOfElement)) header.write('\t *\n') header.write('\t * @see add{0}(const {1}* {2})\n'.format(nameOfElement, typeOfElement, strFunctions.objAbbrev(nameOfElement))) header.write('\t */\n') header.write('\t{0}* create{1}();\n\n\n'.format(elem['element'], strFunctions.cap(elem['name']))) writeRemoveFunctions(header, nameOfElement, typeOfElement) generalFunctions.writeCommonHeaders(header, nameOfElement, None, True) header.write('protected:\n\n') writeProtectedFunctions(header, nameOfElement, nameOfPackage) header.write('\n};\n\n')
def writeListOfCode(output, element, type): loelement = generalFunctions.writeListOf(element) output.write('/**\n') output.write(' * write comments\n') output.write(' */\n') output.write('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(type)) output.write('{0}_getById'.format(loelement)) output.write('(SedListOf_t * lo, const char * sid)\n') output.write('{\n') output.write('\tif (lo == NULL)\n') output.write('\t\treturn NULL;\n\n') output.write( '\treturn (sid != NULL) ? static_cast <{0} *>(lo)->get(sid) : NULL;\n'. format(loelement)) output.write('}\n\n\n') output.write('/**\n') output.write(' * write comments\n') output.write(' */\n') output.write('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(type)) output.write('{0}_removeById'.format(loelement)) output.write('(SedListOf_t * lo, const char * sid)\n') output.write('{\n') output.write('\tif (lo == NULL)\n') output.write('\t\treturn NULL;\n\n') output.write( '\treturn (sid != NULL) ? static_cast <{0} *>(lo)->remove(sid) : NULL;\n' .format(loelement)) output.write('}\n\n\n')
def writeAtt(attrib, output): att = generalFunctions.parseAttribute(attrib) attName = att[0] capAttName = att[1] attType = att[2] attTypeCode = att[3] num = att[4] if attType == 'string': output.write('\tstd::string m{0};\n'.format(capAttName)) elif attType == 'element': if attTypeCode == 'ASTNode*' or attName== 'Math': output.write('\tASTNode* m{0};\n'.format(capAttName)) else: output.write('\t{0}* m{1};\n'.format(attrib['element'], capAttName)) return elif attType == 'lo_element': output.write('\t{0} m{1};\n'.format(generalFunctions.writeListOf(capAttName), capAttName)) elif num == True: while len(attTypeCode) < 13: attTypeCode = attTypeCode + ' ' output.write('\t{1} m{0};\n'.format(capAttName, attTypeCode)) output.write('\tbool mIsSet{0};\n'.format(capAttName)) elif attType == 'boolean': output.write('\tbool m{0};\n'.format(capAttName)) output.write('\tbool mIsSet{0};\n'.format(capAttName)) else: output.write('\tFIX ME {0};\n'.format(attName))
def writeListOfSubElements(attrib, output, element): loname = generalFunctions.writeListOf(strFunctions.cap(attrib['name'])) output.write('LIBSEDML_EXTERN\n') output.write('int\n') output.write('{0}_add{1}({0}_t * {2}, '.format( element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write('{0}_t * {1});\n\n\n'.format( attrib['element'], strFunctions.objAbbrev(attrib['element']))) if attrib.has_key('abstract') == False or (attrib.has_key('abstract') and attrib['abstract'] == False): output.write('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(attrib['element'])) output.write('{0}_create{1}({0}_t * {2}'.format( element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write(');\n\n\n') elif attrib.has_key('concrete'): for elem in attrib['concrete']: output.write('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(elem['element'])) output.write('{0}_create{1}({0}_t * {2}'.format( element, strFunctions.cap(elem['name']), strFunctions.objAbbrev(element))) output.write(');\n\n\n') output.write('LIBSEDML_EXTERN\n') output.write('SedListOf_t *\n') output.write('{0}_get{1}({0}_t * {2})'.format( element, loname, strFunctions.objAbbrev(element))) output.write(';\n\n\n') output.write('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(attrib['element'])) output.write('{0}_get{1}({0}_t * {2}, '.format( element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write('unsigned int n);\n\n\n') output.write('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(attrib['element'])) output.write('{0}_get{1}ById({0}_t * {2}, '.format( element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write('const char * sid);\n\n\n') output.write('LIBSEDML_EXTERN\n') output.write('unsigned int\n') output.write('{0}_getNum{1}s({0}_t * {2}'.format( element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write(');\n\n\n') output.write('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(attrib['element'])) output.write('{0}_remove{1}({0}_t * {2}, '.format( element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write('unsigned int n);\n\n\n') output.write('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(attrib['element'])) output.write('{0}_remove{1}ById({0}_t * {2}, '.format( element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write('const char * sid);\n\n\n')
def writeAtt(attrib, output): att = generalFunctions.parseAttribute(attrib) attName = att[0] capAttName = att[1] attType = att[2] attTypeCode = att[3] num = att[4] if attType == 'string': output.write(' std::string m{0};\n'.format(capAttName)) elif attType == 'element': if attTypeCode == 'ASTNode*' or attName== 'Math': output.write(' ASTNode* m{0};\n'.format(capAttName)) else: output.write(' {0}* m{1};\n'.format(attrib['element'], capAttName)) return elif attType == 'lo_element': output.write(' {0} m{1};\n'.format(generalFunctions.writeListOf(capAttName), strFunctions.capp(attName))) elif attTypeCode == 'XMLNode*': output.write(' {0} m{1};\n'.format('XMLNode*', capAttName)) elif attTypeCode == 'DimensionDescription*': output.write(' {0} m{1};\n'.format('DimensionDescription*', capAttName)) elif num == True: while len(attTypeCode) < 13: attTypeCode = attTypeCode + ' ' output.write(' {1} m{0};\n'.format(capAttName, attTypeCode)) output.write(' bool mIsSet{0};\n'.format(capAttName)) elif attType == 'boolean': output.write(' bool m{0};\n'.format(capAttName)) output.write(' bool mIsSet{0};\n'.format(capAttName)) elif attType == 'std::vector<double>': output.write(' std::vector<double> m{0};\n'.format( strFunctions.capp(attName))) else: output.write(' FIX ME {0};\n'.format(attName))
def writeConstructors(element, type, package, output): element = generalFunctions.writeListOf(element) indent = strFunctions.getIndent(element) output.write('/*\n' ) output.write(' * Constructor\n') output.write(' */\n') output.write('{0}::{0}(unsigned int level,\n'.format(element)) output.write(' {0}unsigned int version)\n'.format(indent)) output.write(' : SedListOf(level, version)\n') output.write('{\n' ) output.write(' setSedNamespacesAndOwn(new ') output.write('SedNamespaces(level, version));\n') output.write('}\n\n\n') output.write('/*\n' ) output.write(' * Constructor\n') output.write(' */\n') output.write('{0}::{0}(SedNamespaces* {1}ns)\n'.format(element, package.lower())) output.write(' : SedListOf({0}ns)\n'.format(package.lower())) output.write('{\n' ) output.write(' setElementNamespace({0}ns->getURI());\n'.format(package.lower())) output.write('}\n\n\n') output.write('/*\n' ) output.write(' * Returns a deep copy of this {0}\n'.format(element)) output.write(' */\n') output.write('{0}*\n'.format(element)) output.write('{0}::clone () const\n'.format(element)) output.write('{\n' ) output.write(' return new {0}(*this);\n'.format(element)) output.write('}\n\n\n')
def writeListOfCode(output, element, elementDict = None): loelement = generalFunctions.writeListOf(element) loelementClass = generalFunctions.getListOfClassName(elementDict, element) hasId = generalFunctions.hasIdAttribute (elementDict, element) if hasId: output.write('/*\n') output.write(' *\n') output.write(' */\n') output.write('LIBSBML_EXTERN\n') output.write('{0}_t *\n'.format(element)) output.write('{0}_getById'.format(loelementClass)) output.write('(ListOf_t * lo, const char * sid)\n') output.write('{\n') output.write(' if (lo == NULL)\n') output.write(' return NULL;\n\n') output.write(' return (sid != NULL) ? static_cast <{0} *>(lo)->get(sid) : NULL;\n'.format(loelementClass)) output.write('}\n\n\n') output.write('/*\n') output.write(' *\n') output.write(' */\n') output.write('LIBSBML_EXTERN\n') output.write('{0}_t *\n'.format(element)) output.write('{0}_removeById'.format(loelement)) output.write('(ListOf_t * lo, const char * sid)\n') output.write('{\n') output.write(' if (lo == NULL)\n') output.write(' return NULL;\n\n') output.write(' return (sid != NULL) ? static_cast <{0} *>(lo)->remove(sid) : NULL;\n'.format(loelementClass)) output.write('}\n\n\n')
def writeListOfCode(output, element, type): loelement = generalFunctions.writeListOf(element) output.write('/**\n') output.write(' * write comments\n') output.write(' */\n') output.write('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(type)) output.write('{0}_getById'.format(loelement)) output.write('(SedListOf_t * lo, const char * sid)\n') output.write('{\n') output.write('\tif (lo == NULL)\n') output.write('\t\treturn NULL;\n\n') output.write('\treturn (sid != NULL) ? static_cast <{0} *>(lo)->get(sid) : NULL;\n'.format(loelement)) output.write('}\n\n\n') output.write('/**\n') output.write(' * write comments\n') output.write(' */\n') output.write('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(type)) output.write('{0}_removeById'.format(loelement)) output.write('(SedListOf_t * lo, const char * sid)\n') output.write('{\n') output.write('\tif (lo == NULL)\n') output.write('\t\treturn NULL;\n\n') output.write('\treturn (sid != NULL) ? static_cast <{0} *>(lo)->remove(sid) : NULL;\n'.format(loelement)) output.write('}\n\n\n')
def writeRemoveFunctions(output, element, type, subelement=False, topelement="", name=""): listOf = generalFunctions.writeListOf(element) output.write('/*\n') if subelement == True: output.write(' * Removes the nth {0} from the {1}.\n'.format( element, listOf)) output.write(' */\n') output.write('{0}*\n'.format(type)) output.write('{0}::remove{1}(unsigned int n)\n'.format( topelement, element)) output.write('{\n') output.write(' return m{0}.remove(n);\n'.format( strFunctions.capp(name))) output.write('}\n\n\n') else: output.write(' * Removes the nth {0} from this {1}\n'.format( element, listOf)) output.write(' */\n') output.write('{0}*\n{1}::remove(unsigned int n)\n'.format( type, listOf)) output.write('{\n') output.write( ' return static_cast<{0}*>(SedListOf::remove(n));\n'.format(type)) output.write('}\n\n\n') output.write('/*\n') if subelement == True: output.write( ' * Removes the a {0} with given id from the {1}.\n'.format( element, listOf)) output.write(' */\n') output.write('{0}*\n'.format(type)) output.write('{0}::remove{1}(const std::string& sid)\n'.format( topelement, element)) output.write('{\n') output.write(' return m{0}.remove(sid);\n'.format( strFunctions.capp(name))) output.write('}\n\n\n') else: output.write( ' * Removes the {0} from this {1} with the given identifier\n'. format(element, listOf)) output.write(' */\n') output.write('{0}*\n{1}::remove(const std::string& sid)\n'.format( type, listOf)) output.write('{\n') output.write(' SedBase* item = NULL;\n') output.write(' vector<SedBase*>::iterator result;\n\n') output.write( ' result = find_if( mItems.begin(), mItems.end(), SedIdEq<{0}>(sid) );\n\n' .format(type)) output.write(' if (result != mItems.end())\n {\n') output.write(' item = *result;\n') output.write(' mItems.erase(result);\n }\n\n') output.write(' return static_cast <{0}*> (item);\n'.format(type)) output.write('}\n\n\n')
def writeConstructors(element, type, package, output): element = generalFunctions.writeListOf(element) indent = strFunctions.getIndent(element) output.write('/*\n') output.write(' * Constructor\n') output.write(' */\n') output.write('{0}::{0}(unsigned int level,\n'.format(element)) output.write(' {0}unsigned int version)\n'.format(indent)) output.write(' : SedListOf(level, version)\n') output.write('{\n') output.write(' setSedNamespacesAndOwn(new ') output.write('SedNamespaces(level, version));\n') output.write('}\n\n\n') output.write('/*\n') output.write(' * Constructor\n') output.write(' */\n') output.write('{0}::{0}(SedNamespaces* {1}ns)\n'.format( element, package.lower())) output.write(' : SedListOf({0}ns)\n'.format(package.lower())) output.write('{\n') output.write(' setElementNamespace({0}ns->getURI());\n'.format( package.lower())) output.write('}\n\n\n') output.write('/*\n') output.write(' * Returns a deep copy of this {0}\n'.format(element)) output.write(' */\n') output.write('{0}*\n'.format(element)) output.write('{0}::clone () const\n'.format(element)) output.write('{\n') output.write(' return new {0}(*this);\n'.format(element)) output.write('}\n\n\n')
def writeAtt(attrib, output): att = generalFunctions.parseAttribute(attrib) attName = att[0] capAttName = att[1] attType = att[2] attTypeCode = att[3] num = att[4] if attType == 'string': output.write('\tstd::string m{0};\n'.format(capAttName)) elif attType == 'element': if attTypeCode == 'ASTNode*' or attName == 'Math': output.write('\tASTNode* m{0};\n'.format(capAttName)) else: output.write('\t{0}* m{1};\n'.format(attrib['element'], capAttName)) return elif attType == 'lo_element': output.write('\t{0} m{1};\n'.format( generalFunctions.writeListOf(capAttName), capAttName)) elif num == True: while len(attTypeCode) < 13: attTypeCode = attTypeCode + ' ' output.write('\t{1} m{0};\n'.format(capAttName, attTypeCode)) output.write('\tbool mIsSet{0};\n'.format(capAttName)) elif attType == 'boolean': output.write('\tbool m{0};\n'.format(capAttName)) output.write('\tbool mIsSet{0};\n'.format(capAttName)) else: output.write('\tFIX ME {0};\n'.format(attName))
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 writeListOfHeaders(output, element, type): loelement = generalFunctions.writeListOf(element) output.write('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(type)) output.write('{0}_getById'.format(loelement)) output.write('(SedListOf_t * lo, const char * sid);\n\n\n') output.write('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(type)) output.write('{0}_removeById'.format(loelement)) output.write('(SedListOf_t * lo, const char * sid);\n\n\n')
def writeConstructors(element, type, package, output): element = generalFunctions.writeListOf(element) indent = strFunctions.getIndent(element) output.write(' /**\n * ') output.write('Creates a new {0}'.format(element)) output.write(' with the given level, version, and package version.\n') output.write(' *\n') output.write( ' * @param level an unsigned int, the SEDML Level to assign') output.write(' to this {0}\n'.format(element)) output.write(' *\n') output.write( ' * @param version an unsigned int, the SEDML Version to assign') output.write(' to this {0}\n'.format(element)) output.write(' *\n') output.write( ' * @param pkgVersion an unsigned int, the SEDML {0} Version to assign' .format(package)) output.write(' to this {0}\n */\n'.format(element)) output.write(' {0}(unsigned int level = '.format(element)) output.write('SEDML_DEFAULT_LEVEL,\n') output.write(' {0}unsigned int version = '.format(indent)) output.write('SEDML_DEFAULT_VERSION\n') output.write(');\n\n\n'.format(package)) output.write(' /**\n * ') output.write('Creates a new {0}'.format(element)) output.write(' with the given SedNamespaces object.\n') output.write(' *\n') output.write(' * @param {0}ns the SedNamespaces object'.format( package.lower(), package)) output.write('\n */\n') output.write(' {0}(SedNamespaces* {1}ns);\n\n\n'.format( element, package.lower())) # output.write(' /**\n * ' ) # output.write('Copy constructor for {0}.\n'.format(element)) # output.write(' *\n') # output.write(' * @param orig; the {0} instance to copy.\n'.format(element)) # output.write(' */\n') # output.write(' {0}(const {1}& orig);\n\n\n'.format(element, element)) # output.write(' /**\n * ' ) # output.write('Assignment operator for {0}.\n'.format(element)) # output.write(' *\n') # output.write(' * @param rhs; the object whose values are used as the basis\n') # output.write(' * of the assignment\n */\n') # output.write(' {0}& operator=(const {1}& rhs);\n\n\n'.format(element, element)) output.write(' /**\n * ') output.write( 'Creates and returns a deep copy of this {0} object.\n'.format( element)) output.write( ' *\n * @return a (deep) copy of this {0} object.\n */\n'.format( element)) output.write(' virtual {0}* clone () const;\n\n\n'.format(element)) return
def writeListOfSubFunctions(attrib, output, element, elementDict): loname = generalFunctions.writeListOf(strFunctions.cap(attrib['name'])) output.write(' /**\n') output.write(' * Returns the \"{0}\"'.format(loname)) output.write(' in this {0} object.\n'.format(element)) output.write(' *\n') output.write(' * @return the \"{0}\"'.format(loname)) output.write(' attribute of this {0}.\n'.format(element)) output.write(' */\n') output.write(' const {0}*'.format(loname)) output.write(' getListOf{0}s() const;\n\n\n'.format(strFunctions.cap(attrib['name']))) writeListOfHeader.writeGetFunctions(output, strFunctions.cap(attrib['name']), attrib['element'], True, element) output.write(' /**\n') output.write(' * Adds a copy the given \"{0}\" to this {1}.\n'.format(attrib['element'], element)) output.write(' *\n') output.write(' * @param {0}; the {1} object to add\n'.format(strFunctions.objAbbrev(attrib['element']), attrib['element'])) output.write(' *\n') output.write(' * @return integer value indicating success/failure of the\n') output.write(' * function. @if clike The value is drawn from the\n') output.write(' * enumeration #OperationReturnValues_t. @endif The possible values\n') output.write(' * returned by this function are:\n') output.write(' * @li LIBSEDML_OPERATION_SUCCESS\n') output.write(' * @li LIBSEDML_INVALID_ATTRIBUTE_VALUE\n') output.write(' */\n') output.write(' int add{0}(const {1}* {2});\n\n\n'.format(strFunctions.cap(attrib['name']), attrib['element'], strFunctions.objAbbrev(attrib['element']))) output.write(' /**\n') output.write(' * Get the number of {0} objects in this {1}.\n'.format(attrib['element'], element)) output.write(' *\n') output.write(' * @return the number of {0} objects in this {1}\n'.format(attrib['element'], element)) output.write(' */\n') output.write(' unsigned int getNum{0}s() const;\n\n\n'.format(strFunctions.cap(attrib['name']))) if attrib.has_key('abstract') == False or (attrib.has_key('abstract') and attrib['abstract'] == False): output.write(' /**\n') output.write(' * Creates a new {0} object, adds it to this {1}s\n'.format(attrib['element'], element)) output.write(' * {0} and returns the {1} object created.\n'.format(loname, attrib['element'])) output.write(' *\n') output.write(' * @return a new {0} object instance\n'.format(attrib['element'])) output.write(' *\n') output.write(' * @see add{0}(const {1}* {2})\n'.format(strFunctions.cap(attrib['name']), attrib['element'], strFunctions.objAbbrev(attrib['element']))) output.write(' */\n') output.write(' {0}* create{1}();\n\n\n'.format(attrib['element'], strFunctions.cap(attrib['name']))) elif attrib.has_key('concrete'): for elem in attrib['concrete']: output.write(' /**\n') output.write(' * Creates a new {0} object, adds it to this {1}s\n'.format(elem['element'], element)) output.write(' * {0} and returns the {1} object created.\n'.format(loname, elem['element'])) output.write(' *\n') output.write(' * @return a new {0} object instance\n'.format(elem['element'])) output.write(' *\n') output.write(' * @see add{0}(const {0}* {1})\n'.format(attrib['element'], strFunctions.objAbbrev(attrib['element']))) output.write(' */\n') output.write(' {0}* create{1}();\n\n\n'.format(elem['element'], strFunctions.cap(elem['name']))) writeListOfHeader.writeRemoveFunctions(output, strFunctions.cap(attrib['name']), attrib['element'], True, element)
def 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): listOf = generalFunctions.writeListOf(element) generalFunctions.writeInternalStartDecl(output) output.write('\t/**\n') output.write('\t * Creates a new {0} in this {1}\n'.format(element, listOf)) output.write('\t */\n') output.write('\tvirtual SedBase* createObject(XMLInputStream& stream);\n\n\n') generalFunctions.writeInternalEndDecl(output) generalFunctions.writeInternalStartDecl(output) output.write('\t/**\n') output.write('\t * Write the namespace for the {0} package.\n'.format(package)) output.write('\t */\n') output.write('\tvirtual void writeXMLNS(XMLOutputStream& stream) const;\n\n\n') generalFunctions.writeInternalEndDecl(output)
def writeProtectedFunctions(output, element, package): listOf = generalFunctions.writeListOf(element) generalFunctions.writeInternalStartDecl(output) output.write(' /**\n') output.write(' * Creates a new {0} in this {1}\n'.format(element, listOf)) output.write(' */\n') output.write(' virtual SedBase* createObject(XMLInputStream& stream);\n\n\n') generalFunctions.writeInternalEndDecl(output) generalFunctions.writeInternalStartDecl(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.writeInternalEndDecl(output)
def writeListOfHeaders(output, element, type, elementDict=None): loelement = generalFunctions.writeListOf(element) loelementClass = generalFunctions.getListOfClassName(elementDict, type) hasId = generalFunctions.hasIdAttribute(elementDict, element) if hasId: output.write('LIBSBML_EXTERN\n') output.write('{0}_t *\n'.format(type)) output.write('{0}_getById'.format(loelementClass)) output.write('(ListOf_t * lo, const char * sid);\n\n\n') output.write('LIBSBML_EXTERN\n') output.write('{0}_t *\n'.format(type)) output.write('{0}_removeById'.format(loelementClass)) output.write('(ListOf_t * lo, const char * sid);\n\n\n')
def writeListOfHeaders(output, element, type, elementDict=None): loelement = generalFunctions.writeListOf(element) loelementClass = generalFunctions.getListOfClassName(elementDict, type) hasId = generalFunctions.hasIdAttribute(elementDict, element) if hasId: output.write("LIBSBML_EXTERN\n") output.write("{0}_t *\n".format(type)) output.write("{0}_getById".format(loelementClass)) output.write("(ListOf_t * lo, const char * sid);\n\n\n") output.write("LIBSBML_EXTERN\n") output.write("{0}_t *\n".format(type)) output.write("{0}_removeById".format(loelementClass)) output.write("(ListOf_t * lo, const char * sid);\n\n\n")
def writeConstructors(element, type, package, output): element = generalFunctions.writeListOf(element) indent = strFunctions.getIndent(element) output.write(' /**\n * ' ) output.write('Creates a new {0}'.format(element)) output.write(' with the given level, version, and package version.\n') output.write(' *\n') output.write(' * @param level an unsigned int, the SEDML Level to assign') output.write(' to this {0}\n'.format(element)) output.write(' *\n') output.write(' * @param version an unsigned int, the SEDML Version to assign') output.write(' to this {0}\n'.format(element)) output.write(' *\n') output.write(' * @param pkgVersion an unsigned int, the SEDML {0} Version to assign'.format(package)) output.write(' to this {0}\n */\n'.format(element)) output.write(' {0}(unsigned int level = '.format(element)) output.write('SEDML_DEFAULT_LEVEL,\n') output.write(' {0}unsigned int version = '.format(indent)) output.write('SEDML_DEFAULT_VERSION\n') output.write(');\n\n\n'.format(package)) output.write(' /**\n * ' ) output.write('Creates a new {0}'.format(element)) output.write(' with the given SedNamespaces object.\n') output.write(' *\n') output.write(' * @param {0}ns the SedNamespaces object'.format(package.lower(), package)) output.write('\n */\n') output.write(' {0}(SedNamespaces* {1}ns);\n\n\n'.format(element, package.lower())) # output.write(' /**\n * ' ) # output.write('Copy constructor for {0}.\n'.format(element)) # output.write(' *\n') # output.write(' * @param orig; the {0} instance to copy.\n'.format(element)) # output.write(' */\n') # output.write(' {0}(const {1}& orig);\n\n\n'.format(element, element)) # output.write(' /**\n * ' ) # output.write('Assignment operator for {0}.\n'.format(element)) # output.write(' *\n') # output.write(' * @param rhs; the object whose values are used as the basis\n') # output.write(' * of the assignment\n */\n') # output.write(' {0}& operator=(const {1}& rhs);\n\n\n'.format(element, element)) output.write(' /**\n * ' ) output.write('Creates and returns a deep copy of this {0} object.\n'.format(element)) output.write(' *\n * @return a (deep) copy of this {0} object.\n */\n'.format(element)) output.write(' virtual {0}* clone () const;\n\n\n'.format(element)) return
def writeListOfSubElements(attrib, output, element): loname = generalFunctions.writeListOf(strFunctions.cap(attrib['name'])) output.write('LIBSEDML_EXTERN\n') output.write('int\n') output.write('{0}_add{1}({0}_t * {2}, '.format(element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write('{0}_t * {1});\n\n\n'.format(attrib['element'], strFunctions.objAbbrev(attrib['element']))) if attrib.has_key('abstract') == False or (attrib.has_key('abstract') and attrib['abstract'] == False): output.write('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(attrib['element'])) output.write('{0}_create{1}({0}_t * {2}' .format(element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write(');\n\n\n') elif attrib.has_key('concrete'): for elem in attrib['concrete']: output.write('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(elem['element'])) output.write('{0}_create{1}({0}_t * {2}' .format(element, strFunctions.cap(elem['name']), strFunctions.objAbbrev(element))) output.write(');\n\n\n') output.write('LIBSEDML_EXTERN\n') output.write('SedListOf_t *\n') output.write('{0}_get{1}({0}_t * {2})'.format(element, loname, strFunctions.objAbbrev(element))) output.write(';\n\n\n') output.write('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(attrib['element'])) output.write('{0}_get{1}({0}_t * {2}, '.format(element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write('unsigned int n);\n\n\n') output.write('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(attrib['element'])) output.write('{0}_get{1}ById({0}_t * {2}, '.format(element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write('const char * sid);\n\n\n') output.write('LIBSEDML_EXTERN\n') output.write('unsigned int\n') output.write('{0}_getNum{1}s({0}_t * {2}' .format(element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write(');\n\n\n') output.write('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(attrib['element'])) output.write('{0}_remove{1}({0}_t * {2}, '.format(element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write('unsigned int n);\n\n\n') output.write('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(attrib['element'])) output.write('{0}_remove{1}ById({0}_t * {2}, '.format(element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write('const char * sid);\n\n\n')
def writeRemoveFunctions(output, element, type, subelement=False, topelement=""): listOf = generalFunctions.writeListOf(element) output.write(' /**\n') if subelement == True: output.write(' * Removes the nth {0} from the {1} within this {2}.\n'.format(element, listOf, topelement)) else: output.write(' * Removes the nth {0} from this {1}\n'.format(element, listOf)) output.write(' * and returns a pointer to it.\n') output.write(' *\n') output.write(' * The caller owns the returned item and is responsible for deleting it.\n') output.write(' *\n') output.write(' * @param n the index of the {0} to remove.\n'.format(element)) if subelement == True: output.write(' *\n * @see getNum{0}s()\n'.format(element)) output.write(' */\n') output.write(' {0}* remove{1}(unsigned int n);\n\n\n'.format(type, element)) else: output.write(' *\n * @see size()\n') output.write(' */\n') output.write(' virtual {0}* remove(unsigned int n);\n\n\n'.format(type)) output.write(' /**\n') if subelement == True: output.write(' * Removes the {0} with the given identifier from the {1} within this {2}\n'.format(element, listOf, topelement)) else: output.write(' * Removes the {0} from this {1} with the given identifier\n'.format(element, listOf)) output.write(' * and returns a pointer to it.\n') output.write(' *\n') output.write(' * The caller owns the returned item and is responsible for deleting it.\n') output.write(' * If none of the items in this list have the identifier @p sid, then\n') output.write(' * @c NULL is returned.\n') output.write(' *\n') output.write(' * @param sid the identifier of the {0} to remove.\n'.format(element)) output.write(' *\n') output.write(' * @return the {0} removed. As mentioned above, the caller owns the\n'.format(element)) output.write(' * returned item.\n') output.write(' */\n') if subelement == True: output.write(' {0}* remove{1}(const std::string& sid);\n\n\n'.format(type, element)) else: output.write(' virtual {0}* remove(const std::string& sid);\n\n\n'.format(type))
def writeRemoveFunctions(output, element, type, subelement=False, topelement=""): listOf = generalFunctions.writeListOf(element) output.write('\t/**\n') if subelement == True: output.write('\t * Removes the nth {0} from the {1} within this {2}.\n'.format(element, listOf, topelement)) else: output.write('\t * Removes the nth {0} from this {1}\n'.format(element, listOf)) output.write('\t * and returns a pointer to it.\n') output.write('\t *\n') output.write('\t * The caller owns the returned item and is responsible for deleting it.\n') output.write('\t *\n') output.write('\t * @param n the index of the {0} to remove.\n'.format(element)) if subelement == True: output.write('\t *\n\t * @see getNum{0}s()\n'.format(element)) output.write('\t */\n') output.write('\t{0}* remove{1}(unsigned int n);\n\n\n'.format(type, element)) else: output.write('\t *\n\t * @see size()\n') output.write('\t */\n') output.write('\tvirtual {0}* remove(unsigned int n);\n\n\n'.format(type)) output.write('\t/**\n') if subelement == True: output.write('\t * Removes the {0} with the given identifier from the {1} within this {2}\n'.format(element, listOf, topelement)) else: output.write('\t * Removes the {0} from this {1} with the given identifier\n'.format(element, listOf)) output.write('\t * and returns a pointer to it.\n') output.write('\t *\n') output.write('\t * The caller owns the returned item and is responsible for deleting it.\n') output.write('\t * If none of the items in this list have the identifier @p sid, then\n') output.write('\t * @c NULL is returned.\n') output.write('\t *\n') output.write('\t * @param sid the identifier of the {0} to remove.\n'.format(element)) output.write('\t *\n') output.write('\t * @return the {0} removed. As mentioned above, the caller owns the\n'.format(element)) output.write('\t * returned item.\n') output.write('\t */\n') if subelement == True: output.write('\t{0}* remove{1}(const std::string& sid);\n\n\n'.format(type, element)) else: output.write('\tvirtual {0}* remove(const std::string& sid);\n\n\n'.format(type))
def writeRemoveFunctions(output, element, type, subelement=False, topelement="", name=""): listOf = generalFunctions.writeListOf(element) output.write('/*\n') if subelement == True: output.write(' * Removes the nth {0} from the {1}.\n'.format(element, listOf)) output.write(' */\n') output.write('{0}*\n'.format(type)) output.write('{0}::remove{1}(unsigned int n)\n'.format(topelement, element)) output.write('{\n' ) output.write(' return m{0}.remove(n);\n'.format(strFunctions.capp(name))) output.write('}\n\n\n') else: output.write(' * Removes the nth {0} from this {1}\n'.format(element, listOf)) output.write(' */\n') output.write('{0}*\n{1}::remove(unsigned int n)\n'.format(type, listOf)) output.write('{\n' ) output.write(' return static_cast<{0}*>(SedListOf::remove(n));\n'.format(type)) output.write('}\n\n\n') output.write('/*\n') if subelement == True: output.write(' * Removes the a {0} with given id from the {1}.\n'.format(element, listOf)) output.write(' */\n') output.write('{0}*\n'.format(type)) output.write('{0}::remove{1}(const std::string& sid)\n'.format(topelement, element)) output.write('{\n' ) output.write(' return m{0}.remove(sid);\n'.format(strFunctions.capp(name))) output.write('}\n\n\n') else: output.write(' * Removes the {0} from this {1} with the given identifier\n'.format(element, listOf)) output.write(' */\n') output.write('{0}*\n{1}::remove(const std::string& sid)\n'.format(type, listOf)) output.write('{\n' ) output.write(' SedBase* item = NULL;\n') output.write(' vector<SedBase*>::iterator result;\n\n') output.write(' result = find_if( mItems.begin(), mItems.end(), SedIdEq<{0}>(sid) );\n\n'.format(type)) output.write(' if (result != mItems.end())\n {\n') output.write(' item = *result;\n') output.write(' mItems.erase(result);\n }\n\n') output.write(' return static_cast <{0}*> (item);\n'.format(type)) output.write('}\n\n\n')
def writeGetFunctions(output, element, type, subelement=False, topelement=""): listOf = generalFunctions.writeListOf(element) output.write(' /**\n') output.write(' * Get a {0} from the {1}.\n'.format(element, listOf)) output.write(' *\n') output.write(' * @param n the index number of the {0} to get.\n'.format(element)) output.write(' *\n') if subelement == True: output.write(' * @return the nth {0} in the {1} within this {2}.\n'.format(element, listOf, topelement)) output.write(' *\n * @see getNum{0}s()\n'.format(element)) output.write(' */\n') output.write(' {0}* get{1}(unsigned int n);\n\n\n'.format(type, element)) else: output.write(' * @return the nth {0} in this {1}.\n'.format(element, listOf)) output.write(' *\n * @see size()\n') output.write(' */\n') output.write(' virtual {0}* get(unsigned int n);\n\n\n'.format(type)) output.write(' /**\n') output.write(' * Get a {0} from the {1}.\n'.format(element, listOf)) output.write(' *\n') output.write(' * @param n the index number of the {0} to get.\n'.format(element)) output.write(' *\n') if subelement == True: output.write(' * @return the nth {0} in the {1} within this {2}.\n'.format(element, listOf, topelement)) output.write(' *\n * @see getNum{0}s()\n'.format(element)) output.write(' */\n') output.write(' const {0}* get{1}(unsigned int n) const;\n\n\n'.format(type, element)) else: output.write(' * @return the nth {0} in this {1}.\n'.format(element, listOf)) output.write(' *\n * @see size()\n') output.write(' */\n') output.write(' virtual const {0}* get(unsigned int n) const;\n\n\n'.format(type)) output.write(' /**\n') output.write(' * Get a {0} from the {1}\n'.format(element, listOf)) output.write(' * based on its identifier.\n') output.write(' *\n') output.write(' * @param sid a string representing the identifier\n * of the {0} to get.\n'.format(element)) output.write(' *\n') if subelement == True: output.write(' * @return the {0} in the {1}\n'.format(element, listOf)) output.write(' * with the given id or NULL if no such\n * {0} exists.\n'.format(element)) output.write(' *\n * @see get{0}(unsigned int n)\n'.format(element)) output.write(' *\n * @see getNum{0}s()\n'.format(element)) output.write(' */\n') output.write(' {0}* get{1}(const std::string& sid);\n\n\n'.format(type, element)) else: output.write(' * @return {0} in this {1}\n'.format(element, listOf)) output.write(' * with the given id or NULL if no such\n * {0} exists.\n'.format(element)) output.write(' *\n * @see get(unsigned int n)') output.write(' *\n * @see size()\n') output.write(' */\n') output.write(' virtual {0}* get(const std::string& sid);\n\n\n'.format(type)) output.write(' /**\n') output.write(' * Get a {0} from the {1}\n'.format(element, listOf)) output.write(' * based on its identifier.\n') output.write(' *\n') output.write(' * @param sid a string representing the identifier\n * of the {0} to get.\n'.format(element)) output.write(' *\n') if subelement == True: output.write(' * @return the {0} in the {1}\n'.format(element, listOf)) output.write(' * with the given id or NULL if no such\n * {0} exists.\n'.format(element)) output.write(' *\n * @see get{0}(unsigned int n)\n'.format(element)) output.write(' *\n * @see getNum{0}s()\n'.format(element)) output.write(' */\n') output.write(' const {0}* get{1}(const std::string& sid) const;\n\n\n'.format(type,element)) else: output.write(' * @return {0} in this {1}\n'.format(element, listOf)) output.write(' * with the given id or NULL if no such\n * {0} exists.\n'.format(element)) output.write(' *\n * @see get(unsigned int n)') output.write(' *\n * @see size()\n') output.write(' */\n') output.write(' virtual const {0}* get(const std::string& sid) const;\n\n\n'.format(type))
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 createCode(element, code): type = element['name'] name = element['name'] if element.has_key('elementName'): name = strFunctions.cap(element['elementName']) if element.has_key('element'): type = element['element'] listOf = generalFunctions.writeListOf(name) writeConstructors(name, type, element['package'], code) writeGetFunctions(code, name, type) code.write('/**\n') code.write(' * Adds a copy the given \"{0}\" to this {1}.\n'.format( type, listOf)) code.write(' *\n') code.write(' * @param {0}; the {1} object to add\n'.format( strFunctions.objAbbrev(type), type)) code.write(' *\n') code.write(' * @return integer value indicating success/failure of the\n') code.write(' * function. @if clike The value is drawn from the\n') code.write( ' * enumeration #OperationReturnValues_t. @endif The possible values\n' ) code.write(' * returned by this function are:\n') code.write(' * @li LIBSEDML_OPERATION_SUCCESS\n') code.write(' * @li LIBSEDML_INVALID_ATTRIBUTE_VALUE\n') code.write(' */\n') code.write('int\n') code.write('{0}::add{1}(const {2}* {3})\n'.format( listOf, strFunctions.cap(name), type, strFunctions.objAbbrev(type))) code.write('{\n') code.write( ' if({0} == NULL) return LIBSEDML_INVALID_ATTRIBUTE_VALUE;\n'.format( strFunctions.objAbbrev(type))) code.write(' append({0});\n'.format(strFunctions.objAbbrev(type))) code.write(' return LIBSEDML_OPERATION_SUCCESS;\n') code.write('}\n\n\n') code.write('/**\n') code.write(' * Get the number of {0} objects in this {1}.\n'.format( type, listOf)) code.write(' *\n') code.write(' * @return the number of {0} objects in this {1}\n'.format( type, listOf)) code.write(' */\n') code.write('unsigned int\n') code.write('{0}::getNum{1}s() const\n'.format(listOf, strFunctions.cap(name))) code.write('{\n') code.write(' return size();\n') code.write('}\n\n') 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}s\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} *temp = new {0}();\n'.format(type)) code.write(' if (temp != NULL) appendAndOwn(temp);\n') code.write(' return temp;\n') code.write('}\n\n') elif element.has_key('concrete'): for elem in 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} *temp = new {0}();\n'.format(elem['element'])) code.write(' if (temp != NULL) appendAndOwn(temp);\n') code.write(' return temp;\n') code.write('}\n\n') writeRemoveFunctions(code, name, type) generalFunctions.writeCommonCPPCode(code, element['name'], element['typecode'], None, True, False, False, element) elementName = element['name'] if element.has_key('elementName'): elementName = element['elementName'] writeProtectedFunctions(code, element['name'], element['package'], elementName, element)
def writeListOfSubFunctions(attrib, output, 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(loname)) output.write(' in this {0} object.\n'.format(element)) output.write(' */\n') output.write('const {0}*\n'.format(loname)) output.write('{0}::getListOf{1}s() const\n'.format(element, strFunctions.cap(attrib['name']))) output.write('{\n') output.write('\treturn &m{0};\n'.format(strFunctions.capp(attName))) output.write('}\n\n\n') writeListOfCode.writeRemoveFunctions(output, strFunctions.cap(attrib['name']), attrib['element'], True, element, capAttName) writeListOfCode.writeGetFunctions(output, strFunctions.cap(attrib['name']), attrib['element'], True, element, capAttName) output.write('/**\n') output.write(' * Adds a copy the given \"{0}\" to this {1}.\n'.format(attrib['element'], element)) output.write(' *\n') output.write(' * @param {0}; the {1} object to add\n'.format(strFunctions.objAbbrev(attrib['element']), attrib['element'])) output.write(' *\n') output.write(' * @return integer value indicating success/failure of the\n') output.write(' * function. @if clike The value is drawn from the\n') output.write(' * enumeration #OperationReturnValues_t. @endif The possible values\n') output.write(' * returned by this function are:\n') output.write(' * @li LIBSEDML_OPERATION_SUCCESS\n') output.write(' * @li LIBSEDML_INVALID_ATTRIBUTE_VALUE\n') output.write(' */\n') output.write('int\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('\tif({0} == NULL) return LIBSEDML_INVALID_ATTRIBUTE_VALUE;\n'.format(strFunctions.objAbbrev(attrib['element']))) output.write('\tm{0}.append({1});\n'.format(strFunctions.capp(attrib['name']),strFunctions.objAbbrev(attrib['element']))) output.write('\treturn LIBSEDML_OPERATION_SUCCESS;\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}s() const\n'.format(element, strFunctions.cap(attrib['name']))) output.write('{\n') output.write('\treturn m{0}.size();\n'.format(strFunctions.capp(attrib['name']))) output.write('}\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('\t{0} *temp = new {0}();\n'.format(attrib['element'])) output.write('\tif (temp != NULL) m{0}.appendAndOwn(temp);\n'.format(strFunctions.capp(attrib['name']))) output.write('\treturn temp;\n') output.write('}\n\n') elif attrib.has_key('concrete'): for elem in attrib['concrete']: output.write('/**\n') output.write(' * Creates a new {0} object, adds it to this {1}s\n'.format(elem['element'], element)) output.write(' * {0} and returns the {1} object created. \n'.format(element, 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 {1}* {2})\n'.format(strFunctions.cap(elem['name']), attrib['element'], strFunctions.objAbbrev(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('\t{0} *temp = new {0}();\n'.format(elem['element'])) output.write('\tif (temp != NULL) m{0}.appendAndOwn(temp);\n'.format(strFunctions.capp(attrib['name']))) output.write('\treturn temp;\n') output.write('}\n\n')
def writeGetFunctions(output, element, type, subelement=False, topelement="", name=""): listOf = generalFunctions.writeListOf(element) output.write('/*\n') if subelement == True: output.write( ' * Return the nth {0} in the {1} within this {2}.\n'.format( element, listOf, topelement)) output.write(' */\n') output.write('{0}*\n'.format(type)) output.write('{0}::get{1}(unsigned int n)\n'.format( topelement, element)) output.write('{\n') output.write(' return m{0}.get(n);\n'.format(strFunctions.capp(name))) output.write('}\n\n\n') else: output.write(' * Get a {0} from the {1} by index.\n'.format( element, listOf)) output.write('*/\n') output.write('{0}*\n'.format(type)) output.write('{0}::get(unsigned int n)\n'.format(listOf)) output.write('{\n') output.write( ' return static_cast<{0}*>(SedListOf::get(n));\n'.format(type)) output.write('}\n\n\n') output.write('/*\n') if subelement == True: output.write( ' * Return the nth {0} in the {1} within this {2}.\n'.format( element, listOf, topelement)) output.write(' */\n') output.write('const {0}*\n'.format(type)) output.write('{0}::get{1}(unsigned int n) const\n'.format( topelement, element)) output.write('{\n') output.write(' return m{0}.get(n);\n'.format(strFunctions.capp(name))) output.write('}\n\n\n') else: output.write(' * Get a {0} from the {1} by index.\n'.format( element, listOf)) output.write(' */\n') output.write('const {0}*\n'.format(type)) output.write('{0}::get(unsigned int n) const\n'.format(listOf)) output.write('{\n') output.write( ' return static_cast<const {0}*>(SedListOf::get(n));\n'.format( type)) output.write('}\n\n\n') output.write('/*\n') if subelement == True: output.write(' * Return a {0} from the {1} by id.\n'.format( element, listOf)) output.write(' */\n') output.write('{0}*\n'.format(type)) output.write('{0}::get{1}(const std::string& sid)\n'.format( topelement, element)) output.write('{\n') output.write(' return m{0}.get(sid);\n'.format( strFunctions.capp(name))) output.write('}\n\n\n') else: output.write(' * Get a {0} from the {1} by id.\n'.format( element, listOf)) output.write(' */\n') output.write('{0}*\n'.format(type)) output.write('{0}::get(const std::string& sid)\n'.format(listOf)) output.write('{\n') output.write(' return const_cast<{0}*>(\n'.format(type)) output.write( ' static_cast<const {0}&>(*this).get(sid));\n'.format(listOf)) output.write('}\n\n\n') output.write('/*\n') if subelement == True: output.write(' * Return a {0} from the {1} by id.\n'.format( element, listOf)) output.write(' */\n') output.write('const {0}*\n'.format(type)) output.write('{0}::get{1}(const std::string& sid) const\n'.format( topelement, element)) output.write('{\n') output.write(' return m{0}.get(sid);\n'.format( strFunctions.capp(name))) output.write('}\n\n\n') else: output.write(' * Get a {0} from the {1} by id.\n'.format( element, listOf)) output.write(' */\n') output.write('const {0}*\n'.format(type)) output.write('{0}::get(const std::string& sid) const\n'.format(listOf)) output.write('{\n') output.write(' vector<SedBase*>::const_iterator result;\n\n') output.write( ' result = find_if( mItems.begin(), mItems.end(), SedIdEq<{0}>(sid) );\n' .format(type)) output.write( ' return (result == mItems.end()) ? 0 : static_cast <{0}*> (*result);\n' .format(type)) output.write('}\n\n\n')
def writeGetFunctions(output, element, type, subelement=False, topelement="", name=""): listOf = generalFunctions.writeListOf(element) output.write('/*\n') if subelement == True: output.write(' * Return the nth {0} in the {1} within this {2}.\n'.format(element, listOf, topelement)) output.write(' */\n') output.write('{0}*\n'.format(type)) output.write('{0}::get{1}(unsigned int n)\n'.format(topelement, element)) output.write('{\n' ) output.write(' return m{0}.get(n);\n'.format(strFunctions.capp(name))) output.write('}\n\n\n') else: output.write(' * Get a {0} from the {1} by index.\n'.format(element, listOf)) output.write('*/\n') output.write('{0}*\n'.format(type)) output.write('{0}::get(unsigned int n)\n'.format(listOf)) output.write('{\n' ) output.write(' return static_cast<{0}*>(SedListOf::get(n));\n'.format(type)) output.write('}\n\n\n') output.write('/*\n') if subelement == True: output.write(' * Return the nth {0} in the {1} within this {2}.\n'.format(element, listOf, topelement)) output.write(' */\n') output.write('const {0}*\n'.format(type)) output.write('{0}::get{1}(unsigned int n) const\n'.format(topelement, element)) output.write('{\n' ) output.write(' return m{0}.get(n);\n'.format(strFunctions.capp(name))) output.write('}\n\n\n') else: output.write(' * Get a {0} from the {1} by index.\n'.format(element, listOf)) output.write(' */\n') output.write('const {0}*\n'.format(type)) output.write('{0}::get(unsigned int n) const\n'.format(listOf)) output.write('{\n' ) output.write(' return static_cast<const {0}*>(SedListOf::get(n));\n'.format(type)) output.write('}\n\n\n') output.write('/*\n') if subelement == True: output.write(' * Return a {0} from the {1} by id.\n'.format(element, listOf)) output.write(' */\n') output.write('{0}*\n'.format(type)) output.write('{0}::get{1}(const std::string& sid)\n'.format(topelement, element)) output.write('{\n' ) output.write(' return m{0}.get(sid);\n'.format(strFunctions.capp(name))) output.write('}\n\n\n') else: output.write(' * Get a {0} from the {1} by id.\n'.format(element, listOf)) output.write(' */\n') output.write('{0}*\n'.format(type)) output.write('{0}::get(const std::string& sid)\n'.format(listOf)) output.write('{\n' ) output.write(' return const_cast<{0}*>(\n'.format(type)) output.write(' static_cast<const {0}&>(*this).get(sid));\n'.format(listOf)) output.write('}\n\n\n') output.write('/*\n') if subelement == True: output.write(' * Return a {0} from the {1} by id.\n'.format(element, listOf)) output.write(' */\n') output.write('const {0}*\n'.format(type)) output.write('{0}::get{1}(const std::string& sid) const\n'.format(topelement, element)) output.write('{\n' ) output.write(' return m{0}.get(sid);\n'.format(strFunctions.capp(name))) output.write('}\n\n\n') else: output.write(' * Get a {0} from the {1} by id.\n'.format(element, listOf)) output.write(' */\n') output.write('const {0}*\n'.format(type)) output.write('{0}::get(const std::string& sid) const\n'.format(listOf)) output.write('{\n' ) output.write(' vector<SedBase*>::const_iterator result;\n\n') output.write(' result = find_if( mItems.begin(), mItems.end(), SedIdEq<{0}>(sid) );\n'.format(type)) output.write(' return (result == mItems.end()) ? 0 : static_cast <{0}*> (*result);\n'.format(type)) output.write('}\n\n\n')
def createCode(element, code): type = element['name'] name = element['name'] if element.has_key('elementName'): name = strFunctions.cap(element['elementName']) if element.has_key('element'): type = element['element'] listOf = generalFunctions.writeListOf(name) writeConstructors(name, type, element['package'], code) writeGetFunctions(code, name, type) code.write('/**\n') code.write(' * Adds a copy the given \"{0}\" to this {1}.\n'.format(type, listOf)) code.write(' *\n') code.write(' * @param {0}; the {1} object to add\n'.format(strFunctions.objAbbrev(type), type)) code.write(' *\n') code.write(' * @return integer value indicating success/failure of the\n') code.write(' * function. @if clike The value is drawn from the\n') code.write(' * enumeration #OperationReturnValues_t. @endif The possible values\n') code.write(' * returned by this function are:\n') code.write(' * @li LIBSEDML_OPERATION_SUCCESS\n') code.write(' * @li LIBSEDML_INVALID_ATTRIBUTE_VALUE\n') code.write(' */\n') code.write('int\n') code.write('{0}::add{1}(const {2}* {3})\n'.format(listOf, strFunctions.cap(name), type, strFunctions.objAbbrev(type))) code.write('{\n') code.write(' if({0} == NULL) return LIBSEDML_INVALID_ATTRIBUTE_VALUE;\n'.format(strFunctions.objAbbrev(type))) code.write(' append({0});\n'.format(strFunctions.objAbbrev(type))) code.write(' return LIBSEDML_OPERATION_SUCCESS;\n') code.write('}\n\n\n') code.write('/**\n') code.write(' * Get the number of {0} objects in this {1}.\n'.format(type, listOf)) code.write(' *\n') code.write(' * @return the number of {0} objects in this {1}\n'.format(type, listOf)) code.write(' */\n') code.write('unsigned int\n') code.write('{0}::getNum{1}s() const\n'.format(listOf, strFunctions.cap(name))) code.write('{\n') code.write(' return size();\n') code.write('}\n\n') 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}s\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} *temp = new {0}();\n'.format(type)) code.write(' if (temp != NULL) appendAndOwn(temp);\n') code.write(' return temp;\n') code.write('}\n\n') elif element.has_key('concrete'): for elem in 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} *temp = new {0}();\n'.format(elem['element'])) code.write(' if (temp != NULL) appendAndOwn(temp);\n') code.write(' return temp;\n') code.write('}\n\n') writeRemoveFunctions(code, name, type) generalFunctions.writeCommonCPPCode(code, element['name'], element['typecode'],None, True, False,False, element) elementName = element['name'] if element.has_key('elementName'): elementName = element['elementName'] writeProtectedFunctions(code, element['name'], element['package'], elementName, element)
def writeListOfSubElements(attrib, output, element): loname = generalFunctions.writeListOf(strFunctions.cap(attrib['name'])) output.write('LIBSEDML_EXTERN\n') output.write('int\n') output.write('{0}_add{1}({0}_t * {2}, '.format( element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write('{0}_t * {1})\n'.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('LIBSEDML_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'): for elem in attrib['concrete']: output.write('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(elem['element'])) output.write('{0}_create{1}({0}_t * {2})\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('LIBSEDML_EXTERN\n') output.write('SedListOf_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) ? (SedListOf_t *){0}->getListOf{1}s() : NULL;\n' .format(strFunctions.objAbbrev(element), strFunctions.cap(attrib['name']))) output.write('}\n\n') output.write('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(attrib['element'])) output.write('{0}_get{1}({0}_t * {2}, '.format( element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write('unsigned int n)\n') 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('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(attrib['element'])) output.write('{0}_get{1}ById({0}_t * {2}, '.format( element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write('const char * sid)\n') 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('LIBSEDML_EXTERN\n') output.write('unsigned int\n') output.write('{0}_getNum{1}s({0}_t * {2})\n'.format( element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write('{\n') output.write( '\treturn ({0} != NULL) ? {0}->getNum{1}s() : SEDML_INT_MAX;\n'. format(strFunctions.objAbbrev(element), strFunctions.cap(attrib['name']))) output.write('}\n\n') output.write('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(attrib['element'])) output.write('{0}_remove{1}({0}_t * {2}, '.format( element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write('unsigned int n)\n') 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('LIBSEDML_EXTERN\n') output.write('{0}_t *\n'.format(attrib['element'])) output.write('{0}_remove{1}ById({0}_t * {2}, '.format( element, strFunctions.cap(attrib['name']), strFunctions.objAbbrev(element))) output.write('const char * sid)\n') 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 writeListOfSubFunctions(attrib, output, 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(loname)) output.write(' in this {0} object.\n'.format(element)) output.write(' */\n') output.write('const {0}*\n'.format(loname)) output.write('{0}::getListOf{1}s() const\n'.format( element, strFunctions.cap(attrib['name']))) output.write('{\n') output.write('\treturn &m{0};\n'.format(capAttName)) output.write('}\n\n\n') writeListOfCode.writeRemoveFunctions(output, strFunctions.cap(attrib['name']), attrib['element'], True, element, capAttName) writeListOfCode.writeGetFunctions(output, strFunctions.cap(attrib['name']), attrib['element'], True, element, capAttName) output.write('/**\n') output.write(' * Adds a copy the given \"{0}\" to this {1}.\n'.format( attrib['element'], element)) output.write(' *\n') output.write(' * @param {0}; the {1} object to add\n'.format( strFunctions.objAbbrev(attrib['element']), attrib['element'])) output.write(' *\n') output.write( ' * @return integer value indicating success/failure of the\n') output.write(' * function. @if clike The value is drawn from the\n') output.write( ' * enumeration #OperationReturnValues_t. @endif The possible values\n' ) output.write(' * returned by this function are:\n') output.write(' * @li LIBSEDML_OPERATION_SUCCESS\n') output.write(' * @li LIBSEDML_INVALID_ATTRIBUTE_VALUE\n') output.write(' */\n') output.write('int\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( '\tif({0} == NULL) return LIBSEDML_INVALID_ATTRIBUTE_VALUE;\n'.format( strFunctions.objAbbrev(attrib['element']))) output.write('\tm{0}.append({1});\n'.format( strFunctions.cap(attrib['name']), strFunctions.objAbbrev(attrib['element']))) output.write('\treturn LIBSEDML_OPERATION_SUCCESS;\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}s() const\n'.format( element, strFunctions.cap(attrib['name']))) output.write('{\n') output.write('\treturn m{0}.size();\n'.format( strFunctions.cap(attrib['name']))) output.write('}\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('\t{0} *temp = new {0}();\n'.format(attrib['element'])) output.write('\tif (temp != NULL) m{0}.appendAndOwn(temp);\n'.format( strFunctions.cap(attrib['name']))) output.write('\treturn temp;\n') output.write('}\n\n') elif attrib.has_key('concrete'): for elem in attrib['concrete']: output.write('/**\n') output.write( ' * Creates a new {0} object, adds it to this {1}s\n'.format( elem['element'], element)) output.write( ' * {0} and returns the {1} object created. \n'.format( element, 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 {1}* {2})\n'.format( strFunctions.cap(elem['name']), attrib['element'], strFunctions.objAbbrev(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('\t{0} *temp = new {0}();\n'.format(elem['element'])) output.write( '\tif (temp != NULL) m{0}.appendAndOwn(temp);\n'.format( strFunctions.cap(attrib['name']))) output.write('\treturn temp;\n') output.write('}\n\n')
def writeGetFunctions(output, element, type, subelement=False, topelement=""): listOf = generalFunctions.writeListOf(element) output.write(' /**\n') output.write(' * Get a {0} from the {1}.\n'.format(element, listOf)) output.write(' *\n') output.write( ' * @param n the index number of the {0} to get.\n'.format(element)) output.write(' *\n') if subelement == True: output.write( ' * @return the nth {0} in the {1} within this {2}.\n'.format( element, listOf, topelement)) output.write(' *\n * @see getNum{0}s()\n'.format(element)) output.write(' */\n') output.write(' {0}* get{1}(unsigned int n);\n\n\n'.format( type, element)) else: output.write(' * @return the nth {0} in this {1}.\n'.format( element, listOf)) output.write(' *\n * @see size()\n') output.write(' */\n') output.write(' virtual {0}* get(unsigned int n);\n\n\n'.format(type)) output.write(' /**\n') output.write(' * Get a {0} from the {1}.\n'.format(element, listOf)) output.write(' *\n') output.write( ' * @param n the index number of the {0} to get.\n'.format(element)) output.write(' *\n') if subelement == True: output.write( ' * @return the nth {0} in the {1} within this {2}.\n'.format( element, listOf, topelement)) output.write(' *\n * @see getNum{0}s()\n'.format(element)) output.write(' */\n') output.write(' const {0}* get{1}(unsigned int n) const;\n\n\n'.format( type, element)) else: output.write(' * @return the nth {0} in this {1}.\n'.format( element, listOf)) output.write(' *\n * @see size()\n') output.write(' */\n') output.write( ' virtual const {0}* get(unsigned int n) const;\n\n\n'.format( type)) output.write(' /**\n') output.write(' * Get a {0} from the {1}\n'.format(element, listOf)) output.write(' * based on its identifier.\n') output.write(' *\n') output.write( ' * @param sid a string representing the identifier\n * of the {0} to get.\n' .format(element)) output.write(' *\n') if subelement == True: output.write(' * @return the {0} in the {1}\n'.format( element, listOf)) output.write( ' * with the given id or NULL if no such\n * {0} exists.\n'. format(element)) output.write( ' *\n * @see get{0}(unsigned int n)\n'.format(element)) output.write(' *\n * @see getNum{0}s()\n'.format(element)) output.write(' */\n') output.write(' {0}* get{1}(const std::string& sid);\n\n\n'.format( type, element)) else: output.write(' * @return {0} in this {1}\n'.format(element, listOf)) output.write( ' * with the given id or NULL if no such\n * {0} exists.\n'. format(element)) output.write(' *\n * @see get(unsigned int n)') output.write(' *\n * @see size()\n') output.write(' */\n') output.write( ' virtual {0}* get(const std::string& sid);\n\n\n'.format(type)) output.write(' /**\n') output.write(' * Get a {0} from the {1}\n'.format(element, listOf)) output.write(' * based on its identifier.\n') output.write(' *\n') output.write( ' * @param sid a string representing the identifier\n * of the {0} to get.\n' .format(element)) output.write(' *\n') if subelement == True: output.write(' * @return the {0} in the {1}\n'.format( element, listOf)) output.write( ' * with the given id or NULL if no such\n * {0} exists.\n'. format(element)) output.write( ' *\n * @see get{0}(unsigned int n)\n'.format(element)) output.write(' *\n * @see getNum{0}s()\n'.format(element)) output.write(' */\n') output.write( ' const {0}* get{1}(const std::string& sid) const;\n\n\n'.format( type, element)) else: output.write(' * @return {0} in this {1}\n'.format(element, listOf)) output.write( ' * with the given id or NULL if no such\n * {0} exists.\n'. format(element)) output.write(' *\n * @see get(unsigned int n)') output.write(' *\n * @see size()\n') output.write(' */\n') output.write( ' virtual const {0}* get(const std::string& sid) const;\n\n\n'. format(type))