Esempio n. 1
0
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 writePkg(fileOut, name, classes):
  capName = name.upper()
  fileOut.write('#ifdef USE_{0}\n'.format(capName))
  fileOut.write('else if (pkgName == "{0}")\n'.format(name))
  fileOut.write('{\n')
  fileOut.write('  switch (sb->getTypeCode() )\n')
  fileOut.write('  {\n')
  fileOut.write('    case SBML_LIST_OF:\n')
  fileOut.write('      name = sb->getElementName();\n')
  for i in range (0, len(classes)):
    if (classes[i]['hasListOf'] == True):
      loName = strFunctions.listOfName(classes[i]['name'])
      if classes[i].has_key('lo_elementName'):
        loName = classes[i]['lo_elementName']
      if (i==0):
        fileOut.write('      if (name == "{0}")\n'.format(loName))
      else :
        fileOut.write('      else if (name == "{0}")\n'.format(loName))
      fileOut.write('      {\n')
      fileOut.write('        return SWIGTYPE_p_{0};\n'.format(generalFunctions.getListOfClassName (classes[i], classes[i]['name'])))
      fileOut.write('      }\n')
  fileOut.write('\n      return SWIGTYPE_p_ListOf;\n\n')
  for i in range (0, len(classes)):
    if classes[i]['typecode'] != 'HACK':
      fileOut.write('    case {0}:\n'.format(classes[i]['typecode']))
      fileOut.write('      return SWIGTYPE_p_{0};\n\n'.format(classes[i]['name']))
  fileOut.write('    default:\n')
  fileOut.write('      return SWIGTYPE_p_SBase;\n')
  fileOut.write('  }\n')
  fileOut.write('}\n\n')
  fileOut.write('#endif // USE_{0} \n\n'.format(capName))
