Esempio n. 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)
Esempio n. 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)
Esempio n. 3
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)
  

  
Esempio n. 4
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)