Beispiel #1
0
def createCode(element):
  nameOfElement = element['name']
  nameOfPackage = element['package']
  sedmltypecode = element['typecode']
  hasSedListOf = element['hasSedListOf']
  attributes = element['attribs']
  hasChildren = element['hasChildren']
  hasMath = element['hasMath']
  baseClass = 'SedBase'
  if element != None and element.has_key('baseClass'):
    baseClass = element['baseClass']

  codeName = nameOfElement + '.cpp'
  code = open(codeName, 'w')
  fileHeaders.addFilename(code, codeName, nameOfElement)
  fileHeaders.addLicence(code)
  writeIncludes(code, nameOfElement, nameOfPackage, hasMath)
  writeConstructors(nameOfElement, nameOfPackage, code, attributes, hasChildren, hasMath, element)
  writeAttributeCode(attributes, code, nameOfElement)
  generalFunctions.writeCommonCPPCode(code, nameOfElement, sedmltypecode, attributes, False, hasChildren, hasMath, element,baseClass)
  generalFunctions.writeInternalCPPCode(code, nameOfElement, attributes, False, hasChildren or hasSedListOf, hasMath,baseClass)
  generalFunctions.writeProtectedCPPCode(code, nameOfElement, attributes, False, hasChildren, hasMath,baseClass)
  if element.has_key('additionalCPPImpls'):
    code.write(open(element['additionalCPPImpls'], 'r').read())
  if hasSedListOf:
    writeListOfCode.createCode(element, code)
  writeCCode.createCode(element, code)
Beispiel #2
0
def createCode(element):
    nameOfElement = element['name']
    nameOfPackage = element['package']
    sedmltypecode = element['typecode']
    hasSedListOf = element['hasSedListOf']
    attributes = element['attribs']
    hasChildren = element['hasChildren']
    hasMath = element['hasMath']
    baseClass = 'SedBase'
    if element != None and element.has_key('baseClass'):
        baseClass = element['baseClass']

    codeName = nameOfElement + '.cpp'
    code = open(codeName, 'w')
    fileHeaders.addFilename(code, codeName, nameOfElement)
    fileHeaders.addLicence(code)
    writeIncludes(code, nameOfElement, nameOfPackage, hasMath)
    writeConstructors(nameOfElement, nameOfPackage, code, attributes,
                      hasChildren, hasMath, element)
    writeAttributeCode(attributes, code, nameOfElement)
    generalFunctions.writeCommonCPPCode(code, nameOfElement, sedmltypecode,
                                        attributes, False, hasChildren,
                                        hasMath, element, baseClass)
    generalFunctions.writeInternalCPPCode(code, nameOfElement, attributes,
                                          False, hasChildren or hasSedListOf,
                                          hasMath, baseClass)
    generalFunctions.writeProtectedCPPCode(code, nameOfElement, attributes,
                                           False, hasChildren, hasMath,
                                           baseClass)
    if element.has_key('additionalCPPImpls'):
        code.write(open(element['additionalCPPImpls'], 'r').read())
    if hasSedListOf:
        writeListOfCode.createCode(element, code)
    writeCCode.createCode(element, code)
