Пример #1
0
UncertMLNode * 
UncertMLNode::createDistributionNode(std::string name, 
                     std::string arguments, std::string argumentIds)
{
  UncertMLNode *node = new UncertMLNode();
  node->setElementName(name);

  XMLAttributes attr = XMLAttributes();
  /* really the url should be specific to the distribtuion
  * but whilst the attribue is required in uncertML it does not require
  * it to be an exact match
  */
  attr.add("definition", "http://www.uncertml.org/distributions");
  node->setAttributes(attr);

  /* create an idlist from the arguments 
   * and check we have the same number of args and ids
   */
  IdList args = IdList(arguments);
  IdList argIds = IdList(argumentIds);

  unsigned int numArgs = args.size();
  unsigned int numIds = argIds.size();

  if (numArgs != numIds)
  {
    return NULL;
  }


  for (unsigned int i = 0; i < numArgs; i++)
  {
    UncertMLNode * varChild = new UncertMLNode();
    varChild->setElementName("var");
    
    XMLAttributes attributes = XMLAttributes();
    attributes.add("varId", argIds.at(i));
    varChild->setAttributes(attributes);

    UncertMLNode * child = new UncertMLNode();
    child->setElementName(args.at(i));

    child->addChild(varChild);

    node->addChild(child);
  }


  return node;
}
Пример #2
0
bool
UncertMLNode::parseXMLNode(const XMLNode* xml)
{
  // if we have an UncertML element then we want the
  // child
  if (xml->getName() == "UncertML")
  {
    xml = &(xml->getChild(0));
  }

  bool success = true;

  // set the element name
  if (setElementName(xml->getName()) != LIBSBML_OPERATION_SUCCESS)
  {
    success = false;
  }

  // set any attributes from teh element
  if (xml->getAttributesLength() > 0 && success != false)
  {
    if (setAttributes(xml->getAttributes()) != LIBSBML_OPERATION_SUCCESS)
    {
      success = false;
    }
  }

  // loop thru the children of the XMLNode
  // parse each and add as a child
  for (unsigned int i = 0; success != false && i < xml->getNumChildren(); i++)
  {
    UncertMLNode * child = new UncertMLNode();
    success = child->parseXMLNode(&(xml->getChild(i)));
    if (success == true)
    {
      if (addChild(child) != LIBSBML_OPERATION_SUCCESS)
      {
        success = false;
      }
    }
  }

  return success;
}
Пример #3
0
/*
 * Copy constructor for UncertMLNode.
 */
UncertMLNode::UncertMLNode (const UncertMLNode& orig)
{
  if (&orig == NULL)
  {
    throw SBMLConstructorException("Null argument to copy constructor");
  }
  else
  {
    mElementName  = orig.mElementName;
    mAttributes  = orig.mAttributes;

    mChildren = new List();

    for (unsigned int c = 0; c < orig.getNumChildren(); ++c)
    {
      addChild( orig.getChild(c)->clone() );
    }
  }
}
END_TEST
  

START_TEST (test_uncertml_children)
{
  fail_unless ( node->getNumChildren() == 0 );
  
  node->setElementName("parent");

  UncertMLNode * child = new UncertMLNode();
  child->setElementName("child");

  int i = node->addChild(child);

  fail_unless ( i == LIBSBML_OPERATION_SUCCESS );
  fail_unless ( node->getNumChildren() == 1 );

  const UncertMLNode * retrieved = node->getChild(0);

  fail_unless ( retrieved != NULL );
  fail_unless ( retrieved->getElementName() == "child" );

  delete child;
}