Ejemplo n.º 1
0
def writeSetFunction(attrib, output, element):
  att = generalFunctions.parseAttributeForC(attrib)
  attName = att[0]
  cleanName = strFunctions.cleanStr(attName)
  capAttName = att[1]
  attType = att[2]
  attTypeCode = att[3]
  num = att[4]
  if attrib['type'] == 'lo_element' or attrib['type'] == 'inline_lo_element':
    return
  if attrib['type'] == 'array':
    return
  varname = strFunctions.objAbbrev(element)
  if attrib['type'] != 'element' and attrib['type'] != 'lo_element' and attrib['type'] != 'inline_lo_element':
      output.write('LIBSBML_EXTERN\n')
      output.write('int\n')
      output.write('{0}_set{1}'.format(element, capAttName))
      output.write('({0}_t * {1},'.format(element, varname))
      output.write(' {0} {1})\n'.format(attTypeCode, cleanName))
      output.write('{\n')
      output.write('  if ({0} != NULL)\n'.format(varname))
      if num or attrib['type'] == 'enum':
        output.write('    return {1}->set{2}({0});\n'.format(cleanName, varname, capAttName))
      elif attrib['type'] == 'array':
        output.write('    return ({0} == NULL) ? {1}->unset{2}() : {1}->set{2}({0});\n'.format(cleanName, varname, capAttName))
      else:
        output.write('    return ({0} == NULL) ? {1}->set{2}("") : {1}->set{2}({0});\n'.format(cleanName, varname, capAttName))
      output.write('  else\n')
      output.write('    return LIBSBML_INVALID_OBJECT;\n')
#      output.write('  return ({0} != NULL) ? {0}->set{1}({2}) : LIBSBML_INVALID_OBJECT;\n'.format(varname, capAttName, attName))
      output.write('}\n\n\n')
  elif attrib['type'] == 'element':
    if attrib['name'] == 'Math' or attrib['name'] == 'math':
      output.write('LIBSBML_EXTERN\n')
      output.write('int\n')
      output.write('{0}_set{1}'.format(element, capAttName))
      output.write('({0}_t * {1},'.format(element, varname))
      output.write(' const {0} {1})\n'.format('ASTNode_t*', cleanName))
      output.write('{\n')
      output.write('\treturn ({0} != NULL) ? {0}->set{1}({2}) : LIBSBML_INVALID_OBJECT;\n'.format(varname, capAttName, cleanName))
      output.write('}\n\n\n')
    else:
      output.write('LIBSBML_EXTERN\n')
      output.write('int\n')
      output.write('{0}_set{1}'.format(element, capAttName))
      output.write('({0}_t * {1},'.format(element, varname))
      output.write(' {0}_t* {1})\n'.format(attrib['element'], cleanName))
      output.write('{\n')
      output.write('\treturn ({0} != NULL) ? {0}->set{1}({2}) : LIBSBML_INVALID_OBJECT;\n'.format(varname, capAttName, cleanName))
      output.write('}\n\n\n')