Beispiel #3
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)

  
Beispiel #4
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)
Beispiel #5
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.writeListOf(name)
  writeConstructors(name, type, element['package'], code) 
  writeGetFunctions(code, name, type)
  code.write('/**\n')
  code.write(' * Adds a copy the given \"{0}\" to this {1}.\n'.format(type, listOf))
  code.write(' *\n')
  code.write(' * @param {0}; the {1} object to add\n'.format(strFunctions.objAbbrev(type), type))
  code.write(' *\n')
  code.write(' * @return integer value indicating success/failure of the\n')
  code.write(' * function.  @if clike The value is drawn from the\n')
  code.write(' * enumeration #OperationReturnValues_t. @endif The possible values\n')
  code.write(' * returned by this function are:\n')
  code.write(' * @li LIBSEDML_OPERATION_SUCCESS\n')
  code.write(' * @li LIBSEDML_INVALID_ATTRIBUTE_VALUE\n')
  code.write(' */\n')
  code.write('int\n')
  code.write('{0}::add{1}(const {2}* {3})\n'.format(listOf, strFunctions.cap(name), type, strFunctions.objAbbrev(type)))
  code.write('{\n')
  code.write('  if({0} == NULL) return LIBSEDML_INVALID_ATTRIBUTE_VALUE;\n'.format(strFunctions.objAbbrev(type)))
  code.write('  append({0});\n'.format(strFunctions.objAbbrev(type)))
  code.write('  return LIBSEDML_OPERATION_SUCCESS;\n')
  code.write('}\n\n\n')
  code.write('/**\n')
  code.write(' * Get the number of {0} objects in this {1}.\n'.format(type, listOf))
  code.write(' *\n')
  code.write(' * @return the number of {0} objects in this {1}\n'.format(type, listOf))
  code.write(' */\n')
  code.write('unsigned int\n')
  code.write('{0}::getNum{1}s() const\n'.format(listOf, strFunctions.cap(name)))
  code.write('{\n')
  code.write('  return size();\n')
  code.write('}\n\n')
  if element.has_key('abstract') == False or (element.has_key('abstract') and element['abstract'] == False):
    code.write('/**\n')
    code.write(' * Creates a new {0} object, adds it to this {1}s\n'.format(type, listOf))
    code.write(' * {0} and returns the {1} object created.\n'.format(element['name'], type))
    code.write(' *\n')
    code.write(' * @return a new {0} object instance\n'.format(type))
    code.write(' *\n')
    code.write(' * @see add{0}(const {0}* {1})\n'.format(type, strFunctions.objAbbrev(type)))
    code.write(' */\n')
    code.write('{0}*\n'.format(type))
    code.write('{0}::create{1}()\n'.format(listOf, strFunctions.cap(name)))
    code.write('{\n')
    code.write('  {0} *temp = new {0}();\n'.format(type))
    code.write('  if (temp != NULL) appendAndOwn(temp);\n')
    code.write('  return temp;\n')
    code.write('}\n\n')
  elif element.has_key('concrete'):
    for elem in element['concrete']:
      code.write('/**\n')
      code.write(' * Creates a new {0} object, adds it to this {1}\n'.format(elem['element'], listOf))
      code.write(' * {0} and returns the {1} object created.\n'.format(elem['name'], elem['element']))
      code.write(' *\n')
      code.write(' * @return a new {0} object instance\n'.format(elem['element']))
      code.write(' *\n')
      code.write(' * @see add{0}(const {1}* {2})\n'.format(strFunctions.cap(elem['name']), type, strFunctions.objAbbrev(type)))
      code.write(' */\n')
      code.write('{0}*\n'.format(elem['element']))
      code.write('{0}::create{1}()\n'.format(listOf, strFunctions.cap(elem['name'])))
      code.write('{\n')
      code.write('  {0} *temp = new {0}();\n'.format(elem['element']))
      code.write('  if (temp != NULL) appendAndOwn(temp);\n')
      code.write('  return temp;\n')
      code.write('}\n\n')
  writeRemoveFunctions(code, name, type)
  generalFunctions.writeCommonCPPCode(code, element['name'], element['typecode'],None,  True, False,False, element)
  elementName = element['name']
  if element.has_key('elementName'):
    elementName = element['elementName']
  writeProtectedFunctions(code, element['name'], element['package'], elementName, element)

  
Beispiel #6
0
def createCode(element):
  nameOfElement = element['name']
  nameOfPackage = element['package']
  sbmltypecode = element['typecode']
  isListOf = element['hasListOf']
  attributes = element['attribs']
  hasChildren = element['hasChildren']
  hasMath = element['hasMath']
  baseClass = 'SBase'
  childrenOverwrite = element.has_key('childrenOverwriteElementName') and element['childrenOverwriteElementName']

  if element != None and element.has_key('baseClass'):
    baseClass = element['baseClass']
    if baseClass == None: 
      baseClass = 'SBase'

  codeName = nameOfElement + '.cpp'
  code = open(codeName, 'w')
  fileHeaders.addFilename(code, codeName, nameOfElement)
  fileHeaders.addLicence(code)
  writeIncludes(code, nameOfElement, nameOfPackage, hasMath, element)
  writeConstructors(nameOfElement, nameOfPackage, code, attributes, hasChildren, hasMath, element, childrenOverwrite)
  writeAttributeCode(attributes, code, nameOfElement, nameOfPackage, element)
  if hasMath == True or generalFunctions.hasSIdRef(attributes) == True:
    generalFunctions.writeRenameSIdCode(code, nameOfElement, attributes, hasMath)
  if hasChildren == True:
    generalFunctions.writeGetAllElementsCode(code, nameOfElement, attributes)
  generalFunctions.writeCommonCPPCode(code, nameOfElement, sbmltypecode, attributes, False, hasChildren, hasMath, element,baseClass)
  generalFunctions.writeInternalCPPCode(code, nameOfElement, attributes, hasChildren, hasMath,baseClass, isListOf)
  generalFunctions.writeProtectedCPPCode(code, nameOfElement, attributes, False, hasChildren, hasMath, nameOfPackage,
                                         isListOf, baseClass, element)
  
  if generalFunctions.hasArray(element):
    
    # writes the array to model
    code.write('void\n{0}::write(XMLOutputStream& stream) const\n'.format(element['name']))
    code.write('{\n')
    code.write('  stream.startElement(getElementName(), getPrefix());\n')
    code.write('  writeAttributes(stream);\n')

    att = generalFunctions.getByType(element['attribs'], 'array')
    if att != None:
      capAttName = strFunctions.cap(att['name'])
      attType = att['element'];
      if attType == 'int':
        attType = 'long'
      code.write('  if(isSet{0}())\n'.format(capAttName))
      code.write('  {\n')
      code.write('    for (int i = 0; i < m{0}Length; ++i)\n'.format(capAttName))
      code.write('    {\n')
      code.write('      stream << ({0})m{1}[i] << " ";\n'.format(attType, capAttName))
      code.write('    }\n')
      code.write('  }\n')
    code.write('  stream.endElement(getElementName(), getPrefix());\n')
    code.write('}\n\n\n')

    # set element text, parses the text
    code.write('void\n{0}::setElementText(const std::string &text)\n'.format(element['name']))
    code.write('{\n')
    code.write('  stringstream strStream(text); // Insert the string into a stream\n')
    code.write('  {0} val;\n'.format(att['element']))
    code.write('  vector<{0}> valuesVector;\n'.format(att['element']))
    code.write('  while (strStream >> val)\n')
    code.write('  {\n')
    code.write('    valuesVector.push_back(val);\n')
    code.write('  }\n')
    code.write('\n')
    code.write('  // convert the vector to an array\n')
    code.write('  unsigned int length = (unsigned int)valuesVector.size();\n')
    code.write('  if (length > 0)\n')
    code.write('  {\n')
    code.write('\n')
    code.write('    {0}* data = new {0}[length];\n'.format(att['element']))
    code.write('    for (unsigned int i = 0; i < length; ++i)\n')
    code.write('    {\n')
    code.write('      data[i] = valuesVector.at(i);\n')
    code.write('    }\n')
    code.write('\n')
    code.write('    set{0}(data, length);\n'.format(strFunctions.cap(att['name'])))
    code.write('    delete[] data;\n')
    code.write('  }\n')     
    code.write('}\n')

  if element.has_key('addDefs'):
    code.write(open(element['addDefs'], 'r').read())

  if isListOf == True:
    writeListOfCode.createCode(element, code)
  writeCCode.createCode(element, code)

