def writeAtt(atttype, name, output, constType, pkg):
    if atttype == 'SId' or atttype == 'SIdRef' or atttype == 'UnitSId' or atttype == 'UnitSIdRef' or atttype == 'string':
        output.write('  , m{0} ("")\n'.format(strFunctions.cap(name)))
    elif atttype == 'element' or atttype == 'XMLNode*' or atttype == 'DimensionDescription*':
        output.write('  , m{0} (NULL)\n'.format(strFunctions.cap(name)))
    elif atttype == 'lo_element':
        output.write('  , m{0} ('.format(strFunctions.capp(name)))
        if constType == 0:
            output.write(')\n')
        elif constType == 1:
            output.write('level, version)\n')
        elif constType == 2:
            output.write('{0}ns)\n'.format(pkg))
    elif atttype == 'double':
        output.write('  , m{0} (numeric_limits<double>::quiet_NaN())\n'.format(
            strFunctions.cap(name)))
        output.write('  , mIsSet{0} (false)\n'.format(strFunctions.cap(name)))
    elif atttype == 'int' or atttype == 'uint':
        output.write('  , m{0} (SEDML_INT_MAX)\n'.format(
            strFunctions.cap(name)))
        output.write('  , mIsSet{0} (false)\n'.format(strFunctions.cap(name)))
    elif atttype == 'bool':
        output.write('  , m{0} (false)\n'.format(strFunctions.cap(name)))
        output.write('  , mIsSet{0} (false)\n'.format(strFunctions.cap(name)))
    elif atttype == 'std::vector<double>':
        output.write('  , m{0} ()\n'.format(strFunctions.capp(name)))
    else:
        output.write('  FIX ME   {0};\n'.format(name))
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 == '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':
    output.write('  {0}   m{1};\n'.format(generalFunctions.writeListOf(capAttName), strFunctions.capp(attName)))
  elif attTypeCode == 'XMLNode*':
    output.write('  {0}   m{1};\n'.format('XMLNode*', capAttName))
  elif attTypeCode == 'DimensionDescription*':
    output.write('  {0}   m{1};\n'.format('DimensionDescription*', 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 attType == 'std::vector<double>':
    output.write('  std::vector<double>  m{0};\n'.format( strFunctions.capp(attName)))    
  else:
    output.write('  FIX ME   {0};\n'.format(attName))
Esempio n. 3
0
def writeRemoveFunctions(output,
                         element,
                         type,
                         subelement=False,
                         topelement="",
                         name=""):
    listOf = generalFunctions.writeListOf(element)
    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('  return 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}*>(SedListOf::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('  return 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('  SedBase* item = NULL;\n')
        output.write('  vector<SedBase*>::iterator result;\n\n')
        output.write(
            '  result = find_if( mItems.begin(), mItems.end(), SedIdEq<{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('  return static_cast <{0}*> (item);\n'.format(type))
        output.write('}\n\n\n')
def writeIsSetCode(attrib, output, element):
    att = generalFunctions.parseAttribute(attrib)
    attName = att[0]
    capAttName = att[1]
    attType = att[2]
    attTypeCode = att[3]
    num = att[4]
    if attType == 'lo_element':
        return
    elif attrib['type'] == 'std::vector<double>':
        output.write('/**\n')
        output.write(
            ' * Predicate returning @c true or @c false depending on ')
        output.write('whether this\n * {0}\'s \"{1}\" '.format(
            element, attName))
        output.write('element has elements set.\n *\n')
        output.write(' * @return @c true if this {0}\'s \"{1}\"'.format(
            element, attName))
        output.write(' element has been set,\n')
        output.write(' * otherwise @c false is returned.\n')
        output.write(' */\n')
        output.write('bool\n{0}::has{1}() const\n'.format(
            element, strFunctions.capp(capAttName)))
        output.write('{\n')
        output.write('  return m{0}.size() > 0;\n'.format(
            strFunctions.capp(capAttName)))
        output.write('}\n\n\n')
        output.write('/**\n')
        output.write(
            ' * Returning the number of elements in this\n * {0}\'s \"{1}\" '.
            format(element, attName))
        output.write('.\n *\n')
        output.write(
            ' * @return number of elements in this {0}\'s \"{1}\"'.format(
                element, attName))
        output.write('\n')
        output.write(' */\n')
        output.write('unsigned int\n{0}::getNum{1}() const\n'.format(
            element, strFunctions.capp(capAttName)))
        output.write('{\n')
        output.write('  return (unsigned int)m{0}.size();\n'.format(
            strFunctions.capp(capAttName)))
        output.write('}\n\n\n')
    else:
        output.write('/*\n')
        output.write(' * Returns true/false if {0} is set.\n'.format(attName))
        output.write(' */\n')
        output.write('bool\n')
        output.write('{0}::isSet{1}() const\n'.format(element, capAttName))
        output.write('{\n')
        if attType == 'string':
            output.write(
                '  return (m{0}.empty() == false);\n'.format(capAttName))
        elif attType == 'element' or attType == 'XMLNode*' or attType == 'DimensionDescription*':
            output.write('  return (m{0} != NULL);\n'.format(capAttName))
        elif num == True:
            output.write('  return mIsSet{0};\n'.format(capAttName))
        elif attType == 'boolean':
            output.write('  return mIsSet{0};\n'.format(capAttName))
        output.write('}\n\n\n')
Esempio n. 5
0
def writeAtt(atttype, name, output, constType, pkg):
  if atttype == 'SId' or atttype == 'SIdRef' or atttype == 'UnitSId' or atttype == 'UnitSIdRef' or atttype == 'string':
    output.write('\t, m{0} ("")\n'.format(strFunctions.cap(name)))
  elif atttype == 'element' or atttype == 'XMLNode*':
    output.write('\t, m{0} (NULL)\n'.format(strFunctions.cap(name)))
  elif atttype == 'lo_element':
    output.write('\t, m{0} ('.format(strFunctions.capp(name)))
    if constType == 0:
      output.write(')\n')
    elif constType == 1:
      output.write('level, version)\n')
    elif constType == 2:
      output.write('{0}ns)\n'.format(pkg))
  elif atttype == 'double':
    output.write('\t, m{0} (numeric_limits<double>::quiet_NaN())\n'.format(strFunctions.cap(name)))
    output.write('\t, mIsSet{0} (false)\n'.format(strFunctions.cap(name)))
  elif atttype == 'int' or atttype == 'uint':
    output.write('\t, m{0} (SEDML_INT_MAX)\n'.format(strFunctions.cap(name)))
    output.write('\t, mIsSet{0} (false)\n'.format(strFunctions.cap(name)))
  elif atttype == 'bool':
    output.write('\t, m{0} (false)\n'.format(strFunctions.cap(name)))
    output.write('\t, mIsSet{0} (false)\n'.format(strFunctions.cap(name)))
  elif atttype == 'std::vector<double>':
    output.write('\t, m{0} ()\n'.format(strFunctions.capp(name)))
  else:
    output.write('\tFIX ME   {0};\n'.format(name))
def writeCreateObject(outFile, element, sbmltypecode, attribs, isSedListOf, hasChildren=False, hasMath=False,baseClass='SedBase'):  
  if (isSedListOf == True or hasChildren == False) and baseClass  == 'SedBase':
    return;
  outFile.write('/**\n')
  outFile.write(' * return the SEDML object corresponding to next XMLToken.\n')
  outFile.write(' */\n')
  outFile.write('SedBase*\n{0}::createObject(XMLInputStream& stream)\n'.format(element))
  outFile.write('{\n')
  if baseClass == 'SedBase':
    outFile.write('  SedBase* object = NULL;\n\n')
  else:
    outFile.write('  SedBase* object = {0}::createObject(stream);\n\n'.format(baseClass))
  if hasChildren or hasMath:
    outFile.write('  const string& name   = stream.peek().getName();\n\n')
  for i in range (0, len(attribs)):
    current = attribs[i]
    if current.has_key('lo_elementName'):        
      outFile.write('  if (name == "{0}")\n'.format(current['lo_elementName']))	
      outFile.write('  {\n')	
      outFile.write('    object = &m{0};\n'.format(strFunctions.capp(current['name'])))	
      outFile.write('  }\n\n')
    elif current['type'] == 'lo_element':
      outFile.write('  if (name == "listOf{0}")\n'.format(strFunctions.capp(current['name'])))	
      outFile.write('  {\n')	
      outFile.write('    object = &m{0};\n'.format(strFunctions.capp(current['name'])))	
      outFile.write('  }\n\n')
    elif current['type'] == 'element' and (current['name'] !='Math' and current['name'] != 'math'):
      outFile.write('  if (name == "{0}")\n'.format(current['name']))	
      outFile.write('  {\n')	
      outFile.write('    m{0}= new {1}();\n'.format(strFunctions.cap(current['name']), current['element']))	
      outFile.write('    object = m{0};\n'.format(strFunctions.cap(current['name'])))	
      outFile.write('  }\n\n')
  outFile.write('  connectToChild();\n\n')
  outFile.write('  return object;\n')  
  outFile.write('}\n\n\n')  
Esempio n. 7
0
def writeCreateObject(outFile, element, sbmltypecode, attribs, isSedListOf, hasChildren=False, hasMath=False,baseClass='SedBase'):  
  if (isSedListOf == True or hasChildren == False) and baseClass  == 'SedBase':
    return;
  outFile.write('/**\n')
  outFile.write(' * return the SEDML object corresponding to next XMLToken.\n')
  outFile.write(' */\n')
  outFile.write('SedBase*\n{0}::createObject(XMLInputStream& stream)\n'.format(element))
  outFile.write('{\n')
  if baseClass == 'SedBase':
    outFile.write('\tSedBase* object = NULL;\n\n')
  else:
    outFile.write('\tSedBase* object = {0}::createObject(stream);\n\n'.format(baseClass))
  if hasChildren or hasMath:
    outFile.write('\tconst string& name   = stream.peek().getName();\n\n')
  for i in range (0, len(attribs)):
    current = attribs[i]
    if current.has_key('lo_elementName'):        
      outFile.write('\tif (name == "{0}")\n'.format(current['lo_elementName']))	
      outFile.write('\t{\n')	
      outFile.write('\t\tobject = &m{0};\n'.format(strFunctions.capp(current['name'])))	
      outFile.write('\t}\n\n')
    elif current['type'] == 'lo_element':
      outFile.write('\tif (name == "listOf{0}")\n'.format(strFunctions.capp(current['name'])))	
      outFile.write('\t{\n')	
      outFile.write('\t\tobject = &m{0};\n'.format(strFunctions.capp(current['name'])))	
      outFile.write('\t}\n\n')
    elif current['type'] == 'element' and (current['name'] !='Math' and current['name'] != 'math'):
      outFile.write('\tif (name == "{0}")\n'.format(current['name']))	
      outFile.write('\t{\n')	
      outFile.write('\t\tm{0}= new {1}();\n'.format(strFunctions.cap(current['name']), current['element']))	
      outFile.write('\t\tobject = m{0};\n'.format(strFunctions.cap(current['name'])))	
      outFile.write('\t}\n\n')
  outFile.write('\tconnectToChild();\n\n')
  outFile.write('\treturn object;\n')  
  outFile.write('}\n\n\n')  
Esempio n. 8
0
def writeUnsetCode(attrib, output, element):
  att = generalFunctions.parseAttribute(attrib)
  attName = att[0]
  capAttName = att[1]
  attType = att[2]
  attTypeCode = att[3]
  num = att[4]
  if attType == 'lo_element':
    return
  elif attrib['type'] == 'std::vector<double>':
    output.write('/**\n')
    output.write(' * Clears the \"{0}\"'.format(attName))
    output.write(' element of this {0}.\n'.format(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 LIBSEDML_OPERATION_SUCCESS\n')
    output.write(' * @li LIBSEDML_OPERATION_FAILED\n')
    output.write(' */\n')
    output.write('int\n{0}::clear{1}()\n'.format(element, strFunctions.capp(capAttName)))
    output.write('{\n')
    output.write('\tm{0}.clear();\n'.format(strFunctions.capp(capAttName)))
    output.write('\treturn LIBSEDML_OPERATION_SUCCESS;\n')
    output.write('}\n\n\n')
  else:    
    output.write('/*\n')
    output.write(' * Unsets {0} and returns value indicating success.\n'.format(attName))
    output.write(' */\n')
    output.write('int\n')
    output.write('{0}::unset{1}()\n'.format(element, capAttName))
    output.write('{\n')
    if attType == 'string':
      output.write('\tm{0}.erase();\n\n'.format(capAttName))
      output.write('\tif (m{0}.empty() == true)\n'.format(capAttName))
      output.write('\t{\n\t\treturn LIBSEDML_OPERATION_SUCCESS;\n\t}\n')
      output.write('\telse\n\t{\n')
      output.write('\t\treturn LIBSEDML_OPERATION_FAILED;\n\t}\n')
    elif num == True:
      if attType == 'double':
        output.write('\tm{0} = numeric_limits<double>::quiet_NaN();\n'.format(capAttName))
      else:
        output.write('\tm{0} = SEDML_INT_MAX;\n'.format(capAttName))
      output.write('\tmIsSet{0} = false;\n\n'.format(capAttName))
      output.write('\tif (isSet{0}() == false)\n'.format(capAttName))
      output.write('\t{\n\t\treturn LIBSEDML_OPERATION_SUCCESS;\n\t}\n')
      output.write('\telse\n\t{\n')
      output.write('\t\treturn LIBSEDML_OPERATION_FAILED;\n\t}\n')
    elif attType == 'boolean':
      output.write('\tm{0} = false;\n'.format(capAttName))
      output.write('\tmIsSet{0} = false;\n'.format(capAttName))
      output.write('\treturn LIBSEDML_OPERATION_SUCCESS;\n')
    elif attType == 'element' or attType == 'XMLNode*':
      output.write('\tdelete m{0};\n'.format(capAttName))
      output.write('\tm{0} = NULL;\n'.format(capAttName))
      output.write('\treturn LIBSEDML_OPERATION_SUCCESS;\n')
    output.write('}\n\n\n')
def writeWriteElementsCPPCode(outFile, element, attributes, hasChildren=False, hasMath=False, baseClass='SedBase'):
  writeInternalStart(outFile)
  outFile.write('/*\n')
  outFile.write(' * write contained elements\n')
  outFile.write(' */\n')
  outFile.write('void\n{0}::writeElements (XMLOutputStream& stream) const\n'.format(element))
  outFile.write('{\n')
  outFile.write('  {0}::writeElements(stream);\n'.format(baseClass))
  if hasChildren == True:
    for i in range(0, len(attributes)):
      if attributes[i]['type'] == 'element' and (attributes[i]['name'] != 'Math' and attributes[i]['name'] != 'math'):
        outFile.write('  if (isSet{0}() == true)\n'.format(strFunctions.cap(attributes[i]['name'])))
        outFile.write('  {\n    ')
        outFile.write('m{0}->write(stream);'.format(strFunctions.cap(attributes[i]['name'])))
        outFile.write('\n  }\n')		
      if attributes[i]['type'] == 'lo_element':
        outFile.write('  if (getNum{0}() > 0)\n'.format(strFunctions.capp(attributes[i]['name'])))
        outFile.write('  {\n    ')
        outFile.write('m{0}.write(stream);'.format(strFunctions.capp(attributes[i]['name'])))
        outFile.write('\n  }\n')
  if containsType(attributes, 'DimensionDescription*'):
    node = getByType(attributes, 'DimensionDescription*')
    outFile.write('  if (isSet{0}() == true)\n'.format(strFunctions.cap(node['name'])))
    outFile.write('  {\n    ')
    outFile.write('m{0}->write(stream);'.format(strFunctions.cap(node['name'])))
    outFile.write('\n  }\n')		
  if containsType(attributes, 'XMLNode*'):
    node = getByType(attributes, 'XMLNode*')
    outFile.write('  if (isSet{0}() == true)\n'.format(strFunctions.cap(node['name'])))
    outFile.write('  {\n    ')
    outFile.write('stream.startElement("{0}");\n'.format(node['name']))
    outFile.write('    stream << *m{0};\n'.format(strFunctions.cap(node['name'])))
    outFile.write('    stream.endElement("{0}");\n'.format(node['name']))
    outFile.write('\n  }\n')		
  if containsType(attributes, 'std::vector<double>'):
    vector = getByType(attributes, 'std::vector<double>')
    outFile.write('  if(has{0}())\n'.format(strFunctions.capp(vector['name'])))
    outFile.write('  {\n')
    outFile.write('    for (std::vector<double>::const_iterator it = m{0}.begin(); it != m{0}.end(); ++it)\n'.format(strFunctions.capp(vector['name'])))
    outFile.write('    {\n')
    outFile.write('      stream.startElement("{0}");\n'.format(vector['name']))
    outFile.write('      stream.setAutoIndent(false);\n')
    outFile.write('      stream << " " << *it << " ";\n')
    outFile.write('      stream.endElement("{0}");\n'.format(vector['name']))
    outFile.write('      stream.setAutoIndent(true);\n')
    outFile.write('    }\n')
    outFile.write('  }\n')
  if hasMath == True:
    for i in range(0, len(attributes)):
      if attributes[i]['type'] == 'element' and attributes[i]['name'] == 'Math' or attributes[i]['name'] == 'math':
        outFile.write('  if (isSet{0}() == true)\n'.format('Math'))
        outFile.write('  {\n    writeMathML(getMath(), stream, NULL);\n  }\n')
  outFile.write('}\n\n\n')
  writeInternalEnd(outFile)
Esempio n. 10
0
def writeGetCode(attrib, output, element):
  att = generalFunctions.parseAttribute(attrib)
  attName = att[0]
  capAttName = att[1]
  attType = att[2]
  attTypeCode = att[3]
  if attType == 'lo_element':
    return
  if attType == 'std::vector<double>': 
    output.write('/*\n')
    output.write(' * Returns the value of the \"{0}\"'.format(attName))
    output.write(' attribute of this {0}.\n'.format(element))
    output.write(' */\n')
    output.write('const {0}&\n'.format(attTypeCode))
    output.write('{0}::get{1}() const\n'.format(element, strFunctions.capp(capAttName)))
    output.write('{\n')
    output.write('\treturn m{0};\n'.format(strFunctions.capp(capAttName)))
    output.write('}\n\n\n')
    output.write('/*\n')
    output.write(' * Returns the value of the \"{0}\"'.format(attName))
    output.write(' attribute of this {0}.\n'.format(element))
    output.write(' */\n')
    output.write('{0}&\n'.format(attTypeCode))
    output.write('{0}::get{1}()\n'.format(element, strFunctions.capp(capAttName)))
    output.write('{\n')
    output.write('\treturn m{0};\n'.format(strFunctions.capp(capAttName)))
    output.write('}\n\n\n')
  else: 
    output.write('/*\n')
    output.write(' * Returns the value of the \"{0}\"'.format(attName))
    output.write(' attribute of this {0}.\n'.format(element))
    output.write(' */\n')
    output.write('const {0}\n'.format(attTypeCode))
    output.write('{0}::get{1}() const\n'.format(element, capAttName))
    output.write('{\n')
    output.write('\treturn m{0};\n'.format(capAttName))
    output.write('}\n\n\n')
  if attType == 'element' and attName != 'math':
    output.write('/*\n')
    output.write(' * Creates a new \"{0}\"'.format(attName))
    output.write(' element of this {0} and returns it.\n'.format(element))
    output.write(' */\n')
    output.write('{0}\n'.format(attTypeCode))
    output.write('{0}::create{1}()\n'.format(element, capAttName))
    output.write('{\n')
    output.write('\tm{0} = new {1}();\n'.format(capAttName, attrib['element']))
    output.write('\treturn m{0};\n'.format(capAttName))
    output.write('}\n\n\n')
Esempio n. 11
0
def writeIsSetCode(attrib, output, element):
  att = generalFunctions.parseAttribute(attrib)
  attName = att[0]
  capAttName = att[1]
  attType = att[2]
  attTypeCode = att[3]
  num = att[4]
  if attType == 'lo_element':
    return
  elif attrib['type'] == 'std::vector<double>':
    output.write('/**\n')
    output.write(' * Predicate returning @c true or @c false depending on ')
    output.write('whether this\n * {0}\'s \"{1}\" '.format(element, attName))
    output.write('element has elements set.\n *\n')
    output.write(' * @return @c true if this {0}\'s \"{1}\"'.format(element, attName))
    output.write(' element has been set,\n')
    output.write(' * otherwise @c false is returned.\n')
    output.write(' */\n')
    output.write('bool\n{0}::has{1}() const\n'.format(element, strFunctions.capp(capAttName)))  
    output.write('{\n')
    output.write('\treturn m{0}.size() > 0;\n'.format(strFunctions.capp(capAttName)))
    output.write('}\n\n\n')
    output.write('/**\n')
    output.write(' * Returning the number of elements in this\n * {0}\'s \"{1}\" '.format(element, attName))
    output.write('.\n *\n')
    output.write(' * @return number of elements in this {0}\'s \"{1}\"'.format(element, attName))
    output.write(' \n')
    output.write(' */\n')
    output.write('unsigned int\n{0}::getNum{1}() const\n'.format(element, strFunctions.capp(capAttName)))  
    output.write('{\n')
    output.write('\treturn (unsigned int)m{0}.size();\n'.format(strFunctions.capp(capAttName)))
    output.write('}\n\n\n')
  else:
    output.write('/*\n')
    output.write(' * Returns true/false if {0} is set.\n'.format(attName))
    output.write(' */\n')
    output.write('bool\n')
    output.write('{0}::isSet{1}() const\n'.format(element, capAttName))
    output.write('{\n')
    if attType == 'string':
      output.write('\treturn (m{0}.empty() == false);\n'.format(capAttName))
    elif attType == 'element' or attType == 'XMLNode*':
      output.write('\treturn (m{0} != NULL);\n'.format(capAttName))
    elif num == True:
      output.write('\treturn mIsSet{0};\n'.format(capAttName))
    elif attType == 'boolean':
      output.write('\treturn mIsSet{0};\n'.format(capAttName))
    output.write('}\n\n\n')
Esempio n. 12
0
def writeReadOtherXMLCPPCode(outFile, element, hasMath = True, attribs = None, baseClass='SedBase'):
  writeInternalStart(outFile)
  outFile.write('bool\n{0}::readOtherXML (XMLInputStream& stream)\n'.format(element))
  outFile.write('{\n')
  outFile.write('\tbool          read = false;\n')
  outFile.write('\tconst string& name = stream.peek().getName();\n\n')
  if hasMath == True: 
    outFile.write('\tif (name == "math")\n\t{\n')
    outFile.write('\t\tconst XMLToken elem = stream.peek();\n')
    outFile.write('\t\tconst std::string prefix = checkMathMLNamespace(elem);\n\n')
    #outFile.write('\t\tif (stream.getSedNamespaces() == NULL)\n\t\t{\n')
    #outFile.write('\t\t\tstream.setSedNamespaces(new SedNamespaces(getLevel(), getVersion()));\n\t\t}\n\n')
    outFile.write('\t\tdelete mMath;\n')
    outFile.write('\t\tmMath = readMathML(stream, prefix);\n')
    #outFile.write('\t\tif (mMath != NULL)\n\t\t{\n\t\t\tmMath->setParentSEDMLObject(this);\n\t\t}\n')
    outFile.write('\t\tread = true;\n\t}\n\n')
  elif containsType(attribs, 'std::vector<double>'):
    elem = getByType(attribs, 'std::vector<double>')
    outFile.write('\twhile (stream.peek().getName() == "{0}")\n'.format(elem['name']))
    outFile.write('\t{\n')
    outFile.write('\t  stream.next(); // consume start\n')
    outFile.write('\t  stringstream text;\n')
    outFile.write('\t  while(stream.isGood() && stream.peek().isText())\n')
    outFile.write('\t    text << stream.next().getCharacters();\n')
    outFile.write('\t  double value; text >> value;\n')
    outFile.write('\t  if (!text.fail())\n')
    outFile.write('\t    m{0}.push_back(value);\n'.format(strFunctions.capp(elem['name'])))
    outFile.write('\t  stream.next(); // consume end\n')
    outFile.write('\t  read = true;\n')
    outFile.write('\t}\n')
  outFile.write('\tif ({0}::readOtherXML(stream))\n'.format(baseClass))
  outFile.write('\t{\n\t\tread = true;\n\t}\n')
  outFile.write('\treturn read;\n')
  outFile.write('}\n\n\n')
  writeInternalEnd(outFile)
def writeIsSetFunction(attrib, output, element):
  att = generalFunctions.parseAttribute(attrib)
  attName = att[0]
  capAttName = att[1]
  attType = att[2]
  attTypeCode = att[3]
  num = att[4]
  if attrib['type'] == 'lo_element':
    return
  elif attrib['type'] == 'std::vector<double>':
    output.write('  /**\n')
    output.write('   * Predicate returning @c true or @c false depending on ')
    output.write('whether this\n   * {0}\'s \"{1}\" '.format(element, attName))
    output.write('element has elements set.\n   *\n')
    output.write('   * @return @c true if this {0}\'s \"{1}\"'.format(element, attName))
    output.write(' element has been set,\n')
    output.write('   * otherwise @c false is returned.\n')
    output.write('   */\n')
    output.write('  virtual bool has{0}() const;\n\n\n'.format(strFunctions.capp(capAttName)))  
    output.write('  /**\n')
    output.write('   * Returning the number of elements in this\n   * {0}\'s \"{1}\" '.format(element, attName))
    output.write('.\n   *\n')
    output.write('   * @return number of elements in this {0}\'s \"{1}\"'.format(element, attName))
    output.write('\n')
    output.write('   */\n')
    output.write('  virtual unsigned int getNum{0}() const;\n\n\n'.format(strFunctions.capp(capAttName)))  
  elif attrib['type'] == 'element':
    output.write('  /**\n')
    output.write('   * Predicate returning @c true or @c false depending on ')
    output.write('whether this\n   * {0}\'s \"{1}\" '.format(element, attName))
    output.write('element has been set.\n   *\n')
    output.write('   * @return @c true if this {0}\'s \"{1}\"'.format(element, attName))
    output.write(' element has been set,\n')
    output.write('   * otherwise @c false is returned.\n')
    output.write('   */\n')
    output.write('  virtual bool isSet{0}() const;\n\n\n'.format(capAttName))
  else:
    output.write('  /**\n')
    output.write('   * Predicate returning @c true or @c false depending on ')
    output.write('whether this\n   * {0}\'s \"{1}\" '.format(element, attName))
    output.write('attribute has been set.\n   *\n')
    output.write('   * @return @c true if this {0}\'s \"{1}\"'.format(element, attName))
    output.write(' attribute has been set,\n')
    output.write('   * otherwise @c false is returned.\n')
    output.write('   */\n')
    output.write('  virtual bool isSet{0}() const;\n\n\n'.format(capAttName))
Esempio n. 14
0
def writeGetNumFunction(code, type, listOf, name):
  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}() const\n'.format(listOf, strFunctions.capp(name)))
  code.write('{\n')
  code.write('\treturn size();\n')
  code.write('}\n\n')
def writeReadOtherXMLCPPCode(outFile, element, hasMath = True, attribs = None, baseClass='SedBase'):
  writeInternalStart(outFile)
  outFile.write('bool\n{0}::readOtherXML (XMLInputStream& stream)\n'.format(element))
  outFile.write('{\n')
  outFile.write('  bool          read = false;\n')
  outFile.write('  const string& name = stream.peek().getName();\n\n')
  if hasMath == True: 
    outFile.write('  if (name == "math")\n  {\n')
    outFile.write('    const XMLToken elem = stream.peek();\n')
    outFile.write('    const std::string prefix = checkMathMLNamespace(elem);\n\n')
    #outFile.write('    if (stream.getSedNamespaces() == NULL)\n    {\n')
    #outFile.write('      stream.setSedNamespaces(new SedNamespaces(getLevel(), getVersion()));\n    }\n\n')
    outFile.write('    delete mMath;\n')
    outFile.write('    mMath = readMathML(stream, prefix);\n')
    #outFile.write('    if (mMath != NULL)\n    {\n      mMath->setParentSEDMLObject(this);\n    }\n')
    outFile.write('    read = true;\n  }\n\n')
  elif containsType(attribs, 'XMLNode*'):
    node = getByType(attribs, 'XMLNode*')
    outFile.write('  if (name == "{0}")\n'.format(node['name']))
    outFile.write('  {\n')	
    outFile.write('    const XMLToken& token = stream.next();\n')	
    outFile.write('    stream.skipText();\n')	
    outFile.write('    m{0} = new XMLNode(stream);\n'.format(strFunctions.cap(node['name'])))	
    outFile.write('    stream.skipPastEnd(token);\n')	
    outFile.write('    read = true;\n  }\n\n')
  elif containsType(attribs, 'DimensionDescription*'):
    node = getByType(attribs, 'DimensionDescription*')
    outFile.write('  if (name == "{0}")\n'.format(node['name']))
    outFile.write('  {\n')	
    outFile.write('    const XMLToken& token = stream.next();\n')	
    outFile.write('    m{0} = new DimensionDescription();\n'.format(strFunctions.cap(node['name'])))	
    outFile.write('    m{0}->read(stream);\n'.format(strFunctions.cap(node['name'])))	
    outFile.write('    stream.skipPastEnd(token);\n')	
    outFile.write('    read = true;\n  }\n\n')
  elif containsType(attribs, 'std::vector<double>'):
    elem = getByType(attribs, 'std::vector<double>')
    outFile.write('  while (stream.peek().getName() == "{0}")\n'.format(elem['name']))
    outFile.write('  {\n')
    outFile.write('    stream.next(); // consume start\n')
    outFile.write('    stringstream text;\n')
    outFile.write('    while(stream.isGood() && stream.peek().isText())\n')
    outFile.write('      text << stream.next().getCharacters();\n')
    outFile.write('    double value; text >> value;\n')
    outFile.write('    if (!text.fail())\n')
    outFile.write('      m{0}.push_back(value);\n'.format(strFunctions.capp(elem['name'])))
    outFile.write('    stream.next(); // consume end\n')
    outFile.write('    read = true;\n')
    outFile.write('  }\n')
  outFile.write('  if ({0}::readOtherXML(stream))\n'.format(baseClass))
  outFile.write('  {\n    read = true;\n  }\n')
  outFile.write('  return read;\n')
  outFile.write('}\n\n\n')
  writeInternalEnd(outFile)
Esempio n. 16
0
def writeCopyAttributes(attrs, output, tabs, name):
  for i in range(0, len(attrs)):
    attName = strFunctions.cap(attrs[i]['name'])
    atttype = attrs[i]['type']
    if atttype == 'element' and attName == 'Math':
      output.write('{0}m{1}  = {2}.m{1} != NULL ? {2}.m{1}->deepCopy() : NULL;\n'.format(tabs, strFunctions.cap(attrs[i]['name']), name))
    elif atttype == 'XMLNode*':
      output.write('{0}m{1}  = {2}.m{1} != NULL ? {2}.m{1}->clone() : NULL;\n'.format(tabs, strFunctions.cap(attrs[i]['name']), name))
    else:
      output.write('{0}m{1}  = {2}.m{1};\n'.format(tabs, strFunctions.capp(attrs[i]['name'], atttype == 'lo_element' or atttype == 'std::vector<double>'), name))
    if atttype == 'double' or atttype == 'int' or atttype == 'uint' or atttype == 'bool':
      output.write('{0}mIsSet{1}  = {2}.mIsSet{1};\n'.format(tabs, strFunctions.cap(attrs[i]['name']), name))
Esempio n. 17
0
def writeRemoveFunctions(output, element, type, subelement=False, topelement="", name=""):
  listOf = generalFunctions.writeListOf(element)
  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('  return 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}*>(SedListOf::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('  return 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('  SedBase* item = NULL;\n')
    output.write('  vector<SedBase*>::iterator result;\n\n')
    output.write('  result = find_if( mItems.begin(), mItems.end(), SedIdEq<{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('  return static_cast <{0}*> (item);\n'.format(type))
    output.write('}\n\n\n')
Esempio n. 18
0
def writeGetNumFunction(code, type, listOf, name):
    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}() const\n'.format(listOf,
                                                 strFunctions.capp(name)))
    code.write('{\n')
    code.write('\treturn size();\n')
    code.write('}\n\n')
def writeSetDocCPPCode(outFile, element,attribs, baseClass='SedBase'):
  writeInternalStart(outFile)
  outFile.write('/*\n')
  outFile.write(' * Sets the parent SedDocument.\n')
  outFile.write(' */\n')
  outFile.write('void\n{0}::setSedDocument (SedDocument* d)\n'.format(element))
  outFile.write('{\n')
  outFile.write('  {0}::setSedDocument(d);\n'.format(baseClass))
  for i in range (0, len(attribs)):
    if attribs[i]['type'] == 'lo_element' or ( attribs[i]['type'] == 'element' and attribs[i]['name'] != 'math'):
      if attribs[i]['reqd'] == True or attribs[i]['type'] == 'lo_element':
        outFile.write('  m{0}.setSedDocument(d);\n'.format(strFunctions.capp(attribs[i]['name'], attribs[i]['type'] == 'lo_element')))
      else:
        outFile.write('  if (m{0} != NULL)\n'.format(strFunctions.cap(attribs[i]['name'])))
        outFile.write('    m{0}->setSedDocument(d);\n'.format(strFunctions.cap(attribs[i]['name'])))
  outFile.write('}\n\n\n')
  writeInternalEnd(outFile)
Esempio n. 20
0
def writeSetDocCPPCode(outFile, element,attribs, baseClass='SedBase'):
  writeInternalStart(outFile)
  outFile.write('/*\n')
  outFile.write(' * Sets the parent SedDocument.\n')
  outFile.write(' */\n')
  outFile.write('void\n{0}::setSedDocument (SedDocument* d)\n'.format(element))
  outFile.write('{\n')
  outFile.write('\t{0}::setSedDocument(d);\n'.format(baseClass))
  for i in range (0, len(attribs)):
    if attribs[i]['type'] == 'lo_element' or ( attribs[i]['type'] == 'element' and attribs[i]['name'] != 'math'):
      if attribs[i]['reqd'] == True or attribs[i]['type'] == 'lo_element':
        outFile.write('\tm{0}.setSedDocument(d);\n'.format(strFunctions.capp(attribs[i]['name'], attribs[i]['type'] == 'lo_element')))
      else:
        outFile.write('\tif (m{0} != NULL)\n'.format(strFunctions.cap(attribs[i]['name'])))
        outFile.write('\t\tm{0}->setSedDocument(d);\n'.format(strFunctions.cap(attribs[i]['name'])))
  outFile.write('}\n\n\n')
  writeInternalEnd(outFile)
def writeConnectToParent(outFile, element, sbmltypecode, attribs, isSedListOf, hasChildren=False, hasMath=False, baseClass='SedBase'):  
  #print 'isSedListOf={0} hasChildren={1} hasMath={2}'.format(isSedListOf, hasChildren, hasMath)
  if isSedListOf or hasChildren == False:
    return;
  outFile.write('/*\n')
  outFile.write(' * Read values from the given XMLAttributes set into their specific fields.\n')
  outFile.write(' */\n')
  outFile.write('void\n{0}::connectToChild ()\n'.format(element))
  outFile.write('{\n')
  outFile.write('  {0}::connectToChild();\n\n'.format(baseClass))
  for i in range (0, len(attribs)):
    if attribs[i]['type'] == 'lo_element' or ( attribs[i]['type'] == 'element' and attribs[i]['name'] != 'math'):
      if attribs[i]['reqd'] == True or attribs[i]['type'] == 'lo_element':
        outFile.write('  m{0}.connectToParent(this);\n'.format(strFunctions.capp(attribs[i]['name'],attribs[i]['type'] == 'lo_element')))
      else:
        outFile.write('  if (m{0} != NULL)\n'.format(strFunctions.cap(attribs[i]['name'])))
        outFile.write('    m{0}->connectToParent(this);\n'.format(strFunctions.cap(attribs[i]['name'])))
  outFile.write('}\n\n\n')  
Esempio n. 22
0
def writeConnectToParent(outFile, element, sbmltypecode, attribs, isSedListOf, hasChildren=False, hasMath=False, baseClass='SedBase'):  
  #print 'isSedListOf={0} hasChildren={1} hasMath={2}'.format(isSedListOf, hasChildren, hasMath)
  if isSedListOf or hasChildren == False:
    return;
  outFile.write('/*\n')
  outFile.write(' * Read values from the given XMLAttributes set into their specific fields.\n')
  outFile.write(' */\n')
  outFile.write('void\n{0}::connectToChild ()\n'.format(element))
  outFile.write('{\n')
  outFile.write('\t{0}::connectToChild();\n\n'.format(baseClass))
  for i in range (0, len(attribs)):
    if attribs[i]['type'] == 'lo_element' or ( attribs[i]['type'] == 'element' and attribs[i]['name'] != 'math'):
      if attribs[i]['reqd'] == True or attribs[i]['type'] == 'lo_element':
        outFile.write('\tm{0}.connectToParent(this);\n'.format(strFunctions.capp(attribs[i]['name'],attribs[i]['type'] == 'lo_element')))
      else:
        outFile.write('\tif (m{0} != NULL)\n'.format(strFunctions.cap(attribs[i]['name'])))
        outFile.write('\t\tm{0}->connectToParent(this);\n'.format(strFunctions.cap(attribs[i]['name'])))
  outFile.write('}\n\n\n')  
def writeUnsetFunction(attrib, output, element):
  attName = attrib['name']
  capAttName = strFunctions.cap(attName)
  if attrib['type'] == 'lo_element':
    return
  elif attrib['type'] == 'std::vector<double>':
    output.write('  /**\n')
    output.write('   * Clears the \"{0}\"'.format(attName))
    output.write(' element of this {0}.\n'.format(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 LIBSEDML_OPERATION_SUCCESS\n')
    output.write('   * @li LIBSEDML_OPERATION_FAILED\n')
    output.write('   */\n')
    output.write('  virtual int clear{0}();\n\n\n'.format(strFunctions.capp(capAttName)))
  elif attrib['type'] == 'element':
    output.write('  /**\n')
    output.write('   * Unsets the \"{0}\"'.format(attName))
    output.write(' element of this {0}.\n'.format(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 LIBSEDML_OPERATION_SUCCESS\n')
    output.write('   * @li LIBSEDML_OPERATION_FAILED\n')
    output.write('   */\n')
    output.write('  virtual int unset{0}();\n\n\n'.format(capAttName))
  else:
    output.write('  /**\n')
    output.write('   * Unsets the value of the \"{0}\"'.format(attName))
    output.write(' attribute of this {0}.\n'.format(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 LIBSEDML_OPERATION_SUCCESS\n')
    output.write('   * @li LIBSEDML_OPERATION_FAILED\n')
    output.write('   */\n')
    output.write('  virtual int unset{0}();\n\n\n'.format(capAttName))
def writeCopyAttributes(attrs, output, tabs, name):
    for i in range(0, len(attrs)):
        attName = strFunctions.cap(attrs[i]['name'])
        atttype = attrs[i]['type']
        if atttype == 'element' and attName == 'Math':
            output.write(
                '{0}m{1}  = {2}.m{1} != NULL ? {2}.m{1}->deepCopy() : NULL;\n'.
                format(tabs, strFunctions.cap(attrs[i]['name']), name))
        elif atttype == 'XMLNode*' or atttype == 'DimensionDescription*':
            output.write(
                '{0}m{1}  = {2}.m{1} != NULL ? {2}.m{1}->clone() : NULL;\n'.
                format(tabs, strFunctions.cap(attrs[i]['name']), name))
        else:
            output.write('{0}m{1}  = {2}.m{1};\n'.format(
                tabs,
                strFunctions.capp(
                    attrs[i]['name'], atttype == 'lo_element'
                    or atttype == 'std::vector<double>'), name))
        if atttype == 'double' or atttype == 'int' or atttype == 'uint' or atttype == 'bool':
            output.write('{0}mIsSet{1}  = {2}.mIsSet{1};\n'.format(
                tabs, strFunctions.cap(attrs[i]['name']), name))
def writeGetElementNameCPPCode(outFile, element, isSedListOf=False, dict=None):
  outFile.write('/*\n')
  outFile.write(' * Returns the XML element name of this object\n')
  outFile.write(' */\n')
  outFile.write('const std::string&\n{0}::getElementName () const\n'.format(element))
  outFile.write('{\n')
  if dict != None and dict.has_key('elementName'):
    if isSedListOf:
      if dict.has_key('lo_elementName'):        
        outFile.write('  static const string name = "{0}";\n'.format(dict['lo_elementName']))
      else:
        outFile.write('  static const string name = "listOf{0}";\n'.format(strFunctions.capp(dict['elementName'])))
    else:
      outFile.write('  static const string name = "{0}";\n'.format(dict['elementName']))
  else:
    if dict != None and dict.has_key('lo_elementName'):
      outFile.write('  static const string name = "{0}";\n'.format(dict['lo_elementName']))
    else: 
      outFile.write('  static const string name = "{0}";\n'.format(strFunctions.lowerFirst(element)))
  outFile.write('  return name;\n')
  outFile.write('}\n\n\n')
Esempio n. 26
0
def writeGetElementNameCPPCode(outFile, element, isSedListOf=False, dict=None):
  outFile.write('/*\n')
  outFile.write(' * Returns the XML element name of this object\n')
  outFile.write(' */\n')
  outFile.write('const std::string&\n{0}::getElementName () const\n'.format(element))
  outFile.write('{\n')
  if dict != None and dict.has_key('elementName'):
    if isSedListOf:
      if dict.has_key('lo_elementName'):        
        outFile.write('\tstatic const string name = "{0}";\n'.format(dict['lo_elementName']))
      else:
        outFile.write('\tstatic const string name = "listOf{0}";\n'.format(strFunctions.capp(dict['elementName'])))
    else:
      outFile.write('\tstatic const string name = "{0}";\n'.format(dict['elementName']))
  else:
    if dict != None and dict.has_key('lo_elementName'):
      outFile.write('\tstatic const string name = "{0}";\n'.format(dict['lo_elementName']))
    else: 
      outFile.write('\tstatic const string name = "{0}";\n'.format(strFunctions.lowerFirst(element)))
  outFile.write('\treturn name;\n')
  outFile.write('}\n\n\n')
def writeUnsetCode(attrib, output, element):
    att = generalFunctions.parseAttribute(attrib)
    attName = att[0]
    capAttName = att[1]
    attType = att[2]
    attTypeCode = att[3]
    num = att[4]
    if attType == 'lo_element':
        return
    elif attrib['type'] == 'std::vector<double>':
        output.write('/**\n')
        output.write(' * Clears the \"{0}\"'.format(attName))
        output.write(' element of this {0}.\n'.format(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 LIBSEDML_OPERATION_SUCCESS\n')
        output.write(' * @li LIBSEDML_OPERATION_FAILED\n')
        output.write(' */\n')
        output.write('int\n{0}::clear{1}()\n'.format(
            element, strFunctions.capp(capAttName)))
        output.write('{\n')
        output.write('  m{0}.clear();\n'.format(strFunctions.capp(capAttName)))
        output.write('  return LIBSEDML_OPERATION_SUCCESS;\n')
        output.write('}\n\n\n')
    else:
        output.write('/*\n')
        output.write(
            ' * Unsets {0} and returns value indicating success.\n'.format(
                attName))
        output.write(' */\n')
        output.write('int\n')
        output.write('{0}::unset{1}()\n'.format(element, capAttName))
        output.write('{\n')
        if attType == 'string':
            output.write('  m{0}.erase();\n\n'.format(capAttName))
            output.write('  if (m{0}.empty() == true)\n'.format(capAttName))
            output.write('  {\n    return LIBSEDML_OPERATION_SUCCESS;\n  }\n')
            output.write('  else\n  {\n')
            output.write('    return LIBSEDML_OPERATION_FAILED;\n  }\n')
        elif num == True:
            if attType == 'double':
                output.write(
                    '  m{0} = numeric_limits<double>::quiet_NaN();\n'.format(
                        capAttName))
            else:
                output.write('  m{0} = SEDML_INT_MAX;\n'.format(capAttName))
            output.write('  mIsSet{0} = false;\n\n'.format(capAttName))
            output.write('  if (isSet{0}() == false)\n'.format(capAttName))
            output.write('  {\n    return LIBSEDML_OPERATION_SUCCESS;\n  }\n')
            output.write('  else\n  {\n')
            output.write('    return LIBSEDML_OPERATION_FAILED;\n  }\n')
        elif attType == 'boolean':
            output.write('  m{0} = false;\n'.format(capAttName))
            output.write('  mIsSet{0} = false;\n'.format(capAttName))
            output.write('  return LIBSEDML_OPERATION_SUCCESS;\n')
        elif attType == 'element' or attType == 'XMLNode*' or attType == 'DimensionDescription*':
            output.write('  delete m{0};\n'.format(capAttName))
            output.write('  m{0} = NULL;\n'.format(capAttName))
            output.write('  return LIBSEDML_OPERATION_SUCCESS;\n')
        output.write('}\n\n\n')
def writeListOfSubFunctions(attrib, output, 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(loname))
    output.write(' in this {0} object.\n'.format(element))
    output.write(' */\n')
    output.write('const {0}*\n'.format(loname))
    output.write('{0}::getListOf{1}s() const\n'.format(
        element, strFunctions.cap(attrib['name'])))
    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)
    writeListOfCode.writeGetFunctions(output, strFunctions.cap(attrib['name']),
                                      attrib['element'], True, element,
                                      capAttName)
    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 LIBSEDML_OPERATION_SUCCESS\n')
    output.write(' * @li LIBSEDML_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) return LIBSEDML_INVALID_ATTRIBUTE_VALUE;\n'.format(
            strFunctions.objAbbrev(attrib['element'])))
    output.write('  m{0}.append({1});\n'.format(
        strFunctions.capp(attrib['name']),
        strFunctions.objAbbrev(attrib['element'])))
    output.write('  return LIBSEDML_OPERATION_SUCCESS;\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}s() const\n'.format(
        element, strFunctions.cap(attrib['name'])))
    output.write('{\n')
    output.write('  return m{0}.size();\n'.format(
        strFunctions.capp(attrib['name'])))
    output.write('}\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} *temp = new {0}();\n'.format(attrib['element']))
        output.write('  if (temp != NULL) m{0}.appendAndOwn(temp);\n'.format(
            strFunctions.capp(attrib['name'])))
        output.write('  return temp;\n')
        output.write('}\n\n')
    elif attrib.has_key('concrete'):
        for elem in 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(
                element, 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 {1}* {2})\n'.format(
                strFunctions.cap(elem['name']), attrib['element'],
                strFunctions.objAbbrev(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} *temp = new {0}();\n'.format(elem['element']))
            output.write(
                '  if (temp != NULL) m{0}.appendAndOwn(temp);\n'.format(
                    strFunctions.capp(attrib['name'])))
            output.write('  return temp;\n')
            output.write('}\n\n')
Esempio n. 29
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. 30
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. 31
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))
def writeGetCode(attrib, output, element):
    att = generalFunctions.parseAttribute(attrib)
    attName = att[0]
    capAttName = att[1]
    attType = att[2]
    attTypeCode = att[3]
    if attType == 'lo_element':
        return
    if attType == 'std::vector<double>':
        output.write('/*\n')
        output.write(' * Returns the value of the \"{0}\"'.format(attName))
        output.write(' attribute of this {0}.\n'.format(element))
        output.write(' */\n')
        output.write('const {0}&\n'.format(attTypeCode))
        output.write('{0}::get{1}() const\n'.format(
            element, strFunctions.capp(capAttName)))
        output.write('{\n')
        output.write('  return m{0};\n'.format(strFunctions.capp(capAttName)))
        output.write('}\n\n\n')
        output.write('/*\n')
        output.write(' * Returns the value of the \"{0}\"'.format(attName))
        output.write(' attribute of this {0}.\n'.format(element))
        output.write(' */\n')
        output.write('{0}&\n'.format(attTypeCode))
        output.write('{0}::get{1}()\n'.format(element,
                                              strFunctions.capp(capAttName)))
        output.write('{\n')
        output.write('  return m{0};\n'.format(strFunctions.capp(capAttName)))
        output.write('}\n\n\n')
    else:
        output.write('/*\n')
        output.write(' * Returns the value of the \"{0}\"'.format(attName))
        output.write(' attribute of this {0}.\n'.format(element))
        output.write(' */\n')
        output.write('const {0}\n'.format(attTypeCode))
        output.write('{0}::get{1}() const\n'.format(element, capAttName))
        output.write('{\n')
        output.write('  return m{0};\n'.format(capAttName))
        output.write('}\n\n\n')
        if attrib['type'] == 'element' and attName != 'math':
            output.write('/*\n')
            output.write(' * Returns the value of the \"{0}\"'.format(attName))
            output.write(' attribute of this {0}.\n'.format(element))
            output.write(' */\n')
            output.write('{0}\n'.format(attTypeCode))
            output.write('{0}::get{1}()\n'.format(element, capAttName))
            output.write('{\n')
            output.write('  return m{0};\n'.format(capAttName))
            output.write('}\n\n\n')
    if attType == 'element' and attName != 'math':
        output.write('/*\n')
        output.write(' * Creates a new \"{0}\"'.format(attName))
        output.write(' element of this {0} and returns it.\n'.format(element))
        output.write(' */\n')
        output.write('{0}\n'.format(attTypeCode))
        output.write('{0}::create{1}()\n'.format(element, capAttName))
        output.write('{\n')
        output.write('  m{0} = new {1}();\n'.format(capAttName,
                                                    attrib['element']))
        output.write('  return m{0};\n'.format(capAttName))
        output.write('}\n\n\n')
    if attType == 'DimensionDescription*':
        output.write('/*\n')
        output.write(' * Creates a new \"{0}\"'.format(attName))
        output.write(' element of this {0} and returns it.\n'.format(element))
        output.write(' */\n')
        output.write('{0}\n'.format(attTypeCode))
        output.write('{0}::create{1}()\n'.format(element, capAttName))
        output.write('{\n')
        output.write(
            '  if (m{0} != NULL)\n    delete m{0};\n\n'.format(capAttName))
        output.write('  m{0} = new {1}();\n'.format(capAttName,
                                                    'DimensionDescription'))
        output.write('  return m{0};\n'.format(capAttName))
        output.write('}\n\n\n')
Esempio n. 33
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. 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')
def writeSetFunction(attrib, output, element):
  att = generalFunctions.parseAttribute(attrib)
  attName = att[0]
  capAttName = att[1]
  attType = att[2]
  if attType == 'string':
    attTypeCode = 'const std::string&' 
  else:
    attTypeCode = att[3]
  num = att[4]
  if attrib['type'] == 'lo_element':
    return
  elif attrib['type'] == 'element':    
    output.write('  /**\n')
    output.write('   * Sets the \"{0}\"'.format(attName))
    output.write(' element of this {0}.\n'.format(element))
    output.write('   *\n')
    output.write('   * @param {0}; {1} determining the value of the "resultLevel" attribute to be set.\n'.format(attName, attTypeCode))
    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 LIBSEDML_OPERATION_SUCCESS\n')
    output.write('   * @li LIBSEDML_INVALID_ATTRIBUTE_VALUE\n')
    output.write('   */\n')
    output.write('  virtual int set{0}('.format(capAttName))
    output.write('{0} {1});\n\n\n'.format(attTypeCode, attName))    
  elif attrib['type'] == 'std::vector<double>':
    output.write('  /**\n')
    output.write('   * Sets the value of the \"{0}\"'.format(attName))
    output.write(' attribute of this {0}.\n'.format(element))
    output.write('   *\n')
    output.write('   * @param {0}; {1} value of the "{0}" attribute to be set\n'.format(attName, attTypeCode))
    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 LIBSEDML_OPERATION_SUCCESS\n')
    output.write('   * @li LIBSEDML_INVALID_ATTRIBUTE_VALUE\n')
    output.write('   */\n')
    output.write('  virtual int set{0}('.format(strFunctions.capp(capAttName)))
    output.write('const {0}& {1});\n\n\n'.format(attTypeCode, attName))
    output.write('  /**\n')
    output.write('   * Adds another value to the \"{0}\"'.format(attName))
    output.write(' attribute of this {0}.\n'.format(element))
    output.write('   *\n')
    output.write('   * @param {0}; {1} value of the "{0}" attribute to be added\n'.format(attName, 'double'))
    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 LIBSEDML_OPERATION_SUCCESS\n')
    output.write('   * @li LIBSEDML_INVALID_ATTRIBUTE_VALUE\n')
    output.write('   */\n')
    output.write('  virtual int add{0}('.format(capAttName))
    output.write('{0} {1});\n\n\n'.format('double', attName))
  else:
    output.write('  /**\n')
    output.write('   * Sets the value of the \"{0}\"'.format(attName))
    output.write(' attribute of this {0}.\n'.format(element))
    output.write('   *\n')
    output.write('   * @param {0}; {1} value of the "{0}" attribute to be set\n'.format(attName, attTypeCode))
    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 LIBSEDML_OPERATION_SUCCESS\n')
    output.write('   * @li LIBSEDML_INVALID_ATTRIBUTE_VALUE\n')
    output.write('   */\n')
    output.write('  virtual int set{0}('.format(capAttName))
    output.write('{0} {1});\n\n\n'.format(attTypeCode, attName))
Esempio n. 36
0
def writeRequiredMethods(fileOut, nameOfClass, members, pkg, attribs, plugin = None):
  fileOut.write('//---------------------------------------------------------------\n')
  fileOut.write('//\n')
  fileOut.write('// overridden virtual functions for read/write/check\n')
  fileOut.write('//\n')
  fileOut.write('//---------------------------------------------------------------\n\n')
  fileOut.write('/*\n')
  fileOut.write(' * create object\n')
  fileOut.write(' */\n')
  fileOut.write('SBase*\n')
  fileOut.write('{0}::createObject (XMLInputStream& stream)\n'.format(nameOfClass))
  fileOut.write('{\n')

  numMembers = len(members)
  numAttribs = generalFunctions.countMembers(attribs)

  if numMembers + numAttribs > 0: 
    fileOut.write('  SBase* object = NULL; \n\n')
    fileOut.write('  const std::string&      name   = stream.peek().getName(); \n')
    fileOut.write('  const XMLNamespaces&    xmlns  = stream.peek().getNamespaces(); \n')
    fileOut.write('  const std::string&      prefix = stream.peek().getPrefix(); \n\n')
    fileOut.write('  const std::string& targetPrefix = (xmlns.hasURI(mURI)) ? xmlns.getPrefix(mURI) : mPrefix;\n\n')
    fileOut.write('  if (prefix == targetPrefix) \n')
    fileOut.write('  { \n')
    fileOut.write('    {0}_CREATE_NS({1}ns, getSBMLNamespaces());\n'.format(pkg.upper(), pkg.lower()))
    ifCount = 1
    for i in range (0, len(members)):
      mem = members[i]
      if mem['isListOf'] == True:
        writeCreateLOObject(fileOut, mem, ifCount)
      else:
        writeCreateObject(fileOut, mem, ifCount, pkg)
      ifCount = ifCount + 1  
    for i in range (0, len(attribs)):
      mem = attribs[i]
      if mem['type'] == 'lo_element' or mem['type'] == 'inline_lo_element':
        writeCreateLOObject(fileOut, mem, ifCount)
        ifCount = ifCount + 1
      elif mem['type'] == 'element':
        writeCreateObject(fileOut, mem, ifCount, pkg)
        ifCount = ifCount + 1
    fileOut.write('\n    delete {0}ns;\n'.format(pkg.lower()))
    fileOut.write('  } \n\n')
    fileOut.write('  return object; \n')
  else: 
    fileOut.write('  return NULL; \n')
  fileOut.write('}\n\n\n')
  fileOut.write('/*\n')
  fileOut.write(' * write elements\n')
  fileOut.write(' */\n')
  fileOut.write('void\n')
  fileOut.write('{0}::writeElements (XMLOutputStream& stream) const\n'.format(nameOfClass))
  fileOut.write('{\n')
  for i in range (0, len(members)):
    mem = members[i]
    if mem['isListOf'] == True:
      fileOut.write('  if (getNum{0}() > 0) \n'.format(strFunctions.capp(mem['name'])))
      fileOut.write('  { \n')
      fileOut.write('    m{0}s.write(stream);\n'.format(mem['name']))
      fileOut.write('  } \n')
    else:
      fileOut.write('  if (isSet{0}() == true) \n'.format(mem['name']))
      fileOut.write('  { \n')
      fileOut.write('    m{0}->write(stream);\n'.format(mem['name']))
      fileOut.write('  } \n')

  for i in range (0, len(attribs)):
    mem = attribs[i]
    if mem['type'] == 'lo_element' or mem['type'] == 'inline_lo_element':
      fileOut.write('  if (getNum{0}() > 0) \n'.format(strFunctions.capp(mem['name'])))
      fileOut.write('  { \n')
      fileOut.write('    m{0}s.write(stream);\n'.format(strFunctions.cap(mem['name'])))
      fileOut.write('  } \n')
    elif mem['type'] == 'element':
      fileOut.write('  if (isSet{0}() == true) \n'.format(strFunctions.cap(mem['name'])))
      fileOut.write('  { \n')
      fileOut.write('    m{0}->write(stream);\n'.format(strFunctions.cap(mem['name'])))
      fileOut.write('  } \n')

  fileOut.write('}\n\n\n')
  fileOut.write('/*\n')
  fileOut.write(' * Checks if this plugin object has all the required elements.\n')
  fileOut.write(' */\n')
  fileOut.write('bool\n')
  fileOut.write('{0}::hasRequiredElements () const\n'.format(nameOfClass))
  fileOut.write('{\n')
  fileOut.write('  bool allPresent = true; \n\n')
  fileOut.write('  // TO DO \n\n')
  fileOut.write('  return allPresent; \n')
  fileOut.write('}\n\n\n')

  generalFunctions.writeAddExpectedCPPCode(fileOut, nameOfClass, attribs, 'SBasePlugin')
  generalFunctions.writeReadAttributesCPPCode(fileOut, nameOfClass, attribs, pkg, False, 'SBasePlugin', plugin)
  generalFunctions.writeWriteAttributesCPPCode(fileOut, nameOfClass, attribs, 'SBasePlugin')
def writeGetFunction(attrib, output, element):
  att = generalFunctions.parseAttribute(attrib)
  attName = att[0]
  capAttName = att[1]
  attType = att[2]
  attTypeCode = att[3]
  num = att[4]
  if attrib['type'] == 'lo_element':
    return
  elif attrib['type'] == 'element':
    if attrib['name'] == 'Math' or attrib['name'] == 'math':
      output.write('  /**\n')
      output.write('   * Returns the \"{0}\"'.format(attName))
      output.write(' element of this {0}.\n'.format(element))
      output.write('   *\n')
      output.write('   * @return the \"{0}\"'.format(attName))
      output.write(' element of this {0}.\n'.format(element))
      output.write('   */\n')
      output.write('  virtual const ASTNode*')
      output.write(' get{0}() const;\n\n\n'.format(capAttName))
    else:
      output.write('  /**\n')
      output.write('   * Returns the \"{0}\"'.format(attName))
      output.write(' element of this {0}.\n'.format(element))
      output.write('   *\n')
      output.write('   * @return the \"{0}\"'.format(attName))
      output.write(' element of this {0}.\n'.format(element))
      output.write('   */\n')
      output.write('  virtual const {0}*'.format(attrib['element']))
      output.write(' get{0}() const;\n\n\n'.format(capAttName))
      output.write('  /**\n')
      output.write('   * Returns the \"{0}\"'.format(attName))
      output.write(' element of this {0}.\n'.format(element))
      output.write('   *\n')
      output.write('   * @return the \"{0}\"'.format(attName))
      output.write(' element of this {0}.\n'.format(element))
      output.write('   */\n')
      output.write('  virtual {0}*'.format(attrib['element']))
      output.write(' get{0}();\n\n\n'.format(capAttName))
      output.write('  /**\n')
      output.write('   * Creates a new \"{0}\"'.format(attrib['element']))
      output.write(' and sets it for this {0}.\n'.format(element))
      output.write('   *\n')
      output.write('   * @return the created \"{0}\"'.format(attrib['element']))
      output.write(' element of this {0}.\n'.format(element))
      output.write('   */\n')
      output.write('  virtual {0}*'.format(attrib['element']))
      output.write(' create{0}();\n\n\n'.format(capAttName))
  elif attrib['type'] == 'std::vector<double>':
    output.write('  /**\n')
    output.write('   * Returns the value of the \"{0}\"'.format(attName))
    output.write(' attribute of this {0}.\n'.format(element))
    output.write('   *\n')
    output.write('   * @return the value of the \"{0}\"'.format(attName))
    output.write(' attribute of this {0} as a {1}.\n'.format(element, attType))
    output.write('   */\n')
    output.write('  virtual const {0}&'.format(attTypeCode))
    output.write(' get{0}() const;\n\n\n'.format(strFunctions.capp(attName)))
    output.write('  /**\n')
    output.write('   * Returns the value of the \"{0}\"'.format(attName))
    output.write(' attribute of this {0}.\n'.format(element))
    output.write('   *\n')
    output.write('   * @return the value of the \"{0}\"'.format(attName))
    output.write(' attribute of this {0} as a {1}.\n'.format(element, attType))
    output.write('   */\n')
    output.write('  virtual {0}&'.format(attTypeCode))
    output.write(' get{0}();\n\n\n'.format(strFunctions.capp(attName)))
  elif attrib['type'] == 'DimensionDescription*':
    output.write('  /**\n')
    output.write('   * Returns the value of the \"{0}\"'.format(attName))
    output.write(' attribute of this {0}.\n'.format(element))
    output.write('   *\n')
    output.write('   * @return the value of the \"{0}\"'.format(attName))
    output.write(' attribute of this {0} as a {1}.\n'.format(element, attType))
    output.write('   */\n')
    output.write('  virtual const {0}'.format(attTypeCode))
    output.write(' get{0}() const;\n\n\n'.format(capAttName))
    output.write('  /**\n')
    output.write('   * Creates a new \"{0}\"'.format(attrib['type']))
    output.write(' and sets it for this {0}.\n'.format(element))
    output.write('   *\n')
    output.write('   * @return the created \"{0}\"'.format(attrib['type']))
    output.write(' element of this {0}.\n'.format(element))
    output.write('   */\n')
    output.write('  virtual {0}'.format(attrib['type']))
    output.write(' create{0}();\n\n\n'.format(capAttName))
  else:
    output.write('  /**\n')
    output.write('   * Returns the value of the \"{0}\"'.format(attName))
    output.write(' attribute of this {0}.\n'.format(element))
    output.write('   *\n')
    output.write('   * @return the value of the \"{0}\"'.format(attName))
    output.write(' attribute of this {0} as a {1}.\n'.format(element, attType))
    output.write('   */\n')
    output.write('  virtual const {0}'.format(attTypeCode))
    output.write(' get{0}() const;\n\n\n'.format(capAttName))
Esempio n. 38
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. 39
0
def writeSetCode(attrib, output, element):
  att = generalFunctions.parseAttribute(attrib)
  attName = att[0]
  capAttName = att[1]
  attType = att[2]
  if attType == 'string':
    attTypeCode = 'const std::string&'
  else:
    attTypeCode = att[3]
  num = att[4]
  if attType == 'lo_element':
    return
  elif attrib['type'] == 'std::vector<double>':
    output.write('/**\n')
    output.write(' * Sets the value of the \"{0}\"'.format(attName))
    output.write(' attribute of this {0}.\n'.format(element))
    output.write(' *\n')
    output.write(' * @param {0}; {1} value of the "{0}" attribute to be set\n'.format(attName, attTypeCode))
    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 LIBSEDML_OPERATION_SUCCESS\n')
    output.write(' * @li LIBSEDML_INVALID_ATTRIBUTE_VALUE\n')
    output.write(' */\n')
    output.write('int\n{0}::set{1}('.format(element, strFunctions.capp(capAttName)))
    output.write('const {0}& {1})\n'.format(attTypeCode, attName))
    output.write('{\n')
    output.write('\tm{0} = {1};\n'.format( strFunctions.capp(capAttName), attName))
    output.write('\treturn LIBSEDML_OPERATION_SUCCESS;\n')
    output.write('}\n\n\n')
    output.write('/**\n')
    output.write(' * Adds another value to the \"{0}\"'.format(attName))
    output.write(' attribute of this {0}.\n'.format(element))
    output.write(' *\n')
    output.write(' * @param {0}; {1} value of the "{0}" attribute to be added \n'.format(attName, 'double'))
    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 LIBSEDML_OPERATION_SUCCESS\n')
    output.write(' * @li LIBSEDML_INVALID_ATTRIBUTE_VALUE\n')
    output.write(' */\n')
    output.write('int\n{0}::add{1}('.format(element, capAttName))
    output.write('{0} {1})\n'.format('double', attName))
    output.write('{\n')
    output.write('\tm{0}.push_back({1});\n'.format( strFunctions.capp(capAttName), attName))
    output.write('\treturn LIBSEDML_OPERATION_SUCCESS;\n')
    output.write('}\n\n\n')
  else:
    output.write('/*\n')
    output.write(' * Sets {0} and returns value indicating success.\n'.format(attName))
    output.write(' */\n')
    output.write('int\n')
    output.write('{0}::set{1}({2} {3})\n'.format(element, capAttName, attTypeCode, attName))
    output.write('{\n')
    if attType == 'string':
      if attName == 'id':
        output.write('\treturn SyntaxChecker::checkAndSetSId({0}, m{1});\n'.format(attName, capAttName ))
      else:
        output.write('\tif (&({0}) == NULL)\n'.format(attName))
        output.write('\t{\n\t\treturn LIBSEDML_INVALID_ATTRIBUTE_VALUE;\n\t}\n')
        if attrib['type'] == 'SIdRef':
          output.write('\telse if (!(SyntaxChecker::isValidInternalSId({0})))\n'.format(attName))
          output.write('\t{\n\t\treturn LIBSEDML_INVALID_ATTRIBUTE_VALUE;\n\t}\n')
        output.write('\telse\n\t{\n')
        output.write('\t\tm{0} = {1};\n'.format(capAttName, attName))
        output.write('\t\treturn LIBSEDML_OPERATION_SUCCESS;\n\t}\n')
    elif num == True:
      output.write('\tm{0} = {1};\n'.format(capAttName, attName))
      output.write('\tmIsSet{0} = true;\n'.format(capAttName))
      output.write('\treturn LIBSEDML_OPERATION_SUCCESS;\n')
    elif attType == 'boolean':
      output.write('\tm{0} = {1};\n'.format(capAttName, attName))
      output.write('\tmIsSet{0} = true;\n'.format(capAttName))
      output.write('\treturn LIBSEDML_OPERATION_SUCCESS;\n')
    elif attType == 'XMLNode*':
      output.write('\tif (m{0} == {1})\n'.format(capAttName, attName))
      output.write('\t{\n\t\treturn LIBSEDML_OPERATION_SUCCESS;\n\t}\n')
      output.write('\telse if ({0} == NULL)\n'.format(attName))
      output.write('\t{\n')
      output.write('\t\tdelete m{0};\n'.format(capAttName))
      output.write('\t\tm{0} = NULL;\n'.format(capAttName))
      output.write('\t\treturn LIBSEDML_OPERATION_SUCCESS;\n\t}\n')
      output.write('\tdelete m{0};\n'.format(capAttName))
      output.write('\tm{0} = ({1} != NULL) ?\n'.format(capAttName, attName))
      output.write('\t\t{0}->clone() : NULL;\n'.format(attName))
      output.write('\treturn LIBSEDML_OPERATION_SUCCESS;\n')
    elif attType == 'element':
      output.write('\tif (m{0} == {1})\n'.format(capAttName, attName))
      output.write('\t{\n\t\treturn LIBSEDML_OPERATION_SUCCESS;\n\t}\n')
      output.write('\telse if ({0} == NULL)\n'.format(attName))
      output.write('\t{\n')
      output.write('\t\tdelete m{0};\n'.format(capAttName))
      output.write('\t\tm{0} = NULL;\n'.format(capAttName))
      output.write('\t\treturn LIBSEDML_OPERATION_SUCCESS;\n\t}\n')
      if attTypeCode == 'ASTNode*':
        output.write('\telse if (!({0}->isWellFormedASTNode()))\n'.format(attName))
        output.write('\t{\n\t\treturn LIBSEDML_INVALID_OBJECT;\n\t}\n')
      output.write('\telse\n\t{\n')
      output.write('\t\tdelete m{0};\n'.format(capAttName))
      output.write('\t\tm{0} = ({1} != NULL) ?\n'.format(capAttName, attName))
      if attTypeCode == 'ASTNode*':
        output.write('\t\t\t{0}->deepCopy() : NULL;\n'.format(attName))
      else:
        output.write('\t\t\tstatic_cast<{0}*>({1}->clone()) : NULL;\n'.format(attrib['element'], attName))
      output.write('\t\tif (m{0} != NULL)\n'.format(capAttName))
      output.write('\t\t{\n')
      #if attTypeCode == 'ASTNode*':
      #  output.write('\t\t\tm{0}->setParentSEDMLObject(this);\n'.format(capAttName, attName))
      #else:
      #  output.write('\t\t\tm{0}->connectToParent(this);\n'.format(capAttName, attName))
      if attTypeCode != 'ASTNode*':
        output.write('\t\t\tm{0}->connectToParent(this);\n'.format(capAttName, attName))
      output.write('\t\t}\n')
      output.write('\t\treturn LIBSEDML_OPERATION_SUCCESS;\n\t}\n')
    output.write('}\n\n\n')
def writeSetCode(attrib, output, element):
    att = generalFunctions.parseAttribute(attrib)
    attName = att[0]
    capAttName = att[1]
    attType = att[2]
    if attType == 'string':
        attTypeCode = 'const std::string&'
    else:
        attTypeCode = att[3]
    num = att[4]
    if attType == 'lo_element':
        return
    elif attrib['type'] == 'std::vector<double>':
        output.write('/**\n')
        output.write(' * Sets the value of the \"{0}\"'.format(attName))
        output.write(' attribute of this {0}.\n'.format(element))
        output.write(' *\n')
        output.write(
            ' * @param {0}; {1} value of the "{0}" attribute to be set\n'.
            format(attName, attTypeCode))
        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 LIBSEDML_OPERATION_SUCCESS\n')
        output.write(' * @li LIBSEDML_INVALID_ATTRIBUTE_VALUE\n')
        output.write(' */\n')
        output.write('int\n{0}::set{1}('.format(element,
                                                strFunctions.capp(capAttName)))
        output.write('const {0}& {1})\n'.format(attTypeCode, attName))
        output.write('{\n')
        output.write('  m{0} = {1};\n'.format(strFunctions.capp(capAttName),
                                              attName))
        output.write('  return LIBSEDML_OPERATION_SUCCESS;\n')
        output.write('}\n\n\n')
        output.write('/**\n')
        output.write(' * Adds another value to the \"{0}\"'.format(attName))
        output.write(' attribute of this {0}.\n'.format(element))
        output.write(' *\n')
        output.write(
            ' * @param {0}; {1} value of the "{0}" attribute to be added\n'.
            format(attName, 'double'))
        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 LIBSEDML_OPERATION_SUCCESS\n')
        output.write(' * @li LIBSEDML_INVALID_ATTRIBUTE_VALUE\n')
        output.write(' */\n')
        output.write('int\n{0}::add{1}('.format(element, capAttName))
        output.write('{0} {1})\n'.format('double', attName))
        output.write('{\n')
        output.write('  m{0}.push_back({1});\n'.format(
            strFunctions.capp(capAttName), attName))
        output.write('  return LIBSEDML_OPERATION_SUCCESS;\n')
        output.write('}\n\n\n')
    else:
        output.write('/*\n')
        output.write(
            ' * Sets {0} and returns value indicating success.\n'.format(
                attName))
        output.write(' */\n')
        output.write('int\n')
        output.write('{0}::set{1}({2} {3})\n'.format(element, capAttName,
                                                     attTypeCode, attName))
        output.write('{\n')
        if attType == 'string':
            if attName == 'id':
                output.write(
                    '  return SyntaxChecker::checkAndSetSId({0}, m{1});\n'.
                    format(attName, capAttName))
            else:
                if attrib['type'] == 'SIdRef':
                    output.write(
                        '  if (!(SyntaxChecker::isValidInternalSId({0})))\n'.
                        format(attName))
                    output.write(
                        '  {\n    return LIBSEDML_INVALID_ATTRIBUTE_VALUE;\n  }\n'
                    )
                    output.write('  else\n')
                output.write('  {\n')
                output.write('    m{0} = {1};\n'.format(capAttName, attName))
                output.write('    return LIBSEDML_OPERATION_SUCCESS;\n  }\n')
        elif num == True:
            output.write('  m{0} = {1};\n'.format(capAttName, attName))
            output.write('  mIsSet{0} = true;\n'.format(capAttName))
            output.write('  return LIBSEDML_OPERATION_SUCCESS;\n')
        elif attType == 'boolean':
            output.write('  m{0} = {1};\n'.format(capAttName, attName))
            output.write('  mIsSet{0} = true;\n'.format(capAttName))
            output.write('  return LIBSEDML_OPERATION_SUCCESS;\n')
        elif attType == 'XMLNode*' or attType == 'DimensionDescription*':
            output.write('  if (m{0} == {1})\n'.format(capAttName, attName))
            output.write('  {\n    return LIBSEDML_OPERATION_SUCCESS;\n  }\n')
            output.write('  else if ({0} == NULL)\n'.format(attName))
            output.write('  {\n')
            output.write('    delete m{0};\n'.format(capAttName))
            output.write('    m{0} = NULL;\n'.format(capAttName))
            output.write('    return LIBSEDML_OPERATION_SUCCESS;\n  }\n')
            output.write('  delete m{0};\n'.format(capAttName))
            output.write('  m{0} = ({1} != NULL) ?\n'.format(
                capAttName, attName))
            output.write('    {0}->clone() : NULL;\n'.format(attName))
            output.write('  return LIBSEDML_OPERATION_SUCCESS;\n')
        elif attType == 'element':
            output.write('  if (m{0} == {1})\n'.format(capAttName, attName))
            output.write('  {\n    return LIBSEDML_OPERATION_SUCCESS;\n  }\n')
            output.write('  else if ({0} == NULL)\n'.format(attName))
            output.write('  {\n')
            output.write('    delete m{0};\n'.format(capAttName))
            output.write('    m{0} = NULL;\n'.format(capAttName))
            output.write('    return LIBSEDML_OPERATION_SUCCESS;\n  }\n')
            if attTypeCode == 'ASTNode*':
                output.write(
                    '  else if (!({0}->isWellFormedASTNode()))\n'.format(
                        attName))
                output.write('  {\n    return LIBSEDML_INVALID_OBJECT;\n  }\n')
            output.write('  else\n  {\n')
            output.write('    delete m{0};\n'.format(capAttName))
            output.write('    m{0} = ({1} != NULL) ?\n'.format(
                capAttName, attName))
            if attTypeCode == 'ASTNode*':
                output.write('      {0}->deepCopy() : NULL;\n'.format(attName))
            else:
                output.write(
                    '      static_cast<{0}*>({1}->clone()) : NULL;\n'.format(
                        attrib['element'], attName))
            output.write('    if (m{0} != NULL)\n'.format(capAttName))
            output.write('    {\n')
            #if attTypeCode == 'ASTNode*':
            #  output.write('      m{0}->setParentSEDMLObject(this);\n'.format(capAttName, attName))
            #else:
            #  output.write('      m{0}->connectToParent(this);\n'.format(capAttName, attName))
            if attTypeCode != 'ASTNode*':
                output.write('      m{0}->connectToParent(this);\n'.format(
                    capAttName, attName))
            output.write('    }\n')
            output.write('    return LIBSEDML_OPERATION_SUCCESS;\n  }\n')
        output.write('}\n\n\n')
Esempio n. 41
0
def writeGetFunctions(output,
                      element,
                      type,
                      subelement=False,
                      topelement="",
                      name=""):
    listOf = generalFunctions.writeListOf(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')
        output.write('{0}*\n'.format(type))
        output.write('{0}::get{1}(unsigned int n)\n'.format(
            topelement, element))
        output.write('{\n')
        output.write('  return 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}*>(SedListOf::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('  return 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}*>(SedListOf::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('  return 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('  return 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('  return 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<SedBase*>::const_iterator result;\n\n')
        output.write(
            '  result = find_if( mItems.begin(), mItems.end(), SedIdEq<{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. 42
0
def writeListOfSubFunctions(attrib, output, 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(loname))
  output.write(' in this {0} object.\n'.format(element))
  output.write(' */\n')
  output.write('const {0}*\n'.format(loname))
  output.write('{0}::getListOf{1}s() const\n'.format(element, strFunctions.cap(attrib['name'])))
  output.write('{\n')
  output.write('\treturn &m{0};\n'.format(strFunctions.capp(attName)))
  output.write('}\n\n\n')
  writeListOfCode.writeRemoveFunctions(output, strFunctions.cap(attrib['name']), attrib['element'], True, element, capAttName)
  writeListOfCode.writeGetFunctions(output, strFunctions.cap(attrib['name']), attrib['element'], True, element, capAttName)
  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 LIBSEDML_OPERATION_SUCCESS\n')
  output.write(' * @li LIBSEDML_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('\tif({0} == NULL) return LIBSEDML_INVALID_ATTRIBUTE_VALUE;\n'.format(strFunctions.objAbbrev(attrib['element'])))
  output.write('\tm{0}.append({1});\n'.format(strFunctions.capp(attrib['name']),strFunctions.objAbbrev(attrib['element'])))
  output.write('\treturn LIBSEDML_OPERATION_SUCCESS;\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}s() const\n'.format(element, strFunctions.cap(attrib['name'])))
  output.write('{\n')
  output.write('\treturn m{0}.size();\n'.format(strFunctions.capp(attrib['name'])))
  output.write('}\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('\t{0} *temp = new {0}();\n'.format(attrib['element']))
    output.write('\tif (temp != NULL) m{0}.appendAndOwn(temp);\n'.format(strFunctions.capp(attrib['name'])))
    output.write('\treturn temp;\n')
    output.write('}\n\n')
  elif attrib.has_key('concrete'):
    for elem in 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(element, 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 {1}* {2})\n'.format(strFunctions.cap(elem['name']), attrib['element'], strFunctions.objAbbrev(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('\t{0} *temp = new {0}();\n'.format(elem['element']))
      output.write('\tif (temp != NULL) m{0}.appendAndOwn(temp);\n'.format(strFunctions.capp(attrib['name'])))
      output.write('\treturn temp;\n')
      output.write('}\n\n')
Esempio n. 43
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. 44
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. 45
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. 46
0
def writeGetFunctions(output, element, type, subelement=False, topelement="", name=""):
  listOf = generalFunctions.writeListOf(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')
    output.write('{0}*\n'.format(type))
    output.write('{0}::get{1}(unsigned int n)\n'.format(topelement, element))
    output.write('{\n' )
    output.write('  return 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}*>(SedListOf::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('  return 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}*>(SedListOf::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('  return 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('  return 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('  return 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<SedBase*>::const_iterator result;\n\n')
    output.write('  result = find_if( mItems.begin(), mItems.end(), SedIdEq<{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. 47
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. 48
0
def writeRequiredMethods(fileOut,
                         nameOfClass,
                         members,
                         pkg,
                         attribs,
                         plugin=None):
    fileOut.write(
        '//---------------------------------------------------------------\n')
    fileOut.write('//\n')
    fileOut.write('// overridden virtual functions for read/write/check\n')
    fileOut.write('//\n')
    fileOut.write(
        '//---------------------------------------------------------------\n\n'
    )
    fileOut.write('/*\n')
    fileOut.write(' * create object\n')
    fileOut.write(' */\n')
    fileOut.write('SBase*\n')
    fileOut.write(
        '{0}::createObject (XMLInputStream& stream)\n'.format(nameOfClass))
    fileOut.write('{\n')

    numMembers = len(members)
    numAttribs = generalFunctions.countMembers(attribs)

    if numMembers + numAttribs > 0:
        fileOut.write('  SBase* object = NULL; \n\n')
        fileOut.write(
            '  const std::string&      name   = stream.peek().getName(); \n')
        fileOut.write(
            '  const XMLNamespaces&    xmlns  = stream.peek().getNamespaces(); \n'
        )
        fileOut.write(
            '  const std::string&      prefix = stream.peek().getPrefix(); \n\n'
        )
        fileOut.write(
            '  const std::string& targetPrefix = (xmlns.hasURI(mURI)) ? xmlns.getPrefix(mURI) : mPrefix;\n\n'
        )
        fileOut.write('  if (prefix == targetPrefix) \n')
        fileOut.write('  { \n')
        fileOut.write(
            '    {0}_CREATE_NS({1}ns, getSBMLNamespaces());\n'.format(
                pkg.upper(), pkg.lower()))
        ifCount = 1
        for i in range(0, len(members)):
            mem = members[i]
            if mem['isListOf'] == True:
                writeCreateLOObject(fileOut, mem, ifCount)
            else:
                writeCreateObject(fileOut, mem, ifCount, pkg)
            ifCount = ifCount + 1
        for i in range(0, len(attribs)):
            mem = attribs[i]
            if mem['type'] == 'lo_element' or mem[
                    'type'] == 'inline_lo_element':
                writeCreateLOObject(fileOut, mem, ifCount)
                ifCount = ifCount + 1
            elif mem['type'] == 'element':
                writeCreateObject(fileOut, mem, ifCount, pkg)
                ifCount = ifCount + 1
        fileOut.write('\n    delete {0}ns;\n'.format(pkg.lower()))
        fileOut.write('  } \n\n')
        fileOut.write('  return object; \n')
    else:
        fileOut.write('  return NULL; \n')
    fileOut.write('}\n\n\n')
    fileOut.write('/*\n')
    fileOut.write(' * write elements\n')
    fileOut.write(' */\n')
    fileOut.write('void\n')
    fileOut.write(
        '{0}::writeElements (XMLOutputStream& stream) const\n'.format(
            nameOfClass))
    fileOut.write('{\n')
    for i in range(0, len(members)):
        mem = members[i]
        if mem['isListOf'] == True:
            fileOut.write('  if (getNum{0}() > 0) \n'.format(
                strFunctions.capp(mem['name'])))
            fileOut.write('  { \n')
            fileOut.write('    m{0}s.write(stream);\n'.format(mem['name']))
            fileOut.write('  } \n')
        else:
            fileOut.write('  if (isSet{0}() == true) \n'.format(mem['name']))
            fileOut.write('  { \n')
            fileOut.write('    m{0}->write(stream);\n'.format(mem['name']))
            fileOut.write('  } \n')

    for i in range(0, len(attribs)):
        mem = attribs[i]
        if mem['type'] == 'lo_element' or mem['type'] == 'inline_lo_element':
            fileOut.write('  if (getNum{0}() > 0) \n'.format(
                strFunctions.capp(mem['name'])))
            fileOut.write('  { \n')
            fileOut.write('    m{0}s.write(stream);\n'.format(
                strFunctions.cap(mem['name'])))
            fileOut.write('  } \n')
        elif mem['type'] == 'element':
            fileOut.write('  if (isSet{0}() == true) \n'.format(
                strFunctions.cap(mem['name'])))
            fileOut.write('  { \n')
            fileOut.write('    m{0}->write(stream);\n'.format(
                strFunctions.cap(mem['name'])))
            fileOut.write('  } \n')

    fileOut.write('}\n\n\n')
    fileOut.write('/*\n')
    fileOut.write(
        ' * Checks if this plugin object has all the required elements.\n')
    fileOut.write(' */\n')
    fileOut.write('bool\n')
    fileOut.write('{0}::hasRequiredElements () const\n'.format(nameOfClass))
    fileOut.write('{\n')
    fileOut.write('  bool allPresent = true; \n\n')
    fileOut.write('  // TO DO \n\n')
    fileOut.write('  return allPresent; \n')
    fileOut.write('}\n\n\n')

    generalFunctions.writeAddExpectedCPPCode(fileOut, nameOfClass, attribs,
                                             'SBasePlugin')
    generalFunctions.writeReadAttributesCPPCode(fileOut, nameOfClass, attribs,
                                                pkg, False, 'SBasePlugin',
                                                plugin)
    generalFunctions.writeWriteAttributesCPPCode(fileOut, nameOfClass, attribs,
                                                 'SBasePlugin')
Esempio n. 49
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')