ENH: Split visitor operation into a visit and a traverse operation so that...

ENH: Split visitor operation into a visit and a traverse operation so that logic of how to traverse the xdmf graph is kept with xdmf objects rather than the visitor.  The visitor calls this function rather than relying on its own logic.
parent 369f62ea
......@@ -115,6 +115,7 @@ class XdmfAttributePtr(_object):
def printSelf(self): return _Xdmf.XdmfAttributePtr_printSelf(self)
def setArray(self, *args): return _Xdmf.XdmfAttributePtr_setArray(self, *args)
def getArray(self, *args): return _Xdmf.XdmfAttributePtr_getArray(self, *args)
def traverse(self, *args): return _Xdmf.XdmfAttributePtr_traverse(self, *args)
XdmfAttributePtr_swigregister = _Xdmf.XdmfAttributePtr_swigregister
XdmfAttributePtr_swigregister(XdmfAttributePtr)
......@@ -137,10 +138,11 @@ class XdmfArrayPtr(_object):
def getPrecision(self): return _Xdmf.XdmfArrayPtr_getPrecision(self)
def getSize(self): return _Xdmf.XdmfArrayPtr_getSize(self)
def getValues(self): return _Xdmf.XdmfArrayPtr_getValues(self)
def getValuesPointer(self): return _Xdmf.XdmfArrayPtr_getValuesPointer(self)
def getValuesPointer(self, *args): return _Xdmf.XdmfArrayPtr_getValuesPointer(self, *args)
def printSelf(self): return _Xdmf.XdmfArrayPtr_printSelf(self)
def write(self, *args): return _Xdmf.XdmfArrayPtr_write(self, *args)
def setValues(self, *args): return _Xdmf.XdmfArrayPtr_setValues(self, *args)
def traverse(self, *args): return _Xdmf.XdmfArrayPtr_traverse(self, *args)
XdmfArrayPtr_swigregister = _Xdmf.XdmfArrayPtr_swigregister
XdmfArrayPtr_swigregister(XdmfArrayPtr)
......@@ -160,6 +162,7 @@ class XdmfDataItemPtr(_object):
def setArray(self, *args): return _Xdmf.XdmfDataItemPtr_setArray(self, *args)
def getArray(self, *args): return _Xdmf.XdmfDataItemPtr_getArray(self, *args)
def printSelf(self): return _Xdmf.XdmfDataItemPtr_printSelf(self)
def traverse(self, *args): return _Xdmf.XdmfDataItemPtr_traverse(self, *args)
def write(self, *args): return _Xdmf.XdmfDataItemPtr_write(self, *args)
XdmfDataItemPtr_swigregister = _Xdmf.XdmfDataItemPtr_swigregister
XdmfDataItemPtr_swigregister(XdmfDataItemPtr)
......@@ -182,6 +185,7 @@ class XdmfDomainPtr(_object):
def getGrid(self, *args): return _Xdmf.XdmfDomainPtr_getGrid(self, *args)
def getNumberOfGrids(self): return _Xdmf.XdmfDomainPtr_getNumberOfGrids(self)
def printSelf(self): return _Xdmf.XdmfDomainPtr_printSelf(self)
def traverse(self, *args): return _Xdmf.XdmfDomainPtr_traverse(self, *args)
def write(self, *args): return _Xdmf.XdmfDomainPtr_write(self, *args)
XdmfDomainPtr_swigregister = _Xdmf.XdmfDomainPtr_swigregister
XdmfDomainPtr_swigregister(XdmfDomainPtr)
......@@ -208,6 +212,7 @@ class XdmfGeometryPtr(_object):
def write(self, *args): return _Xdmf.XdmfGeometryPtr_write(self, *args)
def setArray(self, *args): return _Xdmf.XdmfGeometryPtr_setArray(self, *args)
def getArray(self, *args): return _Xdmf.XdmfGeometryPtr_getArray(self, *args)
def traverse(self, *args): return _Xdmf.XdmfGeometryPtr_traverse(self, *args)
XdmfGeometryPtr_swigregister = _Xdmf.XdmfGeometryPtr_swigregister
XdmfGeometryPtr_swigregister(XdmfGeometryPtr)
......@@ -235,6 +240,7 @@ class XdmfGridPtr(_object):
def getAttribute(self, *args): return _Xdmf.XdmfGridPtr_getAttribute(self, *args)
def getNumberOfAttributes(self): return _Xdmf.XdmfGridPtr_getNumberOfAttributes(self)
def printSelf(self): return _Xdmf.XdmfGridPtr_printSelf(self)
def traverse(self, *args): return _Xdmf.XdmfGridPtr_traverse(self, *args)
def write(self, *args): return _Xdmf.XdmfGridPtr_write(self, *args)
XdmfGridPtr_swigregister = _Xdmf.XdmfGridPtr_swigregister
XdmfGridPtr_swigregister(XdmfGridPtr)
......@@ -252,6 +258,7 @@ class XdmfItemPtr(_object):
except: self.this = this
__swig_destroy__ = _Xdmf.delete_XdmfItemPtr
__del__ = lambda self : None;
def traverse(self, *args): return _Xdmf.XdmfItemPtr_traverse(self, *args)
def write(self, *args): return _Xdmf.XdmfItemPtr_write(self, *args)
def printSelf(self): return _Xdmf.XdmfItemPtr_printSelf(self)
XdmfItemPtr_swigregister = _Xdmf.XdmfItemPtr_swigregister
......@@ -297,6 +304,7 @@ class XdmfTopologyPtr(_object):
def write(self, *args): return _Xdmf.XdmfTopologyPtr_write(self, *args)
def setArray(self, *args): return _Xdmf.XdmfTopologyPtr_setArray(self, *args)
def getArray(self, *args): return _Xdmf.XdmfTopologyPtr_getArray(self, *args)
def traverse(self, *args): return _Xdmf.XdmfTopologyPtr_traverse(self, *args)
XdmfTopologyPtr_swigregister = _Xdmf.XdmfTopologyPtr_swigregister
XdmfTopologyPtr_swigregister(XdmfTopologyPtr)
......@@ -341,6 +349,7 @@ class XdmfItem(XdmfObject):
__getattr__ = lambda self, name: _swig_getattr(self, XdmfItem, name)
def __init__(self, *args, **kwargs): raise AttributeError("No constructor defined")
__repr__ = _swig_repr
def traverse(self, *args): return _Xdmf.XdmfItem_traverse(self, *args)
def write(self, *args): return _Xdmf.XdmfItem_write(self, *args)
XdmfItem_swigregister = _Xdmf.XdmfItem_swigregister
XdmfItem_swigregister(XdmfItem)
......@@ -379,7 +388,7 @@ class XdmfDataItem(XdmfItem):
def setArray(self, *args): return _Xdmf.XdmfDataItem_setArray(self, *args)
def getArray(self, *args): return _Xdmf.XdmfDataItem_getArray(self, *args)
def printSelf(self): return _Xdmf.XdmfDataItem_printSelf(self)
def write(self, *args): return _Xdmf.XdmfDataItem_write(self, *args)
def traverse(self, *args): return _Xdmf.XdmfDataItem_traverse(self, *args)
XdmfDataItem_swigregister = _Xdmf.XdmfDataItem_swigregister
XdmfDataItem_swigregister(XdmfDataItem)
......@@ -535,7 +544,7 @@ class XdmfArray(XdmfItem):
def getPrecision(self): return _Xdmf.XdmfArray_getPrecision(self)
def getSize(self): return _Xdmf.XdmfArray_getSize(self)
def getValues(self): return _Xdmf.XdmfArray_getValues(self)
def getValuesPointer(self): return _Xdmf.XdmfArray_getValuesPointer(self)
def getValuesPointer(self, *args): return _Xdmf.XdmfArray_getValuesPointer(self, *args)
def printSelf(self): return _Xdmf.XdmfArray_printSelf(self)
def write(self, *args): return _Xdmf.XdmfArray_write(self, *args)
def setValues(self, *args): return _Xdmf.XdmfArray_setValues(self, *args)
......@@ -561,6 +570,7 @@ class XdmfDomain(XdmfItem):
def getGrid(self, *args): return _Xdmf.XdmfDomain_getGrid(self, *args)
def getNumberOfGrids(self): return _Xdmf.XdmfDomain_getNumberOfGrids(self)
def printSelf(self): return _Xdmf.XdmfDomain_printSelf(self)
def traverse(self, *args): return _Xdmf.XdmfDomain_traverse(self, *args)
def write(self, *args): return _Xdmf.XdmfDomain_write(self, *args)
XdmfDomain_swigregister = _Xdmf.XdmfDomain_swigregister
XdmfDomain_swigregister(XdmfDomain)
......@@ -687,6 +697,7 @@ class XdmfGrid(XdmfItem):
def getAttribute(self, *args): return _Xdmf.XdmfGrid_getAttribute(self, *args)
def getNumberOfAttributes(self): return _Xdmf.XdmfGrid_getNumberOfAttributes(self)
def printSelf(self): return _Xdmf.XdmfGrid_printSelf(self)
def traverse(self, *args): return _Xdmf.XdmfGrid_traverse(self, *args)
def write(self, *args): return _Xdmf.XdmfGrid_write(self, *args)
XdmfGrid_swigregister = _Xdmf.XdmfGrid_swigregister
XdmfGrid_swigregister(XdmfGrid)
......
......@@ -284,5 +284,5 @@ std::string XdmfArray::printSelf() const
void XdmfArray::write(boost::shared_ptr<XdmfVisitor> visitor) const
{
visitor->visit(this);
visitor->visit(this, visitor);
}
......@@ -63,7 +63,7 @@ void XdmfAttribute::setName(const std::string& name)
void XdmfAttribute::write(boost::shared_ptr<XdmfVisitor> visitor) const
{
visitor->visit(this);
visitor->visit(this, visitor);
}
std::string XdmfAttribute::printSelf() const
......
......@@ -38,3 +38,8 @@ boost::shared_ptr<const XdmfArray> XdmfDataItem::getArray() const
{
return mArray;
}
void XdmfDataItem::traverse(boost::shared_ptr<XdmfVisitor> visitor) const
{
mArray->write(visitor);
}
......@@ -42,7 +42,7 @@ public:
std::string printSelf() const;
void write(boost::shared_ptr<XdmfVisitor> visitor) const = 0;
virtual void traverse(boost::shared_ptr<XdmfVisitor> visitor) const;
protected:
......
......@@ -6,6 +6,7 @@
*/
#include "XdmfDomain.hpp"
#include "XdmfGrid.hpp"
#include "XdmfVisitor.hpp"
XdmfDomain::XdmfDomain()
......@@ -53,7 +54,15 @@ std::string XdmfDomain::printSelf() const
return "XdmfDomain";
}
void XdmfDomain::traverse(boost::shared_ptr<XdmfVisitor> visitor) const
{
for(std::vector<boost::shared_ptr<XdmfGrid> >::const_iterator iter = mGrids.begin(); iter != mGrids.end(); ++iter)
{
(*iter)->write(visitor);
}
}
void XdmfDomain::write(boost::shared_ptr<XdmfVisitor> visitor) const
{
visitor->visit(this);
visitor->visit(this, visitor);
}
......@@ -45,6 +45,7 @@ public:
virtual std::string printSelf() const;
virtual void traverse(boost::shared_ptr<XdmfVisitor> visitor) const;
virtual void write(boost::shared_ptr<XdmfVisitor> visitor) const;
protected:
......
......@@ -47,5 +47,5 @@ std::string XdmfGeometry::printSelf() const
void XdmfGeometry::write(boost::shared_ptr<XdmfVisitor> visitor) const
{
visitor->visit(this);
visitor->visit(this, visitor);
}
......@@ -5,6 +5,7 @@
* Author: kleiter
*/
#include "XdmfAttribute.hpp"
#include "XdmfGrid.hpp"
#include "XdmfGeometry.hpp"
#include "XdmfTopology.hpp"
......@@ -108,7 +109,17 @@ std::string XdmfGrid::printSelf() const
return "XdmfGrid containing a " + mGeometry->printSelf() + " and a " + mTopology->printSelf();
}
void XdmfGrid::traverse(boost::shared_ptr<XdmfVisitor> visitor) const
{
mGeometry->write(visitor);
mTopology->write(visitor);
for(std::vector<boost::shared_ptr<XdmfAttribute> >::const_iterator iter = mAttributes.begin(); iter != mAttributes.end(); ++iter)
{
(*iter)->write(visitor);
}
}
void XdmfGrid::write(boost::shared_ptr<XdmfVisitor> visitor) const
{
visitor->visit(this);
visitor->visit(this, visitor);
}
......@@ -102,6 +102,8 @@ public:
virtual std::string printSelf() const;
virtual void traverse(boost::shared_ptr<XdmfVisitor> visitor) const;
virtual void write(boost::shared_ptr<XdmfVisitor> visitor) const;
protected:
......
#include "XdmfItem.hpp"
#include "XdmfVisitor.hpp"
XdmfItem::XdmfItem()
{
......@@ -8,3 +9,8 @@ XdmfItem::XdmfItem()
XdmfItem::~XdmfItem()
{
}
void XdmfItem::traverse(boost::shared_ptr<XdmfVisitor> visitor) const
{
return;
}
......@@ -18,7 +18,8 @@ class XdmfItem : public XdmfObject {
public:
virtual void write(boost::shared_ptr<XdmfVisitor>) const = 0;
virtual void traverse(boost::shared_ptr<XdmfVisitor> visitor) const;
virtual void write(boost::shared_ptr<XdmfVisitor> visitor) const = 0;
protected:
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -53,5 +53,5 @@ std::string XdmfTopology::printSelf() const
void XdmfTopology::write(boost::shared_ptr<XdmfVisitor> visitor) const
{
visitor->visit(this);
visitor->visit(this, visitor);
}
......@@ -31,7 +31,7 @@ XdmfVisitor::~XdmfVisitor()
std::cout << "Deleted Visitor " << this << std::endl;
}
void XdmfVisitor::visit(const XdmfAttribute * const attribute)
void XdmfVisitor::visit(const XdmfAttribute * const attribute, boost::shared_ptr<XdmfVisitor> visitor)
{
xmlNodePtr parentNode = xmlCurrentNode;
xmlCurrentNode = xmlNewChild(xmlCurrentNode, NULL, (xmlChar*)"Attribute", NULL);
......@@ -40,13 +40,13 @@ void XdmfVisitor::visit(const XdmfAttribute * const attribute)
xmlNewProp(xmlCurrentNode, (xmlChar*)"Center", (xmlChar*)attribute->getAttributeCenterAsString().c_str());
dataHierarchy.push_back(attribute->getName());
visit(attribute->getArray().get());
attribute->traverse(visitor);
dataHierarchy.pop_back();
xmlCurrentNode = parentNode;
}
void XdmfVisitor::visit(const XdmfArray * const array)
void XdmfVisitor::visit(const XdmfArray * const array, boost::shared_ptr<XdmfVisitor> visitor)
{
xmlNodePtr parentNode = xmlCurrentNode;
xmlCurrentNode = xmlNewChild(xmlCurrentNode, NULL, (xmlChar*)"DataItem", NULL);
......@@ -110,51 +110,43 @@ void XdmfVisitor::visit(const XdmfArray * const array)
xmlCurrentNode = parentNode;
}
void XdmfVisitor::visit(const XdmfDomain * const domain)
void XdmfVisitor::visit(const XdmfDomain * const domain, boost::shared_ptr<XdmfVisitor> visitor)
{
xmlNodePtr parentNode = xmlCurrentNode;
xmlCurrentNode = xmlNewChild(xmlCurrentNode, NULL, (xmlChar*)"Domain", NULL);
for(unsigned int i=0; i<domain->getNumberOfGrids(); ++i)
{
visit(domain->getGrid(i).get());
}
domain->traverse(visitor);
xmlCurrentNode = parentNode;
}
void XdmfVisitor::visit(const XdmfGeometry * const geometry)
void XdmfVisitor::visit(const XdmfGeometry * const geometry, boost::shared_ptr<XdmfVisitor> visitor)
{
xmlNodePtr parentNode = xmlCurrentNode;
xmlCurrentNode = xmlNewChild(xmlCurrentNode, NULL, (xmlChar*)"Geometry", NULL);
xmlNewProp(xmlCurrentNode, (xmlChar*)"GeometryType", (xmlChar*)geometry->getGeometryTypeAsString().c_str());
dataHierarchy.push_back("XYZ");
visit(geometry->getArray().get());
geometry->traverse(visitor);
dataHierarchy.pop_back();
xmlCurrentNode = parentNode;
}
void XdmfVisitor::visit(const XdmfGrid * const grid)
void XdmfVisitor::visit(const XdmfGrid * const grid, boost::shared_ptr<XdmfVisitor> visitor)
{
xmlNodePtr parentNode = xmlCurrentNode;
xmlCurrentNode = xmlNewChild(xmlCurrentNode, NULL, (xmlChar*)"Grid", NULL);
xmlNewProp(xmlCurrentNode, (xmlChar*)"Name", (xmlChar*)grid->getName().c_str());
dataHierarchy.push_back(grid->getName());
visit(grid->getGeometry().get());
visit(grid->getTopology().get());
for(unsigned int i=0; i<grid->getNumberOfAttributes(); ++i)
{
visit(grid->getAttribute(i).get());
}
grid->traverse(visitor);
dataHierarchy.pop_back();
xmlCurrentNode = parentNode;
}
void XdmfVisitor::visit(const XdmfTopology * const topology)
void XdmfVisitor::visit(const XdmfTopology * const topology, boost::shared_ptr<XdmfVisitor> visitor)
{
xmlNodePtr parentNode = xmlCurrentNode;
xmlCurrentNode = xmlNewChild(xmlCurrentNode, NULL, (xmlChar*)"Topology", NULL);
......@@ -164,7 +156,7 @@ void XdmfVisitor::visit(const XdmfTopology * const topology)
xmlNewProp(xmlCurrentNode, (xmlChar*)"NumberOfElements", (xmlChar*)numberElementsString.str().c_str());
dataHierarchy.push_back("Connectivity");
visit(topology->getArray().get());
topology->traverse(visitor);
dataHierarchy.pop_back();
xmlCurrentNode = parentNode;
......
......@@ -25,17 +25,17 @@ public:
XdmfNewMacro(XdmfVisitor);
virtual void visit(const XdmfArray * const array);
virtual void visit(const XdmfArray * const array, boost::shared_ptr<XdmfVisitor> visitor);
virtual void visit(const XdmfAttribute * const attribute);
virtual void visit(const XdmfAttribute * const attribute, boost::shared_ptr<XdmfVisitor> visitor);
virtual void visit(const XdmfDomain * const domain);
virtual void visit(const XdmfDomain * const domain, boost::shared_ptr<XdmfVisitor> visitor);
virtual void visit(const XdmfGeometry * const geometry);
virtual void visit(const XdmfGeometry * const geometry, boost::shared_ptr<XdmfVisitor> visitor);
virtual void visit(const XdmfGrid * const grid);
virtual void visit(const XdmfGrid * const grid, boost::shared_ptr<XdmfVisitor> visitor);
virtual void visit(const XdmfTopology * const topology);
virtual void visit(const XdmfTopology * const topology, boost::shared_ptr<XdmfVisitor> visitor);
virtual std::string printSelf() const;
......
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