#if len(sys.argv) != 2:
#  print 'Usage: writeCode.py element'
#else:
#  element = createNewElementDictObj.createFBCObjective()
#  createCode(element)
  

  
Beispiel #7
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.writeListOf(name)
    writeConstructors(name, type, element['package'], code)
    writeGetFunctions(code, name, type)
    code.write('/**\n')
    code.write(' * Adds a copy the given \"{0}\" to this {1}.\n'.format(
        type, listOf))
    code.write(' *\n')
    code.write(' * @param {0}; the {1} object to add\n'.format(
        strFunctions.objAbbrev(type), type))
    code.write(' *\n')
    code.write(' * @return integer value indicating success/failure of the\n')
    code.write(' * function.  @if clike The value is drawn from the\n')
    code.write(
        ' * enumeration #OperationReturnValues_t. @endif The possible values\n'
    )
    code.write(' * returned by this function are:\n')
    code.write(' * @li LIBSEDML_OPERATION_SUCCESS\n')
    code.write(' * @li LIBSEDML_INVALID_ATTRIBUTE_VALUE\n')
    code.write(' */\n')
    code.write('int\n')
    code.write('{0}::add{1}(const {2}* {3})\n'.format(
        listOf, strFunctions.cap(name), type, strFunctions.objAbbrev(type)))
    code.write('{\n')
    code.write(
        '  if({0} == NULL) return LIBSEDML_INVALID_ATTRIBUTE_VALUE;\n'.format(
            strFunctions.objAbbrev(type)))
    code.write('  append({0});\n'.format(strFunctions.objAbbrev(type)))
    code.write('  return LIBSEDML_OPERATION_SUCCESS;\n')
    code.write('}\n\n\n')
    code.write('/**\n')
    code.write(' * Get the number of {0} objects in this {1}.\n'.format(
        type, listOf))
    code.write(' *\n')
    code.write(' * @return the number of {0} objects in this {1}\n'.format(
        type, listOf))
    code.write(' */\n')
    code.write('unsigned int\n')
    code.write('{0}::getNum{1}s() const\n'.format(listOf,
                                                  strFunctions.cap(name)))
    code.write('{\n')
    code.write('  return size();\n')
    code.write('}\n\n')
    if element.has_key('abstract') == False or (element.has_key('abstract') and
                                                element['abstract'] == False):
        code.write('/**\n')
        code.write(
            ' * Creates a new {0} object, adds it to this {1}s\n'.format(
                type, listOf))
        code.write(' * {0} and returns the {1} object created.\n'.format(
            element['name'], type))
        code.write(' *\n')
        code.write(' * @return a new {0} object instance\n'.format(type))
        code.write(' *\n')
        code.write(' * @see add{0}(const {0}* {1})\n'.format(
            type, strFunctions.objAbbrev(type)))
        code.write(' */\n')
        code.write('{0}*\n'.format(type))
        code.write('{0}::create{1}()\n'.format(listOf, strFunctions.cap(name)))
        code.write('{\n')
        code.write('  {0} *temp = new {0}();\n'.format(type))
        code.write('  if (temp != NULL) appendAndOwn(temp);\n')
        code.write('  return temp;\n')
        code.write('}\n\n')
    elif element.has_key('concrete'):
        for elem in element['concrete']:
            code.write('/**\n')
            code.write(
                ' * Creates a new {0} object, adds it to this {1}\n'.format(
                    elem['element'], listOf))
            code.write(' * {0} and returns the {1} object created.\n'.format(
                elem['name'], elem['element']))
            code.write(' *\n')
            code.write(' * @return a new {0} object instance\n'.format(
                elem['element']))
            code.write(' *\n')
            code.write(' * @see add{0}(const {1}* {2})\n'.format(
                strFunctions.cap(elem['name']), type,
                strFunctions.objAbbrev(type)))
            code.write(' */\n')
            code.write('{0}*\n'.format(elem['element']))
            code.write('{0}::create{1}()\n'.format(
                listOf, strFunctions.cap(elem['name'])))
            code.write('{\n')
            code.write('  {0} *temp = new {0}();\n'.format(elem['element']))
            code.write('  if (temp != NULL) appendAndOwn(temp);\n')
            code.write('  return temp;\n')
            code.write('}\n\n')
    writeRemoveFunctions(code, name, type)
    generalFunctions.writeCommonCPPCode(code, element['name'],
                                        element['typecode'], None, True, False,
                                        False, element)
    elementName = element['name']
    if element.has_key('elementName'):
        elementName = element['elementName']
    writeProtectedFunctions(code, element['name'], element['package'],
                            elementName, element)
