Commit 7cb7333a authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Clean up XInclude additions. Verify that writing reading and writing an...

ENH: Clean up XInclude additions.  Verify that writing reading and writing an XPath/XInclude file produces the same file.
parent 326d3866
......@@ -23,7 +23,7 @@ public:
{
};
std::vector<boost::shared_ptr<XdmfItem> > read(xmlNodePtr currNode)
std::vector<boost::shared_ptr<XdmfItem> > read(xmlNodePtr currNode, bool ignoreSiblings = false)
{
std::vector<boost::shared_ptr<XdmfItem> > myItems;
......@@ -31,10 +31,10 @@ public:
{
if(currNode->type == XML_ELEMENT_NODE)
{
xmlChar * xpointer = NULL;
if(xmlStrcmp(currNode->name, (xmlChar*)"include") == 0)
{
xmlAttrPtr currAttribute = currNode->properties;
xmlChar * xpointer;
while(currAttribute != NULL)
{
if(xmlStrcmp(currAttribute->name, (xmlChar*)"xpointer") == 0)
......@@ -44,23 +44,12 @@ public:
}
}
xmlXPathObjectPtr xPathObject = xmlXPtrEval(xpointer, mXPathContext);
std::cout << "HERE" << std::endl;
std::map<xmlNodePtr, boost::shared_ptr<XdmfItem> >::const_iterator iter = mXPathMap.find(xPathObject->nodesetval->nodeTab[0]);
if(iter != mXPathMap.end())
for(unsigned int i=0; i<xPathObject->nodesetval->nodeNr; ++i)
{
myItems.push_back(iter->second);
std::vector<boost::shared_ptr<XdmfItem> > newItems = this->read(xPathObject->nodesetval->nodeTab[i], true);
myItems.insert(myItems.end(), newItems.begin(), newItems.end());
}
//this->read();
//for(unsigned int i=0; i<xPathObject->nodesetval->nodeNr; ++i)
//{
//std::cout << xPathObject->nodesetval->nodeTab[i]->type << std::endl;
//std::cout << xPathObject->nodesetval->nodeTab[i]->name << std::endl;
//this->read(xPathObject->nodesetval->nodeTab[i]);
//currNode = NULL;
//currNode = xPathObject->nodesetval->nodeTab[0];
//}
//xmlXPathFreeObject(xPathObject);
xmlXPathFreeObject(xPathObject);
}
else
{
......@@ -86,7 +75,7 @@ public:
itemProperties[(const char *)currAttribute->name] = (const char *)currAttribute->children->content;
currAttribute = currAttribute->next;
}
std::vector<boost::shared_ptr<XdmfItem> > childItems = this->read(currNode->children);
std::vector<boost::shared_ptr<XdmfItem> > childItems = this->read(currNode->children, ignoreSiblings);
boost::shared_ptr<XdmfItem> newItem = mItemFactory->createItem((const char *)currNode->name, itemProperties);
newItem->populateItem(itemProperties, childItems);
myItems.push_back(newItem);
......@@ -94,7 +83,14 @@ public:
}
}
}
currNode = currNode->next;
if(ignoreSiblings)
{
currNode = NULL;
}
else
{
currNode = currNode->next;
}
}
return myItems;
}
......
......@@ -8,7 +8,7 @@
int main(int argc, char* argv[])
{
boost::shared_ptr<XdmfWriter> writer = XdmfWriter::New("xpath.xmf");
boost::shared_ptr<XdmfWriter> writer = XdmfWriter::New("xpath1.xmf");
boost::shared_ptr<XdmfGrid> grid = XdmfTestDataGenerator::createHexahedron();
boost::shared_ptr<XdmfGrid> newGrid = XdmfGrid::New();
......@@ -23,7 +23,7 @@ int main(int argc, char* argv[])
domain->accept(writer);
// Try to find xpaths written to file
std::ifstream file("xpath.xmf");
std::ifstream file("xpath1.xmf");
std::stringstream fileBuffer;
fileBuffer << file.rdbuf();
std::string fileContents(fileBuffer.str());
......@@ -34,9 +34,24 @@ int main(int argc, char* argv[])
// Make sure when we read it in we get the same structure as when we wrote it out (multiple items holding the same shared pointers)
boost::shared_ptr<XdmfReader> reader = XdmfReader::New();
boost::shared_ptr<XdmfDomain> domain2 = boost::shared_dynamic_cast<XdmfDomain>(reader->read("xpath.xmf"));
boost::shared_ptr<XdmfDomain> domain2 = boost::shared_dynamic_cast<XdmfDomain>(reader->read("xpath1.xmf"));
boost::shared_ptr<XdmfWriter> writer2 = XdmfWriter::New("xpath2.xmf");
domain2->accept(writer2);
// Compare two files for equality
std::ifstream firstFile("xpath1.xmf");
std::ifstream secondFile("xpath2.xmf");
std::stringstream firstBuffer;
std::stringstream secondBuffer;
firstBuffer << firstFile.rdbuf();
secondBuffer << secondFile.rdbuf();
std::string firstContents(firstBuffer.str());
std::string secondContents(secondBuffer.str());
assert(firstContents.compare(secondContents) == 0);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment