コード例 #1
0
def createFWD(pkg, classes):
  nameOfClass = pkg + 'fwd'
  codeName = nameOfClass + '.h'
  fileOut = open(codeName, 'w')
  fileHeaders.addFilename(fileOut, codeName, nameOfClass)
  fileHeaders.addLicence(fileOut)
  fileOut.write('#ifndef {0}_H\n'.format(nameOfClass))
  fileOut.write('#define {0}_H\n\n'.format(nameOfClass))
  fileOut.write('/**\n')
  fileOut.write(' * Forward declaration of all opaque C types.\n')
  fileOut.write(' *\n')
  fileOut.write(' * Declaring all types up-front avoids "redefinition of type Foo" compile\n')
  fileOut.write(' * errors and allows our combined C/C++ headers to depend minimally upon\n')
  fileOut.write(' * each other.  Put another way, the type definitions below serve the same\n')
  fileOut.write(' * purpose as "class Foo;" forward declarations in C++ code.\n')
  fileOut.write(' */\n\n')
  fileOut.write('#ifdef __cplusplus\n')
  fileOut.write('#  define CLASS_OR_STRUCT class\n')
  fileOut.write('#else\n')
  fileOut.write('#  define CLASS_OR_STRUCT struct\n')
  fileOut.write('#endif  /* __cplusplus */	\n\n')
  fileOut.write('LIBSBML_CPP_NAMESPACE_BEGIN\n\n')
  for i in range (0, len(classes)):
    if classes[i]['typecode'] != 'HACK':
      fileOut.write('typedef CLASS_OR_STRUCT {0}    {0}_t;\n'.format(classes[i]['name']))
  fileOut.write('\nLIBSBML_CPP_NAMESPACE_END\n\n')
  fileOut.write('#undef CLASS_OR_STRUCT\n\n')
  fileOut.write('\n#endif  /* {0}_H */\n\n'.format(nameOfClass))
コード例 #2
0
ファイル: writeCode.py プロジェクト: jeicher/libSEDML
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)
コード例 #3
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)
コード例 #4
0
def createValidatorHeader(pkg):
  inputFile = os.path.dirname(__file__)  + '/templateValidHead.txt' 
  headerName = pkg + 'Validator.h'
  header = open(headerName, 'w')
  nameOfElement = pkg + 'Validator'
  fileHeaders.addFilename(header, headerName, nameOfElement)
  fileHeaders.addLicence(header)
  header.write('\n#ifndef {0}Validator__H\n'.format(pkg))
  header.write('#define {0}Validator__H\n\n\n'.format(pkg))
  header.write('#ifdef __cplusplus\n\n\n')
  generalFunctions.writeInternalStart(header)
  header.write('#include <list>\n')
  header.write('#include <string>\n')
  generalFunctions.writeInternalEnd(header)
  input = open(inputFile, 'r')
  for line in input:
    if line[0:13] != 'TEMPLATE_STOP':
      line = replaceTags(line, pkg)
      header.write(line)
    else:
      break
  header.write('#endif  /* __cplusplus*/\n')  
  header.write('#endif  /* {0}Validator__H */\n'.format(pkg))
  input.close()
  header.close()
コード例 #5
0
def createHeader(element):
  nameOfElement = element['name']
  nameOfPackage = element['package']
  sbmltypecode = element['typecode']
  isListOf = element['hasListOf']
  attributes = element['attribs']
  hasChildren = element['hasChildren']
  hasMath = element['hasMath']
  headerName = nameOfElement + '.h'
  header = open(headerName, 'w')
  fileHeaders.addFilename(header, headerName, nameOfElement)
  fileHeaders.addLicence(header)
  writeIncludes(header, nameOfElement, nameOfPackage, attributes, element)
  writeClass(attributes, header, nameOfElement, nameOfPackage, hasChildren, hasMath, False, element)
  if isListOf == True:
    writeListOfHeader.createHeader(element, header)
  writeCPPEnd(header)
  writeCStart(header)
  writeCHeader.createHeader(element, header)
  writeCEnd(header, nameOfElement)

