UncertMLNode * UncertMLNode::createStatisticsNode(std::string arguments, std::string argumentIds) { UncertMLNode *node = new UncertMLNode(); node->setElementName("StatisticsCollection"); 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/statistics"); 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 * valueChild = new UncertMLNode(); valueChild->setElementName("value"); valueChild->addChild(varChild); UncertMLNode * child = new UncertMLNode(); child->setElementName(args.at(i)); XMLAttributes attr1 = XMLAttributes(); attr1.add("definition", "http://www.uncertml.org/statistics"); child->setAttributes(attr1); child->addChild(valueChild); node->addChild(child); } return node; }
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; }