Ejemplo n.º 2
0
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' or attrib['type'] == 'inline_lo_element':
    return
  elif attrib['type'] == 'array':
    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 inArray; {1} array to be set (it will be copied).\n'.format(attName, attTypeCode))
    output.write('   * @param arrayLength; the length of the array.\n')
    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('  virtual int set{0}('.format(capAttName))
    output.write('{0} inArray, int arrayLength);\n\n\n'.format(attTypeCode))
  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} to be set.\n'.format(strFunctions.cleanStr(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 LIBSBML_OPERATION_SUCCESS\n')
    output.write('   * @li LIBSBML_INVALID_ATTRIBUTE_VALUE\n')
    output.write('   */\n')
    output.write('  virtual int set{0}('.format(capAttName))
    output.write('{0} {1});\n\n\n'.format(attTypeCode, strFunctions.cleanStr(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 "{2}" attribute to be set\n'.format(strFunctions.cleanStr(attName), attTypeCode, attName))
    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('  virtual int set{0}('.format(capAttName))
    output.write('{0} {1});\n\n\n'.format(attTypeCode, strFunctions.cleanStr(attName)))

    if attrib['type'] == 'enum':
      output.write('  /**\n')
      output.write('   * Sets the value of the \"{0}\"'.format(strFunctions.cleanStr(attName)))
      output.write(' attribute of this {0}.\n'.format(element))
      output.write('   *\n')
      output.write('   * @param {0}; string value of the "{1}" attribute to be set\n'.format(strFunctions.cleanStr(attName), attName))
      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('  virtual int set{0}('.format(capAttName))
      output.write('const std::string& {0});\n\n\n'.format(strFunctions.cleanStr(attName)))
Ejemplo n.º 3
0
def writeSetFunction(attrib, output, element):
    att = generalFunctions.parseAttributeForC(attrib)
    attName = att[0]
    capAttName = att[1]
    attType = att[2]
    attTypeCode = att[3]
    num = att[4]
    if (
        attrib["type"] != "element"
        and attrib["type"] != "lo_element"
        and attrib["type"] != "XMLNode*"
        and attrib["type"] != "inline_lo_element"
    ):
        output.write("/**\n")
        output.write(' * Sets the "{0}" attribute of the given {1}_t structure.\n *\n'.format(attName, element))
        if attType == "string":
            output.write(" * This function copies the string given in @p string.  If the string is\n")
            output.write(
                " * a null pointer, this function performs {0}_unset{1}() instead.\n *\n".format(element, capAttName)
            )
        output.write(" * @param {0} the {1}_t structure.\n *\n".format(strFunctions.objAbbrev(element), element))
        output.write(
            ' * @param {0} the string to which the structures "{1}" attribute should be\n'.format(
                strFunctions.cleanStr(attName), attName
            )
        )
        output.write(" * set.\n *\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 @link OperationReturnValues_t#LIBSBML_OPERATION_SUCCESS LIBSBML_OPERATION_SUCCESS@endlink\n"
        )
        output.write(
            " * @li @link OperationReturnValues_t#LIBSBML_INVALID_ATTRIBUTE_VALUE LIBSBML_INVALID_ATTRIBUTE_VALUE@endlink\n"
        )
        output.write(" * @li @link OperationReturnValues_t#LIBSBML_INVALID_OBJECT LIBSBML_INVALID_OBJECT@endlink\n *\n")
        if attType == "string":
            output.write(" * @note Using this function with a null pointer for @p name is equivalent to\n")
            output.write(' * unsetting the value of the "name" attribute.\n * \n')
        output.write(" * @member of {0}_t\n".format(element))
        output.write(" */\n")
        output.write("LIBSBML_EXTERN\n")
        output.write("int\n")
        output.write("{0}_set{1}".format(element, capAttName))
        output.write("({0}_t * {1},".format(element, strFunctions.objAbbrev(element)))
        output.write(" {0} {1});\n\n\n".format(attTypeCode, strFunctions.cleanStr(attName)))
    elif attrib["type"] == "XMLNode*":
        output.write("LIBSBML_EXTERN\n")
        output.write("int\n")
        output.write("{0}_set{1}".format(element, capAttName))
        output.write("({0}_t * {1},".format(element, strFunctions.objAbbrev(element)))
        output.write(" XMLNode_t* {0});\n\n\n".format(strFunctions.cleanStr(attName)))
    elif attrib["type"] == "element":
        if attrib["name"] == "Math" or attrib["name"] == "math":
            output.write("/**\n")
            output.write(" * Sets the mathematical expression of the given {0}_t structure.\n *\n".format(element))
            output.write(" * @param {0} the {1}_t structure.\n *\n".format(strFunctions.objAbbrev(element), element))
            output.write(' * @param math an ASTNode_t structure to be assigned as the "math"\n')
            output.write(" * subelement of this {0}_t.\n *\n".format(element))
            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 @link OperationReturnValues_t#LIBSBML_OPERATION_SUCCESS LIBSBML_OPERATION_SUCCESS@endlink\n"
            )
            output.write(
                " * @li @link OperationReturnValues_t#LIBSBML_INVALID_OBJECT LIBSBML_INVALID_OBJECT@endlink\n *\n"
            )
            output.write(" * @member of {0}_t\n".format(element))
            output.write(" */\n")
            output.write("LIBSBML_EXTERN\n")
            output.write("int\n")
            output.write("{0}_setMath".format(element))
            output.write("({0}_t * {1},".format(element, strFunctions.objAbbrev(element)))
            output.write(" const ASTNode_t* {0});\n\n\n".format(strFunctions.cleanStr(attName)))
        else:
            output.write("LIBSBML_EXTERN\n")
            output.write("int\n")
            output.write("{0}_set{1}".format(element, capAttName))
            output.write("({0}_t * {1},".format(element, strFunctions.objAbbrev(element)))
            output.write(" {0}_t* {1});\n\n\n".format(attrib["element"], strFunctions.cleanStr(attName)))
Ejemplo n.º 4
0
def writeSetCode(attrib, output, element):
  att = generalFunctions.parseAttribute(attrib)
  attName = att[0]
  cleanName = strFunctions.cleanStr(attName)
  capAttName = att[1]
  attType = att[2]
  if attType == 'string':
    attTypeCode = 'const std::string&'
  else:
    attTypeCode = att[3]
  num = att[4]
  if attType == 'lo_element' or attType == 'inline_lo_element':
    return
  if attrib['type'] == 'array':
    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 inArray; {1} array to be set (it will be copied).\n'.format(attName, attTypeCode))
    output.write(' * @param arrayLength; the length of the array.\n')
    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{0}::set{1}('.format(element, capAttName))
    output.write('{0} inArray, int arrayLength)\n'.format(attTypeCode))
    output.write('{\n')
    output.write('  if (inArray == NULL) return LIBSBML_INVALID_ATTRIBUTE_VALUE;\n')
    output.write('\n')
    output.write('  if (m{0} != NULL) delete[] m{0};\n'.format(capAttName))
    output.write('  m{0} = new {1}[arrayLength];\n'.format(capAttName, attrib['element']))
    output.write('  memcpy(m{0}, inArray, sizeof({1})*arrayLength);\n'.format(capAttName, attrib['element']))
    output.write('  mIsSet{0}Length = true;\n'.format(capAttName))
    output.write('  m{0}Length = arrayLength;\n'.format(capAttName))
    output.write('\n')
    output.write('  return LIBSBML_OPERATION_SUCCESS;\n')
    output.write('}\n')
    return
  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, cleanName))
  output.write('{\n')
  if attType == 'string':
    if attName == 'id':
      output.write('  return SyntaxChecker::checkAndSetSId({0}, m{1});\n'.format(attName, capAttName))
    else:
      output.write('  if (&({0}) == NULL)\n'.format(cleanName))
      output.write('  {\n    return LIBSBML_INVALID_ATTRIBUTE_VALUE;\n  }\n')
      if attrib['type'] == 'SIdRef':
        output.write('  else if (!(SyntaxChecker::isValidInternalSId({0})))\n'.format(cleanName))
        output.write('  {\n    return LIBSBML_INVALID_ATTRIBUTE_VALUE;\n  }\n')
      output.write('  else\n  {\n')
      output.write('    m{0} = {1};\n'.format(capAttName, cleanName))
      output.write('    return LIBSBML_OPERATION_SUCCESS;\n  }\n')
  elif num == True:
    output.write('  m{0} = {1};\n'.format(capAttName, cleanName))
    output.write('  mIsSet{0} = true;\n'.format(capAttName))
    output.write('  return LIBSBML_OPERATION_SUCCESS;\n')
  elif attrib['type'] == 'enum':
    output.write('  m{0} = {1};\n'.format(capAttName, cleanName))
    output.write('  return LIBSBML_OPERATION_SUCCESS;\n')
  elif attrib['type'] == 'array':
    output.write('  m{0} = {1};\n'.format(capAttName, cleanName))
    output.write('  return LIBSBML_OPERATION_SUCCESS;\n')
  elif attType == 'boolean':
    output.write('  m{0} = {1};\n'.format(capAttName, cleanName))
    output.write('  mIsSet{0} = true;\n'.format(capAttName))
    output.write('  return LIBSBML_OPERATION_SUCCESS;\n')
  elif attType == 'XMLNode*':
      output.write('  if (m{0} == {1})\n'.format(capAttName, cleanName))
      output.write('  {\n    return LIBSBML_OPERATION_SUCCESS;\n  }\n')
      output.write('  else if ({0} == NULL)\n'.format(cleanName))
      output.write('  {\n')
      output.write('    delete m{0};\n'.format(capAttName))
      output.write('    m{0} = NULL;\n'.format(capAttName))
      output.write('    return LIBSBML_OPERATION_SUCCESS;\n  }\n')
      output.write('  delete m{0};\n'.format(capAttName))
      output.write('  m{0} = ({1} != NULL) ?\n'.format(capAttName, cleanName))
      output.write('    {0}->clone() : NULL;\n'.format(cleanName))
      output.write('  return LIBSBML_OPERATION_SUCCESS;\n')
  elif attType == 'element':
    output.write('  if (m{0} == {1})\n'.format(capAttName, cleanName))
    output.write('  {\n    return LIBSBML_OPERATION_SUCCESS;\n  }\n')
    output.write('  else if ({0} == NULL)\n'.format(cleanName))
    output.write('  {\n')
    output.write('    delete m{0};\n'.format(capAttName))
    output.write('    m{0} = NULL;\n'.format(capAttName))
    output.write('    return LIBSBML_OPERATION_SUCCESS;\n  }\n')
    if attTypeCode == 'const ASTNode*':
      output.write('  else if (!({0}->isWellFormedASTNode()))\n'.format(cleanName))
      output.write('  {\n    return LIBSBML_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, cleanName))
    if attTypeCode == 'const ASTNode*':
      output.write('      {0}->deepCopy() : NULL;\n'.format(cleanName))
    else:
      output.write('      static_cast<{0}>({1}->clone()) : NULL;\n'.format(attTypeCode, cleanName))
    output.write('    if (m{0} != NULL)\n'.format(capAttName))
    output.write('    {\n')
    if attTypeCode == 'const ASTNode*':
      output.write('      m{0}->setParentSBMLObject(this);\n'.format(capAttName, cleanName))
    else:
      if generalFunctions.overridesElementName(attrib):
        output.write('      m{0}->setElementName("{1}");\n'.format(capAttName, cleanName))
      output.write('      m{0}->connectToParent(this);\n'.format(capAttName, cleanName))
    output.write('    }\n')
    output.write('    return LIBSBML_OPERATION_SUCCESS;\n  }\n')
  output.write('}\n\n\n')

  if attrib['type'] == 'enum':
    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}(const std::string& {2})\n'.format(element, capAttName, cleanName))
    output.write('{\n')
    output.write('  {0}_t parsed = {0}_parse({1}.c_str());\n'.format(attrib['element'], cleanName))
    output.write('  if (parsed == {0}_UNKNOWN) return LIBSBML_INVALID_ATTRIBUTE_VALUE;\n'.format(attrib['element'].upper(), cleanName))
    output.write('  m{0} = parsed;\n'.format(capAttName))
    output.write('  return LIBSBML_OPERATION_SUCCESS;\n')
    output.write('}\n\n\n')
Ejemplo n.º 5
0
def writeSetFunction(attrib, output, element):
    att = generalFunctions.parseAttributeForC(attrib)
    attName = att[0]
    capAttName = att[1]
    attType = att[2]
    attTypeCode = att[3]
    num = att[4]
    if attrib['type'] != 'element' and attrib[
            'type'] != 'lo_element' and attrib[
                'type'] != 'XMLNode*' and attrib['type'] != 'inline_lo_element':
        output.write('/**\n')
        output.write(
            ' * Sets the \"{0}\" attribute of the given {1}_t structure.\n *\n'
            .format(attName, element))
        if (attType == 'string'):
            output.write(
                ' * This function copies the string given in @p string.  If the string is\n'
            )
            output.write(
                ' * a null pointer, this function performs {0}_unset{1}() instead.\n *\n'
                .format(element, capAttName))
        output.write(' * @param {0} the {1}_t structure.\n *\n'.format(
            strFunctions.objAbbrev(element), element))
        output.write(
            ' * @param {0} the string to which the structures \"{1}\" attribute should be\n'
            .format(strFunctions.cleanStr(attName), attName))
        output.write(' * set.\n *\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 @link OperationReturnValues_t#LIBSBML_OPERATION_SUCCESS LIBSBML_OPERATION_SUCCESS@endlink\n'
        )
        output.write(
            ' * @li @link OperationReturnValues_t#LIBSBML_INVALID_ATTRIBUTE_VALUE LIBSBML_INVALID_ATTRIBUTE_VALUE@endlink\n'
        )
        output.write(
            ' * @li @link OperationReturnValues_t#LIBSBML_INVALID_OBJECT LIBSBML_INVALID_OBJECT@endlink\n *\n'
        )
        if (attType == 'string'):
            output.write(
                ' * @note Using this function with a null pointer for @p name is equivalent to\n'
            )
            output.write(
                ' * unsetting the value of the "name" attribute.\n * \n')
        output.write(' * @member of {0}_t\n'.format(element))
        output.write(' */\n')
        output.write('LIBSBML_EXTERN\n')
        output.write('int\n')
        output.write('{0}_set{1}'.format(element, capAttName))
        output.write('({0}_t * {1},'.format(element,
                                            strFunctions.objAbbrev(element)))
        output.write(' {0} {1});\n\n\n'.format(attTypeCode,
                                               strFunctions.cleanStr(attName)))
    elif attrib['type'] == 'XMLNode*':
        output.write('LIBSBML_EXTERN\n')
        output.write('int\n')
        output.write('{0}_set{1}'.format(element, capAttName))
        output.write('({0}_t * {1},'.format(element,
                                            strFunctions.objAbbrev(element)))
        output.write(' XMLNode_t* {0});\n\n\n'.format(
            strFunctions.cleanStr(attName)))
    elif attrib['type'] == 'element':
        if attrib['name'] == 'Math' or attrib['name'] == 'math':
            output.write('/**\n')
            output.write(
                ' * Sets the mathematical expression of the given {0}_t structure.\n *\n'
                .format(element))
            output.write(' * @param {0} the {1}_t structure.\n *\n'.format(
                strFunctions.objAbbrev(element), element))
            output.write(
                ' * @param math an ASTNode_t structure to be assigned as the \"math\"\n'
            )
            output.write(' * subelement of this {0}_t.\n *\n'.format(element))
            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 @link OperationReturnValues_t#LIBSBML_OPERATION_SUCCESS LIBSBML_OPERATION_SUCCESS@endlink\n'
            )
            output.write(
                ' * @li @link OperationReturnValues_t#LIBSBML_INVALID_OBJECT LIBSBML_INVALID_OBJECT@endlink\n *\n'
            )
            output.write(' * @member of {0}_t\n'.format(element))
            output.write(' */\n')
            output.write('LIBSBML_EXTERN\n')
            output.write('int\n')
            output.write('{0}_setMath'.format(element))
            output.write('({0}_t * {1},'.format(
                element, strFunctions.objAbbrev(element)))
            output.write(' const ASTNode_t* {0});\n\n\n'.format(
                strFunctions.cleanStr(attName)))
        else:
            output.write('LIBSBML_EXTERN\n')
            output.write('int\n')
            output.write('{0}_set{1}'.format(element, capAttName))
            output.write('({0}_t * {1},'.format(
                element, strFunctions.objAbbrev(element)))
            output.write(' {0}_t* {1});\n\n\n'.format(
                attrib['element'], strFunctions.cleanStr(attName)))