#if len(sys.argv) != 2:
#  print 'Usage: writeHeader.py element'
#else:
#  element = createNewElementDictObj.createFBCObj()
#  createHeader(element)
  

  
コード例 #6
0
def createExtensionTypes(nameOfPackage, pkg, plugins, classes):
    nameOfClass = nameOfPackage + 'ExtensionTypes'
    codeName = nameOfClass + '.h'
    fileOut = open(codeName, 'w')
    fileHeaders.addFilename(fileOut, codeName, nameOfClass)
    fileHeaders.addLicence(fileOut)
    fileOut.write('#ifndef {0}_H\n'.format(nameOfClass))
    fileOut.write('#define {0}_H\n\n'.format(nameOfClass))
    fileOut.write(
        '#include <sbml/packages/{0}/common/{0}fwd.h>\n\n'.format(pkg))
    fileOut.write(
        '#include <sbml/packages/{0}/extension/{1}Extension.h>\n'.format(
            pkg, nameOfPackage))
    fileOut.write(
        '#include <sbml/packages/{0}/extension/{1}SBMLDocumentPlugin.h>\n'.
        format(pkg, nameOfPackage))
    for i in range(0, len(plugins)):
        fileOut.write(
            '#include <sbml/packages/{0}/extension/{1}{2}Plugin.h>\n'.format(
                pkg, nameOfPackage, plugins[i]['sbase']))
    fileOut.write('\n')
    for i in range(0, len(classes)):
        if classes[i]['typecode'] != 'HACK':
            fileOut.write('#include <sbml/packages/{0}/sbml/{1}.h>\n'.format(
                pkg, classes[i]['name']))
    fileOut.write('\n#endif  /* {0}_H */\n\n'.format(nameOfClass))
コード例 #7
0
def createHeader(element):
  nameOfElement = element['name']
  nameOfPackage = element['package']
  sbmltypecode = element['typecode']
  isListOf = element['hasListOf']
  attributes = element['attribs']
  hasChildren = element['hasChildren']
  hasMath = element['hasMath']
  headerName = nameOfElement + '.h'
  header = open(headerName, 'w')
  fileHeaders.addFilename(header, headerName, nameOfElement)
  fileHeaders.addLicence(header)
  writeIncludes(header, nameOfElement, nameOfPackage, attributes, element)
  writeClass(attributes, header, nameOfElement, nameOfPackage, hasChildren, hasMath, False, element)
  if isListOf == True:
    writeListOfHeader.createHeader(element, header)
  writeCPPEnd(header)
  writeCStart(header)
  writeCHeader.createHeader(element, header)
  writeCEnd(header, nameOfElement)

#if len(sys.argv) != 2:
#  print 'Usage: writeHeader.py element'
#else:
#  element = createNewElementDictObj.createFBCObj()
#  createHeader(element)
  

  
コード例 #8
0
def writeCode(name):
    capName = name.upper()
    codeName = name + '-register.cxx'
    fileOut = open(codeName, 'w')
    fileHeaders.addFilename(fileOut, codeName, name)
    fileHeaders.addLicence(fileOut)
    fileOut.write('\n')
    fileOut.write('#ifdef USE_{0}\n'.format(capName))
    fileOut.write('  {0}Extension::init();\n'.format(strFunctions.cap(name)))
    fileOut.write('#endif\n')
コード例 #9
0
def writeHeader(name):
	capName = name.upper()
	codeName = name + '-register.h'
	fileOut = open(codeName, 'w')
	fileHeaders.addFilename(fileOut, codeName, name)
	fileHeaders.addLicence(fileOut)
	fileOut.write('\n')
	fileOut.write('#ifdef USE_{0}\n'.format(capName))
	fileOut.write('  #include <sbml/packages/{0}/extension/{1}Extension.h>\n'.format(name, strFunctions.cap(name)))
	fileOut.write('#endif\n\n')
