示例#1
0
def writeClass(attributes, header, nameOfElement, nameOfPackage, hasChildren, hasMath, isListOf, elementDict):
  header.write('class LIBSBML_EXTERN {0} :'.format(nameOfElement))
  baseClass = 'SBase'
  childrenOverwrite = elementDict.has_key('childrenOverwriteElementName') and elementDict['childrenOverwriteElementName']
  if elementDict.has_key('baseClass') and elementDict['baseClass'] != None:
    baseClass = elementDict['baseClass']
  header.write(' public {0}\n{1}\n\n'.format(baseClass, '{'))
  writeAttributes(attributes, header)
  if childrenOverwrite:
    header.write('  std::string   mElementName;\n\n')
  header.write('public:\n\n')
  writeConstructors(nameOfElement, nameOfPackage, header)
  writeAttributeFunctions(attributes, header, nameOfElement, elementDict)
  if hasMath == True or generalFunctions.hasSIdRef(attributes) == True:
    generalFunctions.writeRenameSIdHeader(header)

  if hasChildren == True:
    generalFunctions.writeGetAllElements(header)    
  generalFunctions.writeCommonHeaders(header, nameOfElement, attributes, False, hasChildren, hasMath)
  generalFunctions.writeInternalHeaders(header, isListOf, hasChildren)

  if generalFunctions.hasArray(elementDict):
    header.write('  virtual void write(XMLOutputStream& stream) const;\n\n\n')
  if childrenOverwrite:
    header.write('  virtual void setElementName(const std::string& name);\n\n\n')

  header.write('protected:\n\n')
  generalFunctions.writeProtectedHeaders(header, attributes, hasChildren, hasMath, baseClass, elementDict)
  if generalFunctions.hasArray(elementDict):
    header.write('  virtual void setElementText(const std::string &text);\n\n\n')

  if elementDict.has_key('addDecls'):
    header.write(open(elementDict['addDecls'], 'r').read())

  header.write('\n};\n\n')
示例#2
0
def writeClass(attributes, header, nameOfElement, nameOfPackage, hasChildren, hasMath, isListOf, elementDict):
  header.write('class LIBSBML_EXTERN {0} :'.format(nameOfElement))
  baseClass = 'SBase'
  childrenOverwrite = elementDict.has_key('childrenOverwriteElementName') and elementDict['childrenOverwriteElementName']
  if elementDict.has_key('baseClass') and elementDict['baseClass'] != None:
    baseClass = elementDict['baseClass']
  header.write(' public {0}\n{1}\n\n'.format(baseClass, '{'))
  writeAttributes(attributes, header)
  if childrenOverwrite:
    header.write('  std::string   mElementName;\n\n')
  header.write('public:\n\n')
  writeConstructors(nameOfElement, nameOfPackage, header)
  writeAttributeFunctions(attributes, header, nameOfElement, elementDict)
  if hasMath == True or generalFunctions.hasSIdRef(attributes) == True:
    generalFunctions.writeRenameSIdHeader(header)

  if hasChildren == True:
    generalFunctions.writeGetAllElements(header)    
  generalFunctions.writeCommonHeaders(header, nameOfElement, attributes, False, hasChildren, hasMath)
  generalFunctions.writeInternalHeaders(header, isListOf, hasChildren)

  if generalFunctions.hasArray(elementDict):
    header.write('  virtual void write(XMLOutputStream& stream) const;\n\n\n')
  if childrenOverwrite:
    header.write('  virtual void setElementName(const std::string& name);\n\n\n')

  header.write('protected:\n\n')
  generalFunctions.writeProtectedHeaders(header, attributes, hasChildren, hasMath, baseClass, elementDict)
  if generalFunctions.hasArray(elementDict):
    header.write('  virtual void setElementText(const std::string &text);\n\n\n')

  if elementDict.has_key('addDecls'):
    header.write(open(elementDict['addDecls'], 'r').read())

  header.write('\n};\n\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)
  

  
示例#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)