Esempio n. 3
0
def writeConstructors(element, package, output, elementDict=None):
  element = generalFunctions.getListOfClassName(elementDict, 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('  {0}unsigned int pkgVersion)\n'.format(indent))
  output.write(' : ListOf(level, version)\n')
  output.write('{\n' )
  output.write('  setSBMLNamespacesAndOwn(new ')
  output.write('{0}PkgNamespaces(level, version, pkgVersion)); \n'.format(package))
  output.write('}\n\n\n')
  output.write('/*\n' )
  output.write(' * Constructor \n')
  output.write(' */\n')
  output.write('{0}::{0}({1}PkgNamespaces* {2}ns)\n '.format(element, package, package.lower()))
  output.write(' : ListOf({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')
Esempio n. 4
0
def writePkg(fileOut, name, classes):
    capName = name.upper()
    fileOut.write('#ifdef USE_{0}\n'.format(capName))
    fileOut.write('else if (pkgName == "{0}")\n'.format(name))
    fileOut.write('{\n')
    fileOut.write('  switch (sb->getTypeCode() )\n')
    fileOut.write('  {\n')
    fileOut.write('    case SBML_LIST_OF:\n')
    fileOut.write('      name = sb->getElementName();\n')
    for i in range(0, len(classes)):
        if (classes[i]['hasListOf'] == True):
            loName = strFunctions.listOfName(classes[i]['name'])
            if classes[i].has_key('lo_elementName'):
                loName = classes[i]['lo_elementName']
            if (i == 0):
                fileOut.write('      if (name == "{0}")\n'.format(loName))
            else:
                fileOut.write('      else if (name == "{0}")\n'.format(loName))
            fileOut.write('      {\n')
            fileOut.write('        return SWIGTYPE_p_{0};\n'.format(
                generalFunctions.getListOfClassName(classes[i],
                                                    classes[i]['name'])))
            fileOut.write('      }\n')
    fileOut.write('\n      return SWIGTYPE_p_ListOf;\n\n')
    for i in range(0, len(classes)):
        if classes[i]['typecode'] != 'HACK':
            fileOut.write('    case {0}:\n'.format(classes[i]['typecode']))
            fileOut.write('      return SWIGTYPE_p_{0};\n\n'.format(
                classes[i]['name']))
    fileOut.write('    default:\n')
    fileOut.write('      return SWIGTYPE_p_SBase;\n')
    fileOut.write('  }\n')
    fileOut.write('}\n\n')
    fileOut.write('#endif // USE_{0} \n\n'.format(capName))
Esempio n. 5
0
def writeConstructors(element, package, output, elementDict=None):
    element = generalFunctions.getListOfClassName(elementDict, 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('  {0}unsigned int pkgVersion)\n'.format(indent))
    output.write(' : ListOf(level, version)\n')
    output.write('{\n')
    output.write('  setSBMLNamespacesAndOwn(new ')
    output.write(
        '{0}PkgNamespaces(level, version, pkgVersion)); \n'.format(package))
    output.write('}\n\n\n')
    output.write('/*\n')
    output.write(' * Constructor \n')
    output.write(' */\n')
    output.write('{0}::{0}({1}PkgNamespaces* {2}ns)\n '.format(
        element, package, package.lower()))
    output.write(' : ListOf({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')
Esempio n. 6
0
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)
Esempio n. 7
0
def writeConstructors(element, type, package, output, elementDict):
    element = generalFunctions.getListOfClassName(elementDict, type)
    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 SBML Level to assign')
    output.write(' to this {0}\n'.format(element))
    output.write('   *\n')
    output.write(
        '   * @param version an unsigned int, the SBML Version to assign')
    output.write(' to this {0}\n'.format(element))
    output.write('   *\n')
    output.write(
        '   * @param pkgVersion an unsigned int, the SBML {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('{0}Extension::getDefaultLevel(),\n'.format(package))
    output.write('  {0}unsigned int version    = '.format(indent))
    output.write('{0}Extension::getDefaultVersion(),\n'.format(package))
    output.write('  {0}unsigned int pkgVersion = '.format(indent))
    output.write(
        '{0}Extension::getDefaultPackageVersion());\n\n\n'.format(package))
    output.write('  /**\n   * ')
    output.write('Creates a new {0}'.format(element))
    output.write(' with the given {0}PkgNamespaces object.\n'.format(package))
    output.write('   *\n')
    output.write('   * @param {0}ns the {1}PkgNamespaces object'.format(
        package.lower(), package))
    output.write('\n   */\n')
    output.write('  {0}({1}PkgNamespaces* {2}ns);\n\n\n '.format(
        element, package, 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
Esempio n. 8
0
def writeProtectedFunctions(output, element, package, elementDict = None):
  listOf = generalFunctions.getListOfClassName(elementDict, elementDict['name'])
  generalFunctions.writeInternalStart(output)
  output.write('  /**\n')
  output.write('   * Creates a new {0} in this {1}\n'.format(element, listOf))
  output.write('   */\n')
  output.write('  virtual SBase* createObject(XMLInputStream& stream);\n\n\n')
  generalFunctions.writeInternalEnd(output)
  generalFunctions.writeInternalStart(output)
  output.write('  /**\n')
  output.write('   * Write the namespace for the {0} package.\n'.format(package))
  output.write('   */\n')
  output.write('  virtual void writeXMLNS(XMLOutputStream& stream) const;\n\n\n')
  generalFunctions.writeInternalEnd(output)
Esempio n. 9
0
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 == 'const 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' or attType == 'inline_lo_element':
    if attrib.has_key('element'):
      output.write('  {0}   m{1};\n'.format(generalFunctions.getListOfClassName(attrib,attrib['element']), strFunctions.capp(attrib['name'])))
    else:
      output.write('  {0}   m{1};\n'.format(generalFunctions.getListOfClassName(attrib,capAttName), strFunctions.capp(attName)))
  elif attTypeCode == 'XMLNode*':
    output.write('  {0}   m{1};\n'.format('XMLNode*', 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 attrib['type'] == 'enum':
    output.write('  {0}_t   m{1};\n'.format(attrib['element'], capAttName))
  elif attrib['type'] == 'array':
    output.write('  {0}*         m{1};\n'.format(attrib['element'], capAttName))
  else:
    output.write('  FIX ME   {0};\n'.format(attName))
Esempio n. 10
0
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")
Esempio n. 11
0
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')
Esempio n. 12
0
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 == 'const 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' or attType == 'inline_lo_element':
    if attrib.has_key('element'):
      output.write('  {0}   m{1};\n'.format(generalFunctions.getListOfClassName(attrib,attrib['element']), strFunctions.capp(attrib['name'])))
    else:
      output.write('  {0}   m{1};\n'.format(generalFunctions.getListOfClassName(attrib,capAttName), strFunctions.capp(attName)))
  elif attTypeCode == 'XMLNode*':
    output.write('  {0}   m{1};\n'.format('XMLNode*', 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 attrib['type'] == 'enum':
    output.write('  {0}_t   m{1};\n'.format(attrib['element'], capAttName))
  elif attrib['type'] == 'array':
    output.write('  {0}*         m{1};\n'.format(attrib['element'], capAttName))
  else:
    output.write('  FIX ME   {0};\n'.format(attName))
Esempio n. 13
0
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.getListOfClassName(element, type)
  writeConstructors(type, element['package'], code, element) 
  writeGetFunctions(code, name, type, False,"","",element)
  writeListAccessFunctions(code, type, listOf, name, element, element['package'])
  writeRemoveFunctions(code, name, type,False, "", "", element)
  generalFunctions.writeCommonCPPCode(code, type, element['typecode'],None,  True, False,False, element)
  writeProtectedFunctions(code,type, element['package'], element)

  
Esempio n. 14
0
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.getListOfClassName(element, type)
    writeConstructors(type, element['package'], code, element)
    writeGetFunctions(code, name, type, False, "", "", element)
    writeListAccessFunctions(code, type, listOf, name, element,
                             element['package'])
    writeRemoveFunctions(code, name, type, False, "", "", element)
    generalFunctions.writeCommonCPPCode(code, type, element['typecode'], None,
                                        True, False, False, element)
    writeProtectedFunctions(code, type, element['package'], element)
Esempio n. 15
0
def writeConstructors(element, type, package, output,elementDict):
  element = generalFunctions.getListOfClassName(elementDict,type)
  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 SBML Level to assign')
  output.write(' to this {0}\n'.format(element))
  output.write('   *\n')
  output.write('   * @param version an unsigned int, the SBML Version to assign')
  output.write(' to this {0}\n'.format(element))
  output.write('   *\n')
  output.write('   * @param pkgVersion an unsigned int, the SBML {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('{0}Extension::getDefaultLevel(),\n'.format(package))
  output.write('  {0}unsigned int version    = '.format(indent))
  output.write('{0}Extension::getDefaultVersion(),\n'.format(package))
  output.write('  {0}unsigned int pkgVersion = '.format(indent))
  output.write('{0}Extension::getDefaultPackageVersion());\n\n\n'.format(package))
  output.write('  /**\n   * ' )
  output.write('Creates a new {0}'.format(element))
  output.write(' with the given {0}PkgNamespaces object.\n'.format(package))
  output.write('   *\n')
  output.write('   * @param {0}ns the {1}PkgNamespaces object'.format(package.lower(), package))
  output.write('\n   */\n')
  output.write('  {0}({1}PkgNamespaces* {2}ns);\n\n\n '.format(element, package, 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
Esempio n. 16
0
def writeProtectedFunctions(output, element, package, elementDict=None):
    listOf = generalFunctions.getListOfClassName(elementDict,
                                                 elementDict['name'])
    generalFunctions.writeInternalStart(output)
    output.write('  /**\n')
    output.write('   * Creates a new {0} in this {1}\n'.format(
        element, listOf))
    output.write('   */\n')
    output.write(
        '  virtual SBase* createObject(XMLInputStream& stream);\n\n\n')
    generalFunctions.writeInternalEnd(output)
    generalFunctions.writeInternalStart(output)
    output.write('  /**\n')
    output.write(
        '   * Write the namespace for the {0} package.\n'.format(package))
    output.write('   */\n')
    output.write(
        '  virtual void writeXMLNS(XMLOutputStream& stream) const;\n\n\n')
    generalFunctions.writeInternalEnd(output)
Esempio n. 17
0
def writeRemoveFunctions(output, element, type, subelement=False, topelement="", elementDict = None):
  listOf = generalFunctions.getListOfClassName(elementDict, type)
  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('\t{0}* remove{1}(unsigned int n);\n\n\n'.format(type, element))
  else:
    output.write('   *\n   * @see size()\n')
    output.write('   */\n')
    output.write('\tvirtual {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('\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))
Esempio n. 18
0
def writeRemoveFunctions(output, element, type, subelement=False, topelement="", name="", elementDict = None):
  listOf = generalFunctions.getListOfClassName(elementDict, type)
  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('\treturn 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}*>(ListOf::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('\treturn 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('  SBase* item = NULL;\n')
    output.write('  vector<SBase*>::iterator result;\n\n')
    output.write('  result = find_if( mItems.begin(), mItems.end(), IdEq<{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('\treturn static_cast <{0}*> (item);\n'.format(type))
    output.write('}\n\n\n')
Esempio n. 19
0
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")
Esempio n. 20
0
def writeGetFunctions(output,
                      element,
                      type,
                      subelement=False,
                      topelement="",
                      elementDict=None):
    listOf = generalFunctions.getListOfClassName(elementDict, 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('\t{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('\tvirtual {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('\tconst {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(
            '\tvirtual 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('\t{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(
            '\tvirtual {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(
            '\tconst {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))
Esempio n. 21
0
def writeRemoveFunctions(output,
                         element,
                         type,
                         subelement=False,
                         topelement="",
                         elementDict=None):
    listOf = generalFunctions.getListOfClassName(elementDict, type)
    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('\t{0}* remove{1}(unsigned int n);\n\n\n'.format(
            type, element))
    else:
        output.write('   *\n   * @see size()\n')
        output.write('   */\n')
        output.write(
            '\tvirtual {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('\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))
Esempio n. 22
0
def writeJava(fileOut, name, plugins, classes):
    capName = name.upper()
    fileOut.write('#ifdef USE_{0}\n'.format(capName))
    fileOut.write('/**\n')
    fileOut.write(
        ' * Adds DownCastBase(long cPtr, boolean owner) method for the {0} package extension\n'
        .format(name))
    fileOut.write(' */\n')
    fileOut.write('%typemap(javacode) {0}Extension\n'.format(
        strFunctions.cap(name)))
    fileOut.write('%{\n')
    fileOut.write(
        '  public SBasePlugin DowncastSBasePlugin(long cPtr, boolean owner)\n')
    fileOut.write('  {\n')
    fileOut.write('    if (cPtr == 0) return null;\n\n')
    fileOut.write('    SBasePlugin sbp = new SBasePlugin(cPtr, false);\n')
    fileOut.write('    SBase sb = sbp.getParentSBMLObject();\n\n')
    fileOut.write('    switch( sb.getTypeCode() )\n')
    fileOut.write('    {\n')

    listOfPlugins = []
    for plugin in plugins:
        typecode = 'SBML_{0}'.format(createSBase(plugin['sbase'].upper()))
        if plugin.has_key('typecode') and plugin['typecode'] != None:
            typecode = plugin['typecode']

        if typecode != 'SBML_LIST_OF':
            fileOut.write('      case (int) libsbml.{0}:\n'.format(typecode))
            fileOut.write(
                '        return new {0}{1}Plugin(cPtr, owner);\n\n'.format(
                    strFunctions.cap(name), plugin['sbase']))

        else:
            listOfPlugins.append(plugin)

    if len(listOfPlugins) > 0:
        fileOut.write('      case (int) libsbml.SBML_LIST_OF:\n')
        fileOut.write('      {\n')
        fileOut.write('        String name = sb.getElementName();\n')
        for plugin in listOfPlugins:
            fileOut.write('        if (name.equals("{0}"))\n'.format(
                strFunctions.lowerFirst(plugin['sbase'])))
            fileOut.write(
                '          return new {0}{1}Plugin(cPtr, owner);\n\n'.format(
                    strFunctions.cap(name), plugin['sbase']))
        fileOut.write('        return new SBasePlugin(cPtr, owner);\n')
        fileOut.write('      }\n')

    fileOut.write('      default:\n')
    fileOut.write('        return new SBasePlugin(cPtr, owner);\n')
    fileOut.write('    }\n')
    fileOut.write('  }\n\n')
    fileOut.write('  public SBase DowncastSBase(long cPtr, boolean owner)\n')
    fileOut.write('  {\n')
    fileOut.write('    if (cPtr == 0) return null;\n\n')
    fileOut.write('    SBase sb = new SBase(cPtr, false);\n')
    fileOut.write('    switch( sb.getTypeCode() )\n')
    fileOut.write('    {\n')
    fileOut.write('      case (int) libsbml.SBML_LIST_OF:\n')
    fileOut.write('        String name = sb.getElementName();\n')
    for i in range(0, len(classes)):
        if (classes[i]['hasListOf'] == True):
            loName = strFunctions.listOfName(classes[i]['name'])
            if classes[i].has_key('lo_elementName'):
                loName = classes[i]['lo_elementName']
            if (i == 0):
                fileOut.write(
                    '        if (name.equals("{0}"))\n'.format(loName))
            else:
                fileOut.write(
                    '        else if (name.equals("{0}"))\n'.format(loName))
            fileOut.write('        {\n')
            fileOut.write('          return new {0}(cPtr, owner);\n'.format(
                generalFunctions.getListOfClassName(classes[i],
                                                    classes[i]['name'])))
            fileOut.write('        }\n')
    fileOut.write('\n        return new ListOf(cPtr, owner);\n\n')
    for i in range(0, len(classes)):
        if classes[i]['typecode'] != 'HACK':
            fileOut.write('      case (int) libsbml.{0}:\n'.format(
                classes[i]['typecode']))
            fileOut.write('        return new {0}(cPtr, owner);\n\n'.format(
                classes[i]['name']))
    fileOut.write('      default:\n')
    fileOut.write('        return new SBase(cPtr, owner);\n')
    fileOut.write('    }\n')
    fileOut.write('  }\n\n')
    fileOut.write('%}\n\n')
    fileOut.write('COVARIANT_RTYPE_CLONE({0}Extension)\n'.format(
        strFunctions.cap(name)))
    for i in range(0, len(classes)):
        if classes[i]['typecode'] != 'HACK':
            fileOut.write('COVARIANT_RTYPE_CLONE({0})\n'.format(
                classes[i]['name']))
    for i in range(0, len(classes)):
        if (classes[i]['hasListOf'] == True):
            loName = generalFunctions.getListOfClassName(
                classes[i], classes[i]['name'])
            fileOut.write('COVARIANT_RTYPE_CLONE({0})\n'.format(
                strFunctions.cap(loName)))
    fileOut.write('\n')
    for i in range(0, len(classes)):
        if (classes[i]['hasListOf'] == True):
            fileOut.write('COVARIANT_RTYPE_LISTOF_GET_REMOVE({0})\n'.format(
                classes[i]['name']))
    fileOut.write('\n')
    fileOut.write('SBMLCONSTRUCTOR_EXCEPTION({0}PkgNamespaces)\n'.format(
        strFunctions.cap(name)))
    for i in range(0, len(classes)):
        if classes[i]['typecode'] != 'HACK':
            fileOut.write('SBMLCONSTRUCTOR_EXCEPTION({0})\n'.format(
                classes[i]['name']))
    for i in range(0, len(classes)):
        if (classes[i]['hasListOf'] == True):
            loName = generalFunctions.getListOfClassName(
                classes[i], classes[i]['name'])
            fileOut.write('SBMLCONSTRUCTOR_EXCEPTION({0})\n'.format(
                strFunctions.cap(loName)))
    fileOut.write('\n')
    for i in range(0, len(classes)):
        if (classes[i]['abstract'] == True
                or isBaseClassForOthers(classes[i], classes)):
            fileOut.write('//\n')
            fileOut.write(
                '// Convert {0} objects into the most specific object possible.\n'
                .format(classes[i]['name']))
            fileOut.write('//\n')
            fileOut.write('%typemap("javaout") {0}*\n'.format(
                classes[i]['name']))
            fileOut.write('{\n')
            fileOut.write(
                '	return ({0}) libsbml.DowncastSBase($jnicall, $owner);\n'.
                format(classes[i]['name']))
            fileOut.write('}\n')
            fileOut.write('\n')

    fileOut.write('\n')
    fileOut.write('#endif /* USE_{0} */\n\n'.format(capName))
Esempio n. 23
0
def writeGetFunctions(output, element, type, subelement=False, topelement="", name="", elementDict = None):
  listOf = generalFunctions.getListOfClassName(elementDict, type)
  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('\treturn 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}*>(ListOf::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('\treturn 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}*>(ListOf::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('\treturn 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('\treturn 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('\treturn 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<SBase*>::const_iterator result;\n\n')
    output.write('  result = find_if( mItems.begin(), mItems.end(), IdEq<{0}>(sid) );\n'.format(type))
    output.write('  return (result == mItems.end()) ? 0 : static_cast <{0}*> (*result);\n'.format(type))
    output.write('}\n\n\n')
Esempio n. 24
0
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)
Esempio n. 25
0
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)
Esempio n. 26
0
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')
Esempio n. 27
0
def writeGetFunctions(output, element, type, subelement=False, topelement="", elementDict = None):
  listOf = generalFunctions.getListOfClassName(elementDict, 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('\t{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('\tvirtual {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('\tconst {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('\tvirtual 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('\t{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('\tvirtual {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('\tconst {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 writeJava(fileOut, name, plugins, classes):
  capName = name.upper()
  fileOut.write('#ifdef USE_{0}\n'.format(capName))
  fileOut.write('/**\n')
  fileOut.write(' * Adds DownCastBase(long cPtr, boolean owner) method for the {0} package extension\n'.format(name))
  fileOut.write(' */\n')
  fileOut.write('%typemap(javacode) {0}Extension\n'.format(strFunctions.cap(name)))
  fileOut.write('%{\n')
  fileOut.write('  public SBasePlugin DowncastSBasePlugin(long cPtr, boolean owner)\n')
  fileOut.write('  {\n')
  fileOut.write('    if (cPtr == 0) return null;\n\n')
  fileOut.write('    SBasePlugin sbp = new SBasePlugin(cPtr, false);\n')
  fileOut.write('    SBase sb = sbp.getParentSBMLObject();\n\n')
  fileOut.write('    switch( sb.getTypeCode() )\n')
  fileOut.write('    {\n')

  listOfPlugins = []
  for plugin in plugins:
    typecode = 'SBML_{0}'.format(createSBase(plugin['sbase'].upper()))
    if plugin.has_key('typecode') and plugin['typecode'] != None:
      typecode = plugin['typecode']    

    if typecode != 'SBML_LIST_OF':
      fileOut.write('      case (int) libsbml.{0}:\n'.format(typecode))
      fileOut.write('        return new {0}{1}Plugin(cPtr, owner);\n\n'.format(strFunctions.cap(name), plugin['sbase']))
      
    else:
      listOfPlugins.append(plugin)

  if len(listOfPlugins) > 0: 
    fileOut.write('      case (int) libsbml.SBML_LIST_OF:\n')
    fileOut.write('      {\n')
    fileOut.write('        String name = sb.getElementName();\n')
    for plugin in listOfPlugins:
      fileOut.write('        if (name.equals("{0}"))\n'.format(strFunctions.lowerFirst(plugin['sbase'])))
      fileOut.write('          return new {0}{1}Plugin(cPtr, owner);\n\n'.format(strFunctions.cap(name), plugin['sbase']))
    fileOut.write('        return new SBasePlugin(cPtr, owner);\n')
    fileOut.write('      }\n')

  fileOut.write('      default:\n')
  fileOut.write('        return new SBasePlugin(cPtr, owner);\n')
  fileOut.write('    }\n')
  fileOut.write('  }\n\n')
  fileOut.write('  public SBase DowncastSBase(long cPtr, boolean owner)\n')
  fileOut.write('  {\n')
  fileOut.write('    if (cPtr == 0) return null;\n\n')
  fileOut.write('    SBase sb = new SBase(cPtr, false);\n')
  fileOut.write('    switch( sb.getTypeCode() )\n')
  fileOut.write('    {\n')
  fileOut.write('      case (int) libsbml.SBML_LIST_OF:\n')
  fileOut.write('        String name = sb.getElementName();\n')
  for i in range (0, len(classes)):
    if (classes[i]['hasListOf'] == True):
      loName = strFunctions.listOfName(classes[i]['name'])
      if classes[i].has_key('lo_elementName'):
        loName = classes[i]['lo_elementName']
      if (i==0):
        fileOut.write('        if (name.equals("{0}"))\n'.format(loName))
      else :
        fileOut.write('        else if (name.equals("{0}"))\n'.format(loName))
      fileOut.write('        {\n')
      fileOut.write('          return new {0}(cPtr, owner);\n'.format(generalFunctions.getListOfClassName (classes[i], classes[i]['name'])))
      fileOut.write('        }\n')
  fileOut.write('\n        return new ListOf(cPtr, owner);\n\n')
  for i in range (0, len(classes)):
    if classes[i]['typecode'] != 'HACK':
      fileOut.write('      case (int) libsbml.{0}:\n'.format(classes[i]['typecode']))
      fileOut.write('        return new {0}(cPtr, owner);\n\n'.format(classes[i]['name']))
  fileOut.write('      default:\n')
  fileOut.write('        return new SBase(cPtr, owner);\n')
  fileOut.write('    }\n')
  fileOut.write('  }\n\n')
  fileOut.write('%}\n\n')
  fileOut.write('COVARIANT_RTYPE_CLONE({0}Extension)\n'.format(strFunctions.cap(name)))
  for i in range (0, len(classes)):
    if classes[i]['typecode'] != 'HACK':
      fileOut.write('COVARIANT_RTYPE_CLONE({0})\n'.format(classes[i]['name']))
  for i in range (0, len(classes)):
    if (classes[i]['hasListOf'] == True):
      loName = generalFunctions.getListOfClassName (classes[i], classes[i]['name'])
      fileOut.write('COVARIANT_RTYPE_CLONE({0})\n'.format(strFunctions.cap(loName)))
  fileOut.write('\n')
  for i in range (0, len(classes)):
    if (classes[i]['hasListOf'] == True):
      fileOut.write('COVARIANT_RTYPE_LISTOF_GET_REMOVE({0})\n'.format(classes[i]['name']))
  fileOut.write('\n')
  fileOut.write('SBMLCONSTRUCTOR_EXCEPTION({0}PkgNamespaces)\n'.format(strFunctions.cap(name)))
  for i in range (0, len(classes)):
    if classes[i]['typecode'] != 'HACK':
      fileOut.write('SBMLCONSTRUCTOR_EXCEPTION({0})\n'.format(classes[i]['name']))
  for i in range (0, len(classes)):
    if (classes[i]['hasListOf'] == True):
      loName = generalFunctions.getListOfClassName (classes[i], classes[i]['name'])
      fileOut.write('SBMLCONSTRUCTOR_EXCEPTION({0})\n'.format(strFunctions.cap(loName)))
  fileOut.write('\n')
  for i in range (0, len(classes)):
    if (classes[i]['abstract'] == True or isBaseClassForOthers(classes[i], classes)):
      fileOut.write('//\n')
      fileOut.write('// Convert {0} objects into the most specific object possible.\n'.format(classes[i]['name']))
      fileOut.write('//\n')
      fileOut.write('%typemap("javaout") {0}*\n'.format(classes[i]['name']))
      fileOut.write('{\n')
      fileOut.write('	return ({0}) libsbml.DowncastSBase($jnicall, $owner);\n'.format(classes[i]['name']))
      fileOut.write('}\n')
      fileOut.write('\n')

  fileOut.write('\n')
  fileOut.write('#endif /* USE_{0} */\n\n'.format(capName))
Esempio n. 29
0
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')
Esempio n. 30
0
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')
Esempio n. 31
0
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')
Esempio n. 32
0
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)
Esempio n. 33
0
def writeGetFunctions(output,
                      element,
                      type,
                      subelement=False,
                      topelement="",
                      name="",
                      elementDict=None):
    listOf = generalFunctions.getListOfClassName(elementDict, type)
    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('\treturn 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}*>(ListOf::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('\treturn 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}*>(ListOf::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('\treturn 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('\treturn 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('\treturn 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<SBase*>::const_iterator result;\n\n')
        output.write(
            '  result = find_if( mItems.begin(), mItems.end(), IdEq<{0}>(sid) );\n'
            .format(type))
        output.write(
            '  return (result == mItems.end()) ? 0 : static_cast <{0}*> (*result);\n'
            .format(type))
        output.write('}\n\n\n')
Esempio n. 34
0
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')
Esempio n. 35
0
def writeRemoveFunctions(output,
                         element,
                         type,
                         subelement=False,
                         topelement="",
                         name="",
                         elementDict=None):
    listOf = generalFunctions.getListOfClassName(elementDict, type)
    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('\treturn 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}*>(ListOf::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('\treturn 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('  SBase* item = NULL;\n')
        output.write('  vector<SBase*>::iterator result;\n\n')
        output.write(
            '  result = find_if( mItems.begin(), mItems.end(), IdEq<{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('\treturn static_cast <{0}*> (item);\n'.format(type))
        output.write('}\n\n\n')
Esempio n. 36
0
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')