コード例 #10
0
def writeCode(name):
	capName = name.upper()
	codeName = name + '-register.cxx'
	fileOut = open(codeName, 'w')
	fileHeaders.addFilename(fileOut, codeName, name)
	fileHeaders.addLicence(fileOut)
	fileOut.write('\n')
	fileOut.write('#ifdef USE_{0}\n'.format(capName))
	fileOut.write('  {0}Extension::init();\n'.format(strFunctions.cap(name)))
	fileOut.write('#endif\n')
コード例 #11
0
ファイル: writePluginHeader.py プロジェクト: hsorby/libSEDML
def createHeader(package, plugin):
    nameOfPackage = package['name']
    nameOfPlugin = plugin['sbase']
    nameOfClass = nameOfPackage + nameOfPlugin + 'Plugin'
    codeName = nameOfClass + '.h'
    code = open(codeName, 'w')
    fileHeaders.addFilename(code, codeName, nameOfClass)
    fileHeaders.addLicence(code)
    writeIncludes(code, nameOfPackage, nameOfClass, plugin['extension'])
    writeClassDefn(code, nameOfClass, nameOfPackage, plugin['extension'])
    writeIncludeEnds(code, nameOfClass)
コード例 #12
0
def createHeader(package):
    nameOfPackage = package["name"]
    nameOfClass = nameOfPackage + "Extension"
    codeName = nameOfClass + ".h"
    code = open(codeName, "w")
    fileHeaders.addFilename(code, codeName, nameOfClass)
    fileHeaders.addLicence(code)
    writeIncludes(code, nameOfClass, nameOfPackage)
    writeClassDefn(code, nameOfClass, nameOfPackage)
    writeTypeDefns(code, nameOfClass, nameOfPackage, package["elements"], package["number"])
    writeIncludeEnds(code, nameOfClass)
コード例 #13
0
def writeHeader(name):
    capName = name.upper()
    codeName = name + '-register.h'
    fileOut = open(codeName, 'w')
    fileHeaders.addFilename(fileOut, codeName, name)
    fileHeaders.addLicence(fileOut)
    fileOut.write('\n')
    fileOut.write('#ifdef USE_{0}\n'.format(capName))
    fileOut.write(
        '  #include <sbml/packages/{0}/extension/{1}Extension.h>\n'.format(
            name, strFunctions.cap(name)))
    fileOut.write('#endif\n\n')
コード例 #14
0
def createHeader(package):
    nameOfPackage = package['name']
    nameOfClass = nameOfPackage + 'Extension'
    codeName = nameOfClass + '.h'
    code = open(codeName, 'w')
    fileHeaders.addFilename(code, codeName, nameOfClass)
    fileHeaders.addLicence(code)
    writeIncludes(code, nameOfClass, nameOfPackage)
    writeClassDefn(code, nameOfClass, nameOfPackage, package)
    writeTypeDefns(code, nameOfClass, nameOfPackage, package['elements'],
                   package['number'], package['enums'])
    writeIncludeEnds(code, nameOfClass)
コード例 #15
0
def createHeader(package):
  nameOfPackage = package['name']
  nameOfClass = nameOfPackage + 'SBMLDocumentPlugin'
  codeName = nameOfClass + '.h'
  code = open(codeName, 'w')
  fileHeaders.addFilename(code, codeName, nameOfClass)
  fileHeaders.addLicence(code)
  writeIncludes(code, nameOfClass, nameOfPackage)
  writeClassDefn(code, nameOfClass, nameOfPackage)
  writeIncludeEnds(code, nameOfClass)

  