Ejemplo n.º 6
0
def writeSetCode(attrib, output, element):
  att = generalFunctions.parseAttribute(attrib)
  attName = att[0]
  cleanName = strFunctions.cleanStr(attName)
  capAttName = att[1]
  attType = att[2]
  if attType == 'string':
    attTypeCode = 'const std::string&'
  else:
    attTypeCode = att[3]
  num = att[4]
  if attType == 'lo_element' or attType == 'inline_lo_element':
    return
  if attrib['type'] == 'array':
    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 inArray; {1} array to be set (it will be copied).\n'.format(attName, attTypeCode))
    output.write(' * @param arrayLength; the length of the array.\n')
    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{0}::set{1}('.format(element, capAttName))
    output.write('{0} inArray, int arrayLength)\n'.format(attTypeCode))
    output.write('{\n')
    output.write('  if (inArray == NULL) return LIBSBML_INVALID_ATTRIBUTE_VALUE;\n')
    output.write('\n')
    output.write('  if (m{0} != NULL) delete[] m{0};\n'.format(capAttName))
    output.write('  m{0} = new {1}[arrayLength];\n'.format(capAttName, attrib['element']))
    output.write('  memcpy(m{0}, inArray, sizeof({1})*arrayLength);\n'.format(capAttName, attrib['element']))
    output.write('  mIsSet{0}Length = true;\n'.format(capAttName))
    output.write('  m{0}Length = arrayLength;\n'.format(capAttName))
    output.write('\n')
    output.write('  return LIBSBML_OPERATION_SUCCESS;\n')
    output.write('}\n')
    return
  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, cleanName))
  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(cleanName))
        output.write('  {\n    return LIBSBML_INVALID_ATTRIBUTE_VALUE;\n  }\n')
        output.write('  else\n')
      output.write('  {\n')
      output.write('    m{0} = {1};\n'.format(capAttName, cleanName))
      output.write('    return LIBSBML_OPERATION_SUCCESS;\n  }\n')
  elif num == True:
    output.write('  m{0} = {1};\n'.format(capAttName, cleanName))
    output.write('  mIsSet{0} = true;\n'.format(capAttName))
    output.write('  return LIBSBML_OPERATION_SUCCESS;\n')
  elif attrib['type'] == 'enum':
    output.write('  m{0} = {1};\n'.format(capAttName, cleanName))
    output.write('  return LIBSBML_OPERATION_SUCCESS;\n')
  elif attrib['type'] == 'array':
    output.write('  m{0} = {1};\n'.format(capAttName, cleanName))
    output.write('  return LIBSBML_OPERATION_SUCCESS;\n')
  elif attType == 'boolean':
    output.write('  m{0} = {1};\n'.format(capAttName, cleanName))
    output.write('  mIsSet{0} = true;\n'.format(capAttName))
    output.write('  return LIBSBML_OPERATION_SUCCESS;\n')
  elif attType == 'XMLNode*':
      output.write('  if (m{0} == {1})\n'.format(capAttName, cleanName))
      output.write('  {\n    return LIBSBML_OPERATION_SUCCESS;\n  }\n')
      output.write('  else if ({0} == NULL)\n'.format(cleanName))
      output.write('  {\n')
      output.write('    delete m{0};\n'.format(capAttName))
      output.write('    m{0} = NULL;\n'.format(capAttName))
      output.write('    return LIBSBML_OPERATION_SUCCESS;\n  }\n')
      output.write('  delete m{0};\n'.format(capAttName))
      output.write('  m{0} = ({1} != NULL) ?\n'.format(capAttName, cleanName))
      output.write('    {0}->clone() : NULL;\n'.format(cleanName))
      output.write('  return LIBSBML_OPERATION_SUCCESS;\n')
  elif attType == 'element':
    output.write('  if (m{0} == {1})\n'.format(capAttName, cleanName))
    output.write('  {\n    return LIBSBML_OPERATION_SUCCESS;\n  }\n')
    output.write('  else if ({0} == NULL)\n'.format(cleanName))
    output.write('  {\n')
    output.write('    delete m{0};\n'.format(capAttName))
    output.write('    m{0} = NULL;\n'.format(capAttName))
    output.write('    return LIBSBML_OPERATION_SUCCESS;\n  }\n')
    if attTypeCode == 'const ASTNode*':
      output.write('  else if (!({0}->isWellFormedASTNode()))\n'.format(cleanName))
      output.write('  {\n    return LIBSBML_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, cleanName))
    if attTypeCode == 'const ASTNode*':
      output.write('      {0}->deepCopy() : NULL;\n'.format(cleanName))
    else:
      output.write('      static_cast<{0}>({1}->clone()) : NULL;\n'.format(attTypeCode, cleanName))
    output.write('    if (m{0} != NULL)\n'.format(capAttName))
    output.write('    {\n')
    if attTypeCode == 'const ASTNode*':
      output.write('      m{0}->setParentSBMLObject(this);\n'.format(capAttName, cleanName))
    else:
      if generalFunctions.overridesElementName(attrib):
        output.write('      m{0}->setElementName("{1}");\n'.format(capAttName, cleanName))
      output.write('      m{0}->connectToParent(this);\n'.format(capAttName, cleanName))
    output.write('    }\n')
    output.write('    return LIBSBML_OPERATION_SUCCESS;\n  }\n')
  output.write('}\n\n\n')

  if attrib['type'] == 'enum':
    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}(const std::string& {2})\n'.format(element, capAttName, cleanName))
    output.write('{\n')
    output.write('  {0}_t parsed = {0}_parse({1}.c_str());\n'.format(attrib['element'], cleanName))
    output.write('  if (parsed == {0}_UNKNOWN) return LIBSBML_INVALID_ATTRIBUTE_VALUE;\n'.format(attrib['element'].upper(), cleanName))
    output.write('  m{0} = parsed;\n'.format(capAttName))
    output.write('  return LIBSBML_OPERATION_SUCCESS;\n')
    output.write('}\n\n\n')