Beispiel #8
0
def createCode(element):
  nameOfElement = element['name']
  nameOfPackage = element['package']
  sbmltypecode = element['typecode']
  isListOf = element['hasListOf']
  attributes = element['attribs']
  hasChildren = element['hasChildren']
  hasMath = element['hasMath']
  baseClass = 'SBase'
  childrenOverwrite = element.has_key('childrenOverwriteElementName') and element['childrenOverwriteElementName']

  if element != None and element.has_key('baseClass'):
    baseClass = element['baseClass']
    if baseClass == None: 
      baseClass = 'SBase'

  codeName = nameOfElement + '.cpp'
  code = open(codeName, 'w')
  fileHeaders.addFilename(code, codeName, nameOfElement)
  fileHeaders.addLicence(code)
  writeIncludes(code, nameOfElement, nameOfPackage, hasMath, element)
  writeConstructors(nameOfElement, nameOfPackage, code, attributes, hasChildren, hasMath, element, childrenOverwrite)
  writeAttributeCode(attributes, code, nameOfElement, nameOfPackage, element)
  if hasMath == True or generalFunctions.hasSIdRef(attributes) == True:
    generalFunctions.writeRenameSIdCode(code, nameOfElement, attributes, hasMath)
  if hasChildren == True:
    generalFunctions.writeGetAllElementsCode(code, nameOfElement, attributes)
  generalFunctions.writeCommonCPPCode(code, nameOfElement, sbmltypecode, attributes, False, hasChildren, hasMath, element,baseClass)
  generalFunctions.writeInternalCPPCode(code, nameOfElement, attributes, hasChildren, hasMath,baseClass, isListOf)
  generalFunctions.writeProtectedCPPCode(code, nameOfElement, attributes, False, hasChildren, hasMath, nameOfPackage,
                                         isListOf, baseClass, element)
  
  if generalFunctions.hasArray(element):
    
    # writes the array to model
    code.write('void\n{0}::write(XMLOutputStream& stream) const\n'.format(element['name']))
    code.write('{\n')
    code.write('  stream.startElement(getElementName(), getPrefix());\n')
    code.write('  writeAttributes(stream);\n')

    att = generalFunctions.getByType(element['attribs'], 'array')
    if att != None:
      capAttName = strFunctions.cap(att['name'])
      attType = att['element'];
      if attType == 'int':
        attType = 'long'
      code.write('  if(isSet{0}())\n'.format(capAttName))
      code.write('  {\n')
      code.write('    for (int i = 0; i < m{0}Length; ++i)\n'.format(capAttName))
      code.write('    {\n')
      code.write('      stream << ({0})m{1}[i] << " ";\n'.format(attType, capAttName))
      code.write('    }\n')
      code.write('  }\n')
    code.write('  stream.endElement(getElementName(), getPrefix());\n')
    code.write('}\n\n\n')

    # set element text, parses the text
    code.write('void\n{0}::setElementText(const std::string &text)\n'.format(element['name']))
    code.write('{\n')
    code.write('  stringstream strStream(text); // Insert the string into a stream\n')
    code.write('  {0} val;\n'.format(att['element']))
    code.write('  vector<{0}> valuesVector;\n'.format(att['element']))
    code.write('  while (strStream >> val)\n')
    code.write('  {\n')
    code.write('    valuesVector.push_back(val);\n')
    code.write('  }\n')
    code.write('\n')
    code.write('  // convert the vector to an array\n')
    code.write('  unsigned int length = (unsigned int)valuesVector.size();\n')
    code.write('  if (length > 0)\n')
    code.write('  {\n')
    code.write('\n')
    code.write('    {0}* data = new {0}[length];\n'.format(att['element']))
    code.write('    for (unsigned int i = 0; i < length; ++i)\n')
    code.write('    {\n')
    code.write('      data[i] = valuesVector.at(i);\n')
    code.write('    }\n')
    code.write('\n')
    code.write('    set{0}(data, length);\n'.format(strFunctions.cap(att['name'])))
    code.write('    delete[] data;\n')
    code.write('  }\n')     
    code.write('}\n')

  if element.has_key('addDefs'):
    code.write(open(element['addDefs'], 'r').read())

  if isListOf == True:
    writeListOfCode.createCode(element, code)
  writeCCode.createCode(element, code)

#if len(sys.argv) != 2:
#  print 'Usage: writeCode.py element'
#else:
#  element = createNewElementDictObj.createFBCObjective()
#  createCode(element)