コード例 #16
0
def writeJavaFiles(name, plugins, classes):
    capName = name.upper()
    codeName = "local-downcast-extension-" + name + ".i"
    fileOut = open(codeName, "w")
    writeBindingsFiles.writeJavaExt(fileOut, name)
    codeName1 = "local-downcast-namespaces-" + name + ".i"
    fileOut1 = open(codeName1, "w")
    writeBindingsFiles.writeJavaNS(fileOut1, name)
    codeName2 = "local-packages-" + name + ".i"
    fileOut2 = open(codeName2, "w")
    fileHeaders.addFilename(fileOut2, codeName2, name)
    fileHeaders.addLicence(fileOut2)
    writeBindingsFiles.writeJava(fileOut2, name, plugins, classes)
コード例 #17
0
def createHeader(package):
  nameOfPackage = package['name']
  nameOfClass = nameOfPackage + 'Extension'
  codeName = nameOfClass + '.h'
  code = open(codeName, 'w')
  fileHeaders.addFilename(code, codeName, nameOfClass)
  fileHeaders.addLicence(code)
  writeIncludes(code, nameOfClass, nameOfPackage)
  writeClassDefn(code, nameOfClass, nameOfPackage)
  writeTypeDefns(code, nameOfClass, nameOfPackage, package['elements'], package['number']) 
  writeIncludeEnds(code, nameOfClass)

  
コード例 #18
0
ファイル: writePluginHeader.py プロジェクト: hovo1990/deviser
def createHeader(package, plugin):
  nameOfPackage = package['name']
  nameOfPlugin = plugin['sbase']
  nameOfClass = nameOfPackage + nameOfPlugin + 'Plugin'
  codeName = nameOfClass + '.h'
  code = open(codeName, 'w')
  fileHeaders.addFilename(code, codeName, nameOfClass)
  fileHeaders.addLicence(code)
  writeIncludes(code, nameOfPackage, nameOfClass, plugin['extension'], plugin['attribs'])
  writeClassDefn(code, nameOfClass, nameOfPackage, plugin['extension'], plugin['attribs'], plugin)
  writeIncludeEnds(code, nameOfClass)

  
コード例 #19
0
def writeCSharpFiles(name, plugins, classes):
	capName = name.upper()
	codeName = 'local-downcast-extension-' + name + '.i'
	fileOut = open(codeName, 'w')
	writeBindingsFiles.writeCSharpExt(fileOut, name)
	codeName1 = 'local-downcast-namespaces-' + name + '.i'
	fileOut1 = open(codeName1, 'w')
	writeBindingsFiles.writeCSharpNS(fileOut1, name)
	codeName2 = 'local-packages-' + name + '.i'
	fileOut2 = open(codeName2, 'w')
	fileHeaders.addFilename(fileOut2, codeName2, name)
	fileHeaders.addLicence(fileOut2)
	writeBindingsFiles.writeCSharp(fileOut2, name, plugins, classes)
コード例 #20
0
def writeJavaFiles(name, plugins, classes):
	capName = name.upper()
	codeName = 'local-downcast-extension-' + name + '.i'
	fileOut = open(codeName, 'w')
	writeBindingsFiles.writeJavaExt(fileOut, name)
	codeName1 = 'local-downcast-namespaces-' + name + '.i'
	fileOut1 = open(codeName1, 'w')
	writeBindingsFiles.writeJavaNS(fileOut1, name)
	codeName2 = 'local-packages-' + name + '.i'
	fileOut2 = open(codeName2, 'w')
	fileHeaders.addFilename(fileOut2, codeName2, name)
	fileHeaders.addLicence(fileOut2)
	writeBindingsFiles.writeJava(fileOut2, name, plugins, classes)
コード例 #21
0
def createConsistencyFiles(pkg, type):
  nameOfElement = pkg + type + 'ConsistencyValidator'
  fileName = nameOfElement + '.h'
  output = open(fileName, 'w')
  generalFunctions.writeInternalStart(output)
  fileHeaders.addFilename(output, fileName, nameOfElement)
  fileHeaders.addLicence(output)
  writeConsistencyHeader(output, nameOfElement, pkg, type)
  fileName1 = nameOfElement + '.cpp'
  output1 = open(fileName1, 'w')
  generalFunctions.writeInternalStart(output1)
  fileHeaders.addFilename(output1, fileName1, nameOfElement)
  fileHeaders.addLicence(output1)
  writeConsistencyFile(output1, nameOfElement, pkg, type)
