Commit 6f12cfa6 authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Add write() method to XdmfItem and implement in subclasses. The write()...

ENH: Add write() method to XdmfItem and implement in subclasses.  The write() method calls the visitor on the current object which performs some predetermined acivity (writing to heavy data, writing to light data, parallel output, etc.
parent c4c3800f
......@@ -29,6 +29,11 @@ XdmfGeometry::~XdmfGeometry()
std::cout << "Deleted Geometry " << this << std::endl;
}
void XdmfGeometry::write(boost::shared_ptr<XdmfVisitor>) const
{
}
const XdmfGeometryType& XdmfGeometry::getGeometryType() const
{
return *mGeometryType;
......
......@@ -76,6 +76,8 @@ public:
XdmfNewMacro(XdmfGeometry);
virtual void write(boost::shared_ptr<XdmfVisitor>) const;
/**
* Get the XdmfGeometryType associated with this Geometry.
*
......
......@@ -21,6 +21,11 @@ XdmfGrid::~XdmfGrid()
std::cout << "Deleted Grid " << this << std::endl;
}
void XdmfGrid::write(boost::shared_ptr<XdmfVisitor>) const
{
}
const std::string XdmfGrid::printSelf() const
{
return "XdmfGrid containing a " + mGeometry->printSelf() + " and a " + mTopology->printSelf();
......
......@@ -20,6 +20,8 @@ public:
XdmfNewMacro(XdmfGrid);
virtual void write(boost::shared_ptr<XdmfVisitor>) const;
// Get the XdmfGeometry for this grid
XdmfGetValueMacro(Geometry, boost::shared_ptr<XdmfGeometry>);
// Set the XdmfGeometry for this grid
......
......@@ -19,7 +19,7 @@ class XdmfItem : public XdmfObject {
public:
//virtual const std::string printSelf() const = 0;
//virtual void write(XdmfVisitor&) const = 0;
virtual void write(boost::shared_ptr<XdmfVisitor>) const = 0;
protected:
......
......@@ -6,6 +6,7 @@
*/
#include "XdmfTopology.hpp"
#include "XdmfVisitor.hpp"
const XdmfTopologyType XdmfTopologyType::NoTopology(0, "NoTopology", NoCellType);
const XdmfTopologyType XdmfTopologyType::Polyvertex(1, "Polyvertex", Linear);
......@@ -43,6 +44,11 @@ XdmfTopology::~XdmfTopology()
std::cout << "Deleted Topology " << this << std::endl;
}
void XdmfTopology::write(boost::shared_ptr<XdmfVisitor> visitor) const
{
visitor->visit(this);
}
const XdmfTopologyType & XdmfTopology::getTopologyType() const
{
return *mTopologyType;
......
......@@ -98,6 +98,8 @@ public:
XdmfNewMacro(XdmfTopology);
virtual void write(boost::shared_ptr<XdmfVisitor>) const;
/**
* Get the XdmfTopologyType associated with this Topology.
*
......
// Kenneth Leiter
// Xdmf Smart Pointer Test
#include "XdmfItem.hpp"
#include "XdmfVisitor.hpp"
XdmfVisitor::XdmfVisitor()
......@@ -11,7 +12,12 @@ XdmfVisitor::~XdmfVisitor()
{
}
void XdmfVisitor::visit(const XdmfItem * const item)
{
xmlData << item->printSelf();
}
const std::string XdmfVisitor::printSelf() const
{
return "XdmfVisitor";
return "XdmfVisitor:\n\tContents: " + xmlData.str();
}
......@@ -5,17 +5,19 @@
#define XDMFVISITOR_HPP_
// Forward Declarations
class XdmfItem;
// Includes
#include <sstream>
#include "XdmfObject.hpp"
class XdmfVisitor : public XdmfObject {
public:
XdmfNewMacro(XdmfVisitor);
//virtual void visit(boost::shared_ptr<XdmfItem>);
virtual void visit(const XdmfItem * const);
const std::string printSelf() const;
......@@ -26,6 +28,8 @@ protected:
private:
std::stringstream xmlData;
XdmfVisitor(const XdmfVisitor&); // Not implemented.
void operator=(const XdmfVisitor&); // Not implemented.
......
add_executable(TestXdmfTopology TestXdmfTopology)
target_link_libraries(TestXdmfTopology Xdmf)
set(XdmfTests
TestXdmfGeometry
TestXdmfTopology
TestXdmfVisitor
)
add_executable(TestXdmfGeometry TestXdmfGeometry)
target_link_libraries(TestXdmfGeometry Xdmf)
\ No newline at end of file
foreach(test ${XdmfTests})
add_executable(${test} ${test})
target_link_libraries(${test} Xdmf)
endforeach(test XdmfTests)
\ No newline at end of file
#include "XdmfTopology.hpp"
#include "XdmfVisitor.hpp"
int main(int argc, char* argv[])
{
// Test != and == operators
boost::shared_ptr<XdmfVisitor> visitor = XdmfVisitor::New();
boost::shared_ptr<XdmfTopology> top = XdmfTopology::New();
top->write(visitor);
std::cout << visitor->printSelf() << std::endl;
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