Commit b1ff8b8a authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Rename write() operation to accept() which is more consistent for the...

ENH: Rename write() operation to accept() which is more consistent for the Visitor pattern.  Also, we can
do much more to our Xdmf graph structure than just write it using Visitor operations.
parent b5b2127d
......@@ -421,6 +421,11 @@ XdmfArray::~XdmfArray()
std::cout << "Deleted Array " << this << std::endl;
}
void XdmfArray::accept(boost::shared_ptr<XdmfVisitor> visitor) const
{
visitor->visit(this, visitor);
}
void XdmfArray::copyValues(const unsigned int startIndex, const boost::shared_ptr<const XdmfArray> values, const unsigned int valuesStartIndex, const unsigned int numValues, const unsigned int arrayStride, const unsigned int valuesStride)
{
if(mHaveArrayPointer)
......@@ -560,6 +565,12 @@ void XdmfArray::releaseArrayPointer()
mHaveArrayPointer = false;
}
void XdmfArray::releaseData()
{
releaseArray();
releaseArrayPointer();
}
void XdmfArray::reserve(const unsigned int size)
{
if(mHaveArrayPointer)
......@@ -596,8 +607,3 @@ void XdmfArray::swap(boost::shared_ptr<XdmfArray> array)
mHaveArray = tmpHaveArray;
mHaveArrayPointer = tmpHaveArrayPointer;
}
void XdmfArray::write(boost::shared_ptr<XdmfVisitor> visitor) const
{
visitor->visit(this, visitor);
}
......@@ -48,6 +48,11 @@ public:
XdmfNewMacro(XdmfArray);
/**
*
*/
virtual void accept(boost::shared_ptr<XdmfVisitor>) const;
/**
* Copy values from an XdmfArray into this array.
*
......@@ -156,11 +161,7 @@ public:
/**
* Release all data held by this XdmfArray.
*/
void releaseData()
{
releaseArray();
releaseArrayPointer();
}
void releaseData();
/**
* Set the capacity of the XdmfArray to at least size.
......@@ -240,11 +241,6 @@ public:
*/
void swap(boost::shared_ptr<XdmfArray> array);
/**
*
*/
virtual void write(boost::shared_ptr<XdmfVisitor>) const;
protected:
XdmfArray();
......
......@@ -21,6 +21,11 @@ XdmfAttribute::~XdmfAttribute()
std::cout << "Deleted Attribute " << this << std::endl;
}
void XdmfAttribute::accept(boost::shared_ptr<XdmfVisitor> visitor) const
{
visitor->visit(this, visitor);
}
XdmfAttributeCenter XdmfAttribute::getAttributeCenter() const
{
return mAttributeCenter;
......@@ -55,8 +60,3 @@ void XdmfAttribute::setName(const std::string & name)
{
mName= name;
}
void XdmfAttribute::write(boost::shared_ptr<XdmfVisitor> visitor) const
{
visitor->visit(this, visitor);
}
......@@ -18,6 +18,8 @@ public:
XdmfNewMacro(XdmfAttribute);
void accept(boost::shared_ptr<XdmfVisitor> visitor) const;
/**
* Get the XdmfAttributeCenter associated with this attribute.
*
......@@ -62,8 +64,6 @@ public:
*/
void setName(const std::string & name);
void write(boost::shared_ptr<XdmfVisitor> visitor) const;
protected:
XdmfAttribute();
......
......@@ -41,5 +41,5 @@ void XdmfDataItem::setArray(boost::shared_ptr<XdmfArray> array)
void XdmfDataItem::traverse(boost::shared_ptr<XdmfVisitor> visitor) const
{
mArray->write(visitor);
mArray->accept(visitor);
}
......@@ -41,7 +41,6 @@ public:
void setArray(boost::shared_ptr<XdmfArray> array);
virtual void traverse(boost::shared_ptr<XdmfVisitor> visitor) const;
virtual void write(boost::shared_ptr<XdmfVisitor> visitor) const = 0;
protected:
......
......@@ -19,6 +19,11 @@ XdmfDomain::~XdmfDomain()
std::cout << "Deleted Domain " << this << std::endl;
}
void XdmfDomain::accept(boost::shared_ptr<XdmfVisitor> visitor) const
{
visitor->visit(this, visitor);
}
void XdmfDomain::insert(boost::shared_ptr<XdmfGrid> grid)
{
mGrids.push_back(grid);
......@@ -58,11 +63,6 @@ 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);
(*iter)->accept(visitor);
}
}
void XdmfDomain::write(boost::shared_ptr<XdmfVisitor> visitor) const
{
visitor->visit(this, visitor);
}
......@@ -20,6 +20,8 @@ public:
XdmfNewMacro(XdmfDomain);
virtual void accept(boost::shared_ptr<XdmfVisitor> visitor) const;
/**
* Get a XdmfGrid attached to the domain.
*
......@@ -53,7 +55,6 @@ 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:
......
......@@ -20,12 +20,16 @@ XdmfGeometry::~XdmfGeometry()
std::cout << "Deleted Geometry " << this << std::endl;
}
void XdmfGeometry::accept(boost::shared_ptr<XdmfVisitor> visitor) const
{
visitor->visit(this, visitor);
}
XdmfGeometryType XdmfGeometry::getGeometryType() const
{
return mGeometryType;
}
std::string XdmfGeometry::printSelf() const
{
return "XdmfGeometry";
......@@ -35,8 +39,3 @@ void XdmfGeometry::setGeometryType(const XdmfGeometryType & geometryType)
{
mGeometryType = geometryType;
}
void XdmfGeometry::write(boost::shared_ptr<XdmfVisitor> visitor) const
{
visitor->visit(this, visitor);
}
......@@ -18,6 +18,8 @@ public:
XdmfNewMacro(XdmfGeometry);
virtual void accept(boost::shared_ptr<XdmfVisitor> visitor) const;
/**
* Get the XdmfGeometryType associated with this geometry.
*
......@@ -34,8 +36,6 @@ public:
virtual std::string printSelf() const;
virtual void write(boost::shared_ptr<XdmfVisitor> visitor) const;
protected:
XdmfGeometry();
......
......@@ -25,6 +25,11 @@ XdmfGrid::~XdmfGrid()
std::cout << "Deleted Grid " << this << std::endl;
}
void XdmfGrid::accept(boost::shared_ptr<XdmfVisitor> visitor) const
{
visitor->visit(this, visitor);
}
boost::shared_ptr<XdmfAttribute> XdmfGrid::getAttribute(unsigned int index)
{
if(index >= mAttributes.size())
......@@ -60,7 +65,6 @@ std::string XdmfGrid::getName() const
return mName;
}
unsigned int XdmfGrid::getNumberOfAttributes() const
{
return mAttributes.size();
......@@ -76,7 +80,6 @@ boost::shared_ptr<const XdmfTopology> XdmfGrid::getTopology() const
return mTopology;
}
void XdmfGrid::insert(boost::shared_ptr<XdmfAttribute> attribute)
{
mAttributes.push_back(attribute);
......@@ -104,15 +107,10 @@ void XdmfGrid::setTopology(boost::shared_ptr<XdmfTopology> topology)
void XdmfGrid::traverse(boost::shared_ptr<XdmfVisitor> visitor) const
{
mGeometry->write(visitor);
mTopology->write(visitor);
mGeometry->accept(visitor);
mTopology->accept(visitor);
for(std::vector<boost::shared_ptr<XdmfAttribute> >::const_iterator iter = mAttributes.begin(); iter != mAttributes.end(); ++iter)
{
(*iter)->write(visitor);
(*iter)->accept(visitor);
}
}
void XdmfGrid::write(boost::shared_ptr<XdmfVisitor> visitor) const
{
visitor->visit(this, visitor);
}
......@@ -23,6 +23,8 @@ public:
XdmfNewMacro(XdmfGrid);
virtual void accept(boost::shared_ptr<XdmfVisitor> visitor) const;
/**
* Get an XdmfAttribute attached to this grid.
*
......@@ -113,8 +115,6 @@ public:
virtual void traverse(boost::shared_ptr<XdmfVisitor> visitor) const;
virtual void write(boost::shared_ptr<XdmfVisitor> visitor) const;
protected:
XdmfGrid();
......
......@@ -25,8 +25,8 @@ class XdmfItem : public XdmfObject {
public:
virtual void accept(boost::shared_ptr<XdmfVisitor> visitor) const = 0;
virtual void traverse(boost::shared_ptr<XdmfVisitor> visitor) const;
virtual void write(boost::shared_ptr<XdmfVisitor> visitor) const = 0;
protected:
......
......@@ -21,6 +21,11 @@ XdmfTopology::~XdmfTopology()
std::cout << "Deleted Topology " << this << std::endl;
}
void XdmfTopology::accept(boost::shared_ptr<XdmfVisitor> visitor) const
{
visitor->visit(this, visitor);
}
unsigned int XdmfTopology::getNumberElements() const
{
return this->getArray()->getSize() / this->getTopologyType().getNodesPerElement();
......@@ -40,8 +45,3 @@ void XdmfTopology::setTopologyType(const XdmfTopologyType & topologyType)
{
mTopologyType = topologyType;
}
void XdmfTopology::write(boost::shared_ptr<XdmfVisitor> visitor) const
{
visitor->visit(this, visitor);
}
......@@ -18,6 +18,8 @@ public:
XdmfNewMacro(XdmfTopology);
virtual void accept(boost::shared_ptr<XdmfVisitor> visitor) const;
/**
* Get the number of elements this Topology contains.
*
......@@ -41,8 +43,6 @@ public:
*/
void setTopologyType(const XdmfTopologyType & topologyType);
virtual void write(boost::shared_ptr<XdmfVisitor> visitor) const;
protected:
XdmfTopology();
......
......@@ -11,7 +11,7 @@ int main(int argc, char* argv[])
boost::shared_ptr<XdmfDomain> domain = XdmfDomain::New();
domain->insert(grid);
domain->write(visitor);
domain->accept(visitor);
std::cout << visitor->printSelf() << std::endl;
......
......@@ -39,7 +39,7 @@ int main(int argc, char* argv[])
boost::shared_ptr<XdmfVisitorValueCounter> visitor = XdmfVisitorValueCounter::New();
boost::shared_ptr<XdmfGrid> grid = XdmfTestDataGenerator::createHexahedron();
grid->write(visitor);
grid->accept(visitor);
assert(visitor->getCount() == 66);
......
......@@ -36,4 +36,4 @@ if __name__ == "__main__":
domain = XdmfDomain.New()
domain.insert(grid)
domain.write(visitor)
domain.accept(visitor)
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