コード例 #22
0
def createCode(package):
    nameOfPackage = package['name']
    nameOfClass = nameOfPackage + 'Extension'
    plugins = package['plugins']
    codeName = nameOfClass + '.cpp'
    code = open(codeName, 'w')
    fileHeaders.addFilename(code, codeName, nameOfClass)
    fileHeaders.addLicence(code)
    writeIncludes(code, nameOfClass, nameOfPackage, plugins)
    writeClass(code, nameOfClass, nameOfPackage, package['elements'])
    writeTypeDefns(code, nameOfClass, nameOfPackage, package['elements'],
                   package['number'])
    writeInitFunction(code, nameOfPackage, nameOfClass, plugins)
    writeIncludeEnds(code, nameOfClass)
コード例 #23
0
ファイル: writeExtensionCode.py プロジェクト: 0u812/libSEDML
def createCode(package):
  nameOfPackage = package['name']
  nameOfClass = nameOfPackage + 'Extension'
  plugins = package['plugins']
  codeName = nameOfClass + '.cpp'
  code = open(codeName, 'w')
  fileHeaders.addFilename(code, codeName, nameOfClass)
  fileHeaders.addLicence(code)
  writeIncludes(code, nameOfClass, nameOfPackage, plugins)
  writeClass(code, nameOfClass, nameOfPackage, package['elements'])
  writeTypeDefns(code, nameOfClass, nameOfPackage, package['elements'], package['number']) 
  writeInitFunction(code, nameOfPackage, nameOfClass, plugins)
  writeIncludeEnds(code, nameOfClass)

  
コード例 #24
0
def createCode(package):
  nameOfPackage = package['name']
  nameOfClass = nameOfPackage + 'SBMLDocumentPlugin'
  codeName = nameOfClass + '.cpp'
  code = open(codeName, 'w')
  fileHeaders.addFilename(code, codeName, nameOfClass)
  fileHeaders.addLicence(code)
  inputFile = os.path.dirname(__file__)  + '/templateDocPluginCPP.txt' 
  input = open(inputFile, 'r')
  for line in input:
    if line[0:13] != 'TEMPLATE_STOP':
      line = replaceTags(line, nameOfPackage)
      code.write(line)
    else:
      break
コード例 #25
0
def createErrorFiles(pkg, offset, classes):
  nameOfElement = pkg + 'SBMLError'
  fileName = nameOfElement + '.h'
  output = open(fileName, 'w')
  fileHeaders.addFilename(output, fileName, nameOfElement)
  fileHeaders.addLicence(output)
  writeError(output, nameOfElement, pkg, offset, classes)
  nameOfElement1 = pkg + 'SBMLErrorTable'
  fileName1 = nameOfElement1 + '.h'
  output1 = open(fileName1, 'w')
  fileHeaders.addFilename(output1, fileName1, nameOfElement1)
  fileHeaders.addLicence(output1)
  fileName2 = nameOfElement + '.txt'
  output2 = open(fileName2, 'w')
  writeErrorTable(output1, nameOfElement1, pkg, offset, classes)
コード例 #26
0
def createCode(package, plugin):
    nameOfPackage = package['name']
    nameOfPlugin = plugin['sbase']
    nameOfClass = nameOfPackage + nameOfPlugin + 'Plugin'
    codeName = nameOfClass + '.cpp'
    code = open(codeName, 'w')
    fileHeaders.addFilename(code, codeName, nameOfClass)
    fileHeaders.addLicence(code)
    writeIncludes(code, nameOfPackage, nameOfClass)
    writeClassDefn(code, nameOfClass, nameOfPackage, plugin['extension'],
                   plugin['attribs'], plugin)

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

    writeIncludeEnds(code, nameOfClass)