Ejemplo n.º 7
0
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' or attrib['type'] == 'inline_lo_element':
    return
  elif attrib['type'] == 'array':
    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 inArray; {1} array to be set (it will be copied).\n'.format(attName, attTypeCode))
    output.write('   * @param arrayLength; the length of the array.\n')
    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('  virtual int set{0}('.format(capAttName))
    output.write('{0} inArray, int arrayLength);\n\n\n'.format(attTypeCode))
  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} to be set.\n'.format(strFunctions.cleanStr(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 LIBSBML_OPERATION_SUCCESS\n')
    output.write('   * @li LIBSBML_INVALID_ATTRIBUTE_VALUE\n')
    output.write('   */\n')
    output.write('  virtual int set{0}('.format(capAttName))
    output.write('{0} {1});\n\n\n'.format(attTypeCode, strFunctions.cleanStr(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 "{2}" attribute to be set\n'.format(strFunctions.cleanStr(attName), attTypeCode, attName))
    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('  virtual int set{0}('.format(capAttName))
    output.write('{0} {1});\n\n\n'.format(attTypeCode, strFunctions.cleanStr(attName)))

    if attrib['type'] == 'enum':
      output.write('  /**\n')
      output.write('   * Sets the value of the \"{0}\"'.format(strFunctions.cleanStr(attName)))
      output.write(' attribute of this {0}.\n'.format(element))
      output.write('   *\n')
      output.write('   * @param {0}; string value of the "{1}" attribute to be set\n'.format(strFunctions.cleanStr(attName), attName))
      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('  virtual int set{0}('.format(capAttName))
      output.write('const std::string& {0});\n\n\n'.format(strFunctions.cleanStr(attName)))