Commit 983479ed authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Commit Ken Renard's patches modifying populateItem and XdmfCoreReader to...

ENH: Commit Ken Renard's patches modifying populateItem and XdmfCoreReader to support some xpath functionality for backwards compatibility.
parent ab73bf69
......@@ -57,7 +57,7 @@ boost::shared_ptr<const XdmfAttributeType> XdmfAttribute::getType() const
return mAttributeType;
}
void XdmfAttribute::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems)
void XdmfAttribute::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems, const XdmfCoreReader * const reader)
{
std::map<std::string, std::string>::const_iterator name = itemProperties.find("Name");
if(name != itemProperties.end())
......
......@@ -80,7 +80,7 @@ public:
protected:
XdmfAttribute();
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems);
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems, const XdmfCoreReader * const reader);
private:
......
......@@ -84,7 +84,7 @@ void XdmfDomain::insert(const boost::shared_ptr<XdmfGridCollection> gridCollecti
mGridCollections.push_back(gridCollection);
}
void XdmfDomain::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems)
void XdmfDomain::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems, const XdmfCoreReader * const reader)
{
for(std::vector<boost::shared_ptr<XdmfItem> >::const_iterator iter = childItems.begin(); iter != childItems.end(); ++iter)
{
......
......@@ -112,7 +112,7 @@ public:
protected:
XdmfDomain();
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems);
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems, const XdmfCoreReader * const reader);
private:
......
......@@ -52,7 +52,7 @@ boost::shared_ptr<const XdmfGeometryType> XdmfGeometry::getType() const
return mGeometryType;
}
void XdmfGeometry::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems)
void XdmfGeometry::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems, const XdmfCoreReader * const reader)
{
mGeometryType = XdmfGeometryType::New(itemProperties);
for(std::vector<boost::shared_ptr<XdmfItem> >::const_iterator iter = childItems.begin(); iter != childItems.end(); ++iter)
......
......@@ -56,7 +56,7 @@ public:
protected:
XdmfGeometry();
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems);
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems, const XdmfCoreReader * const reader);
private:
......
......@@ -173,7 +173,7 @@ void XdmfGrid::insert(const boost::shared_ptr<XdmfSet> set)
mSets.push_back(set);
}
void XdmfGrid::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems)
void XdmfGrid::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems, const XdmfCoreReader * const reader)
{
std::map<std::string, std::string>::const_iterator name = itemProperties.find("Name");
if(name != itemProperties.end())
......
......@@ -263,7 +263,7 @@ public:
protected:
XdmfGrid();
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems);
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems, const XdmfCoreReader * const reader);
boost::shared_ptr<XdmfGeometry> mGeometry;
std::string mName;
......
......@@ -48,11 +48,11 @@ boost::shared_ptr<const XdmfGridCollectionType> XdmfGridCollection::getType() co
return mCollectionType;
}
void XdmfGridCollection::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems)
void XdmfGridCollection::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems, const XdmfCoreReader * const reader)
{
mCollectionType = XdmfGridCollectionType::New(itemProperties);
XdmfDomain::populateItem(itemProperties, childItems);
XdmfGrid::populateItem(itemProperties, childItems);
XdmfDomain::populateItem(itemProperties, childItems, reader);
XdmfGrid::populateItem(itemProperties, childItems, reader);
}
void XdmfGridCollection::setType(const boost::shared_ptr<const XdmfGridCollectionType> collectionType)
......
......@@ -59,7 +59,7 @@ public:
protected:
XdmfGridCollection();
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems);
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems, const XdmfCoreReader * const reader);
private:
......
......@@ -146,7 +146,7 @@ bool XdmfMap::isInitialized() const
return mImpl->mMap.size() > 0;
}
void XdmfMap::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems)
void XdmfMap::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems, const XdmfCoreReader * const reader)
{
std::vector<boost::shared_ptr<XdmfArray> > arrayVector;
arrayVector.reserve(3);
......
......@@ -60,7 +60,7 @@ public:
protected:
XdmfMap();
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems);
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems, const XdmfCoreReader * const reader);
private:
......
......@@ -67,7 +67,7 @@ bool XdmfSet::isInitialized() const
return std::set<unsigned int>::size() > 0;
}
void XdmfSet::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems)
void XdmfSet::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems, const XdmfCoreReader * const reader)
{
std::map<std::string, std::string>::const_iterator name = itemProperties.find("Name");
if(name != itemProperties.end())
......
......@@ -106,12 +106,10 @@ public:
void traverse(const boost::shared_ptr<XdmfBaseVisitor> visitor);
XdmfSet();
protected:
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems);
XdmfSet();
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems, const XdmfCoreReader * const reader);
private:
......
......@@ -44,7 +44,7 @@ double XdmfTime::getValue() const
return mValue;
}
void XdmfTime::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems)
void XdmfTime::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems, const XdmfCoreReader * const reader)
{
std::map<std::string, std::string>::const_iterator value = itemProperties.find("Value");
if(value != itemProperties.end())
......
......@@ -47,7 +47,7 @@ public:
protected:
XdmfTime(const double & value);
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems);
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems, const XdmfCoreReader * const reader);
private:
......
......@@ -58,7 +58,7 @@ boost::shared_ptr<const XdmfTopologyType> XdmfTopology::getType() const
return mTopologyType;
}
void XdmfTopology::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems)
void XdmfTopology::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems, const XdmfCoreReader * const reader)
{
mTopologyType = XdmfTopologyType::New(itemProperties);
for(std::vector<boost::shared_ptr<XdmfItem> >::const_iterator iter = childItems.begin(); iter != childItems.end(); ++iter)
......
......@@ -58,7 +58,7 @@ public:
protected:
XdmfTopology();
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems);
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems, const XdmfCoreReader * const reader);
private:
......
......@@ -532,7 +532,7 @@ void XdmfArray::internalizeArrayPointer()
}
}
void XdmfArray::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems)
void XdmfArray::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems, const XdmfCoreReader * const reader)
{
std::string contentVal;
unsigned int sizeVal = 1;
......
......@@ -325,7 +325,7 @@ public:
protected:
XdmfArray();
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems);
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems, const XdmfCoreReader * const reader);
private:
......
......@@ -4,6 +4,7 @@
#include <libxml/xpointer.h>
#include <libxml/xmlreader.h>
#include <map>
#include <sstream>
#include "XdmfCoreItemFactory.hpp"
#include "XdmfCoreReader.hpp"
#include "XdmfItem.hpp"
......@@ -16,7 +17,8 @@ class XdmfCoreReader::XdmfCoreReaderImpl {
public:
XdmfCoreReaderImpl(const boost::shared_ptr<const XdmfCoreItemFactory> itemFactory) :
XdmfCoreReaderImpl(const boost::shared_ptr<const XdmfCoreItemFactory> itemFactory, const XdmfCoreReader * const coreReader) :
mCoreReader(coreReader),
mItemFactory(itemFactory)
{
};
......@@ -27,6 +29,7 @@ public:
void closeFile()
{
mXPathMap.clear();
xmlXPathFreeContext(mXPathContext);
xmlFreeDoc(mDocument);
xmlCleanupParser();
......@@ -49,12 +52,13 @@ public:
}
mXPathContext = xmlXPtrNewContext(mDocument, NULL, NULL);
mXPathMap.clear();
}
/**
* Constructs XdmfItems for all nodes in currNode's tree. XdmfItems are constructed by recursively calling this function for all children of currNode.
*/
std::vector<boost::shared_ptr<XdmfItem> > read(xmlNodePtr currNode, std::map<xmlNodePtr, boost::shared_ptr<XdmfItem> > & xPathMap) const
std::vector<boost::shared_ptr<XdmfItem> > read(xmlNodePtr currNode)
{
std::vector<boost::shared_ptr<XdmfItem> > myItems;
......@@ -75,17 +79,23 @@ public:
break;
}
}
xmlXPathObjectPtr xPathObject = xmlXPtrEval(xpointer, mXPathContext);
for(unsigned int i=0; i<xPathObject->nodesetval->nodeNr; ++i)
if(xpointer)
{
this->readSingleNode(xPathObject->nodesetval->nodeTab[i], xPathMap, myItems);
xmlXPathObjectPtr xPathObject = xmlXPtrEval(xpointer, mXPathContext);
if(xPathObject && xPathObject->nodesetval)
{
for(unsigned int i=0; i<xPathObject->nodesetval->nodeNr; ++i)
{
this->readSingleNode(xPathObject->nodesetval->nodeTab[i], myItems);
}
}
xmlXPathFreeObject(xPathObject);
}
xmlXPathFreeObject(xPathObject);
}
else
{
// Normal reading
this->readSingleNode(currNode, xPathMap, myItems);
this->readSingleNode(currNode, myItems);
}
}
currNode = currNode->next;
......@@ -94,12 +104,12 @@ public:
}
/**
* Reads a single xmlNode into an XdmfItem object in memory. The constructed XdmfItem is added to myItems and an entry is added mapping the xmlNodePtr to the new XdmfItem in the xPathMap.
* Reads a single xmlNode into an XdmfItem object in memory. The constructed XdmfItem is added to myItems and an entry is added mapping the xmlNodePtr to the new XdmfItem in the mXPathMap.
*/
void readSingleNode(const xmlNodePtr currNode, std::map<xmlNodePtr, boost::shared_ptr<XdmfItem> > & xPathMap, std::vector<boost::shared_ptr<XdmfItem> > & myItems) const
void readSingleNode(const xmlNodePtr currNode, std::vector<boost::shared_ptr<XdmfItem> > & myItems)
{
std::map<xmlNodePtr, boost::shared_ptr<XdmfItem> >::const_iterator iter = xPathMap.find(currNode);
if(iter != xPathMap.end())
std::map<xmlNodePtr, boost::shared_ptr<XdmfItem> >::const_iterator iter = mXPathMap.find(currNode);
if(iter != mXPathMap.end())
{
myItems.push_back(iter->second);
}
......@@ -118,26 +128,41 @@ 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, xPathMap);
std::vector<boost::shared_ptr<XdmfItem> > childItems = this->read(currNode->children);
boost::shared_ptr<XdmfItem> newItem = mItemFactory->createItem((const char *)currNode->name, itemProperties);
if(newItem == NULL)
{
assert(false);
}
newItem->populateItem(itemProperties, childItems);
newItem->populateItem(itemProperties, childItems, mCoreReader);
myItems.push_back(newItem);
xPathMap[currNode] = newItem;
mXPathMap[currNode] = newItem;
}
}
void readPathObjects(const std::string & xPath, std::vector<boost::shared_ptr<XdmfItem> > & myItems)
{
xmlXPathObjectPtr xPathObject = xmlXPathEvalExpression((xmlChar*)xPath.c_str(), mXPathContext);
if(xPathObject && xPathObject->nodesetval)
{
for(unsigned int i=0; i<xPathObject->nodesetval->nodeNr; ++i)
{
this->readSingleNode(xPathObject->nodesetval->nodeTab[i], myItems);
}
}
xmlXPathFreeObject(xPathObject);
}
xmlDocPtr mDocument;
const XdmfCoreReader * const mCoreReader;
const boost::shared_ptr<const XdmfCoreItemFactory> mItemFactory;
std::string mXMLDir;
xmlXPathContextPtr mXPathContext;
std::map<xmlNodePtr, boost::shared_ptr<XdmfItem> > mXPathMap;
};
XdmfCoreReader::XdmfCoreReader(const boost::shared_ptr<const XdmfCoreItemFactory> itemFactory) :
mImpl(new XdmfCoreReaderImpl(itemFactory))
mImpl(new XdmfCoreReaderImpl(itemFactory, this))
{
}
......@@ -150,8 +175,7 @@ boost::shared_ptr<XdmfItem> XdmfCoreReader::read(const std::string & filePath) c
{
mImpl->openFile(filePath);
const xmlNodePtr currNode = xmlDocGetRootElement(mImpl->mDocument);
std::map<xmlNodePtr, boost::shared_ptr<XdmfItem> > xPathMap;
const std::vector<boost::shared_ptr<XdmfItem> > toReturn = mImpl->read(currNode->children, xPathMap);
const std::vector<boost::shared_ptr<XdmfItem> > toReturn = mImpl->read(currNode->children);
mImpl->closeFile();
return toReturn[0];
}
......@@ -159,14 +183,15 @@ boost::shared_ptr<XdmfItem> XdmfCoreReader::read(const std::string & filePath) c
std::vector<boost::shared_ptr<XdmfItem> > XdmfCoreReader::read(const std::string & filePath, const std::string & xPath) const
{
mImpl->openFile(filePath);
std::vector<boost::shared_ptr<XdmfItem> > toReturn;
std::map<xmlNodePtr, boost::shared_ptr<XdmfItem> > xPathMap;
xmlXPathObjectPtr xPathObject = xmlXPathEvalExpression((xmlChar*)xPath.c_str(), mImpl->mXPathContext);
for(unsigned int i=0; i<xPathObject->nodesetval->nodeNr; ++i)
{
mImpl->readSingleNode(xPathObject->nodesetval->nodeTab[i], xPathMap, toReturn);
}
xmlXPathFreeObject(xPathObject);
std::vector<boost::shared_ptr<XdmfItem> > toReturn = this->readPathObjects(xPath);
mImpl->closeFile();
return toReturn;
}
std::vector<boost::shared_ptr<XdmfItem> > XdmfCoreReader::readPathObjects(const std::string & xPath) const
{
std::vector<boost::shared_ptr<XdmfItem> > toReturn;
mImpl->readPathObjects(xPath, toReturn);
return toReturn;
}
......@@ -39,6 +39,8 @@ public:
*/
virtual std::vector<boost::shared_ptr<XdmfItem> > read(const std::string & filePath, const std::string & xPath) const;
std::vector<boost::shared_ptr<XdmfItem> > readPathObjects(const std::string & xPath) const;
protected:
/**
......
......@@ -48,7 +48,7 @@ std::string XdmfInformation::getValue() const
return mValue;
}
void XdmfInformation::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems)
void XdmfInformation::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems, const XdmfCoreReader * const reader)
{
std::map<std::string, std::string>::const_iterator key = itemProperties.find("Name");
if(key != itemProperties.end())
......
......@@ -60,7 +60,7 @@ public:
protected:
XdmfInformation();
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems);
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems, const XdmfCoreReader * const reader);
private:
......
......@@ -2,6 +2,7 @@
#define XDMFITEM_HPP_
// Forward Declarations
class XdmfCoreReader;
class XdmfVisitor;
// Includes
......@@ -56,7 +57,7 @@ protected:
* @param itemProperties a map of key/value properties associated with this XdmfItem.
* @param childItems a vector of child items to be added to this XdmfItem.
*/
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem > > & childItems) = 0;
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem > > & childItems, const XdmfCoreReader * const reader) = 0;
private:
......
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