コード例 #27
0
def createConstraintsFile(pkg, type):
  nameOfElement = pkg + type + 'ConsistencyConstraints'
  fileName = nameOfElement + '.cpp'
  output = open(fileName, 'w')
  generalFunctions.writeInternalStart(output)
  fileHeaders.addFilename(output, fileName, nameOfElement)
  fileHeaders.addLicence(output)
  output.write('\n#ifndef  AddingConstraintsToValidator\n\n')
  output.write('#include <sbml/validator/VConstraint.h>\n\n')
  output.write('#include <sbml/packages/{0}/validator/{1}SBMLError.h>\n\n'.format(pkg.lower(), pkg))
  output.write('#endif  /* AddingConstrainstToValidator */\n\n')
  output.write('#include <sbml/validator/ConstraintMacros.h>\n\n')
  output.write('/** @cond doxygenIgnored */\n\n')
  output.write('using namespace std;\n\n')
  output.write('/** @endcond */\n\n')
  output.write('/** PUT CONSTRAINTS HERE */\n\n')
  generalFunctions.writeInternalEnd(output)
コード例 #28
0
def createExtensionTypes(nameOfPackage, pkg, plugins, classes):
  nameOfClass = nameOfPackage + 'ExtensionTypes'
  codeName = nameOfClass + '.h'
  fileOut = open(codeName, 'w')
  fileHeaders.addFilename(fileOut, codeName, nameOfClass)
  fileHeaders.addLicence(fileOut)
  fileOut.write('#ifndef {0}_H\n'.format(nameOfClass))
  fileOut.write('#define {0}_H\n\n'.format(nameOfClass))
  fileOut.write('#include <sbml/packages/{0}/common/{0}fwd.h>\n\n'.format(pkg))
  fileOut.write('#include <sbml/packages/{0}/extension/{1}Extension.h>\n'.format(pkg, nameOfPackage))
  fileOut.write('#include <sbml/packages/{0}/extension/{1}SBMLDocumentPlugin.h>\n'.format(pkg, nameOfPackage))
  for i in range (0, len(plugins)):
    fileOut.write('#include <sbml/packages/{0}/extension/{1}{2}Plugin.h>\n'.format(pkg, nameOfPackage, plugins[i]['sbase']))
  fileOut.write('\n')
  for i in range (0, len(classes)):
    if classes[i]['typecode'] != 'HACK':
      fileOut.write('#include <sbml/packages/{0}/sbml/{1}.h>\n'.format(pkg, classes[i]['name']))
  fileOut.write('\n#endif  /* {0}_H */\n\n'.format(nameOfClass))
コード例 #29
0
def createCode(package, plugin):
  nameOfPackage = package['name']
  nameOfPlugin = plugin['sbase']
  nameOfClass = nameOfPackage + nameOfPlugin + 'Plugin'
  codeName = nameOfClass + '.cpp'
  code = open(codeName, 'w')
  fileHeaders.addFilename(code, codeName, nameOfClass)
  fileHeaders.addLicence(code)
  writeIncludes(code, nameOfPackage, nameOfClass)
  writeClassDefn(code, nameOfClass, nameOfPackage, plugin['extension'],plugin['attribs'], plugin)
  
  if plugin.has_key('addDefs'):
    code.write(open(plugin['addDefs'], 'r').read())

  writeIncludeEnds(code, nameOfClass)



  
コード例 #30
0
def createCode(package):
    nameOfPackage = package['name']
    nameOfClass = nameOfPackage + 'Extension'
    plugins = package['plugins']
    offset = package['offset']
    codeName = nameOfClass + '.cpp'
    code = open(codeName, 'w')
    fileHeaders.addFilename(code, codeName, nameOfClass)
    fileHeaders.addLicence(code)
    writeIncludes(code, nameOfClass, nameOfPackage, plugins)
    writeClass(code, nameOfClass, nameOfPackage, package['elements'])
    writeTypeDefns(code, nameOfClass, nameOfPackage, package['elements'],
                   package['number'], package['enums'])
    writeInitFunction(code, nameOfPackage, nameOfClass, plugins)
    writeErrorFunction(code, nameOfPackage, nameOfClass, offset)

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

    writeIncludeEnds(code, nameOfClass)
コード例 #31
0
def createHeader(element):
  nameOfElement = element['name']
  nameOfPackage = element['package']
  sedmltypecode = element['typecode']
  hasSedListOf = element['hasSedListOf']
  attributes = element['attribs']
  hasChildren = element['hasChildren']
  hasMath = element['hasMath']
  headerName = nameOfElement + '.h'
  header = open(headerName, 'w')
  fileHeaders.addFilename(header, headerName, nameOfElement)
  fileHeaders.addLicence(header)
  writeIncludes(header, nameOfElement, nameOfPackage)
  writeClass(attributes, header, nameOfElement, nameOfPackage, hasChildren, hasMath, False, element)
  if hasSedListOf == True:
    writeListOfHeader.createHeader(element, header)
  writeCPPEnd(header)
  writeCStart(header)
  writeCHeader.createHeader(element, header)
  writeCEnd(header, nameOfElement)
コード例 #32
0
def createCode(package):
  nameOfPackage = package['name']
  nameOfClass = nameOfPackage + 'Extension'
  plugins = package['plugins']
  offset = package['offset']
  codeName = nameOfClass + '.cpp'
  code = open(codeName, 'w')
  fileHeaders.addFilename(code, codeName, nameOfClass)
  fileHeaders.addLicence(code)
  writeIncludes(code, nameOfClass, nameOfPackage, plugins)
  writeClass(code, nameOfClass, nameOfPackage, package['elements'])
  writeTypeDefns(code, nameOfClass, nameOfPackage, package['elements'], package['number'], package['enums']) 
  writeInitFunction(code, nameOfPackage, nameOfClass, plugins)
  writeErrorFunction(code, nameOfPackage, nameOfClass, offset)

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

  writeIncludeEnds(code, nameOfClass)

  
コード例 #33
0
def createFWD(pkg, classes):
    nameOfClass = pkg + 'fwd'
    codeName = nameOfClass + '.h'
    fileOut = open(codeName, 'w')
    fileHeaders.addFilename(fileOut, codeName, nameOfClass)
    fileHeaders.addLicence(fileOut)
    fileOut.write('#ifndef {0}_H\n'.format(nameOfClass))
    fileOut.write('#define {0}_H\n\n'.format(nameOfClass))
    fileOut.write('/**\n')
    fileOut.write(' * Forward declaration of all opaque C types.\n')
    fileOut.write(' *\n')
    fileOut.write(
        ' * Declaring all types up-front avoids "redefinition of type Foo" compile\n'
    )
    fileOut.write(
        ' * errors and allows our combined C/C++ headers to depend minimally upon\n'
    )
    fileOut.write(
        ' * each other.  Put another way, the type definitions below serve the same\n'
    )
    fileOut.write(
        ' * purpose as "class Foo;" forward declarations in C++ code.\n')
    fileOut.write(' */\n\n')
    fileOut.write('#ifdef __cplusplus\n')
    fileOut.write('#  define CLASS_OR_STRUCT class\n')
    fileOut.write('#else\n')
    fileOut.write('#  define CLASS_OR_STRUCT struct\n')
    fileOut.write('#endif  /* __cplusplus */	\n\n')
    fileOut.write('LIBSBML_CPP_NAMESPACE_BEGIN\n\n')
    for i in range(0, len(classes)):
        if classes[i]['typecode'] != 'HACK':
            fileOut.write('typedef CLASS_OR_STRUCT {0}    {0}_t;\n'.format(
                classes[i]['name']))
    fileOut.write('\nLIBSBML_CPP_NAMESPACE_END\n\n')
    fileOut.write('#undef CLASS_OR_STRUCT\n\n')
    fileOut.write('\n#endif  /* {0}_H */\n\n'.format(nameOfClass))
コード例 #34
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)
  

  
コード例 #35
0
ファイル: writeCode.py プロジェクト: skeating/auto-generator
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)
  

  
コード例 #36
0
def createValidatorFile(pkg, classes):
  inputFile = os.path.dirname(__file__)  + '/templateValidCPP.txt' 
  fileName = pkg + 'Validator.cpp'
  output = open(fileName, 'w')
  nameOfElement = pkg + 'Validator'
  fileHeaders.addFilename(output, fileName, nameOfElement)
  fileHeaders.addLicence(output)
  output.write('#include <sbml/validator/VConstraint.h>\n\n')
  output.write('#include <sbml/packages/{0}/common/{1}ExtensionTypes.h>\n'.format(pkg.lower(), pkg))
  output.write('#include <sbml/packages/{0}/validator/{1}Validator.h>\n\n'.format(pkg.lower(), pkg))
  generalFunctions.writeInternalStart(output)
  output.write('using namespace std;\n\n')
  generalFunctions.writeInternalEnd(output)
  output.write('LIBSBML_CPP_NAMESPACE_BEGIN\n\n')
  input = open(inputFile, 'r')
  for line in input:
    if line[0:13] != 'TEMPLATE_STOP':
      line = replaceTags(line, pkg)
      output.write(line)
    else:
      break
  for i in range (0, len(classes)):
    if classes[i]['typecode'] != 'HACK':
      output.write('  ConstraintSet<{0}>      m{0};\n'.format(classes[i]['name']))
  for line in input:
    if line[0:13] != 'TEMPLATE_STOP':
      line = replaceTags(line, pkg)
      output.write(line)
    else:
      break
  for i in range (0, len(classes)):
    if classes[i]['typecode'] != 'HACK':
      output.write('  if (dynamic_cast< TConstraint<{0}>* >(c) != NULL)\n'.format(classes[i]['name']))
      output.write('  {\n')
      output.write('    m{0}.add( static_cast< TConstraint<{0}>* >(c) );\n'.format(classes[i]['name']))
      output.write('    return;\n  }\n\n')
  for line in input:
    if line[0:13] != 'TEMPLATE_STOP':
      line = replaceTags(line, pkg)
      output.write(line)
    else:
      break
  for i in range (0, len(classes)):
    if classes[i]['typecode'] != 'HACK':
      output.write('  bool visit (const {0} &x)\n'.format(classes[i]['name']))
      output.write('  {\n')
      output.write('    v.m{0}Constraints->m{1}.applyTo(m, x);\n'.format(pkg, classes[i]['name']))
      output.write('    return !v.m{0}Constraints->m{1}.empty();\n'.format(pkg, classes[i]['name']))
      output.write('  }\n\n')
  output.write('  virtual bool visit(const SBase &x)\n')
  output.write('  {\n')
  output.write('    if (x.getPackageName() != "{0}")\n'.format(pkg.lower()))
  output.write('    {\n      return SBMLVisitor::visit(x);\n    }\n\n')
  output.write('    int code = x.getTypeCode();\n\n')
  output.write('    const ListOf* list = dynamic_cast<const ListOf*>(&x);\n\n')
  output.write('    if (list != NULL)\n')
  output.write('    {\n')
  output.write('      return SBMLVisitor::visit(x);\n')
  output.write('    }\n')
  output.write('    else\n')
  output.write('    {\n')
  order = 0
  for i in range (0, len(classes)):
    if classes[i]['typecode'] != 'HACK':
      if order == 0:
        output.write('      if (code == {0})\n'.format(classes[i]['typecode']))
        order = order + 1
      else:
        output.write('      else if (code == {0})\n'.format(classes[i]['typecode']))
      output.write('      {\n')
      output.write('        return visit((const {0}&)x);\n'.format(classes[i]['name']))
      output.write('      }\n')
  for line in input:
    if line[0:13] != 'TEMPLATE_STOP':
      line = replaceTags(line, pkg)
      output.write(line)
    else:
      break
  input.close()
  output.close()