XdmfWriter.hpp 3.14 KB
Newer Older
1 2 3 4 5
#ifndef XDMFWRITER_HPP_
#define XDMFWRITER_HPP_

// Forward Declarations
class XdmfArray;
6
class XdmfHDF5Writer;
7 8 9 10 11

// Includes
#include "XdmfVisitor.hpp"

/**
12
 * @brief Traverse the Xdmf graph and write light and heavy data stored to disk.
13 14
 *
 * XdmfWriter visits each node of an Xdmf graph structure and writes the data to disk.  Writing begins by calling the
15 16 17
 * accept() operation on any XdmfItem and supplying this writer as the parameter.  The XdmfItem as well as all children
 * attached to the XdmfItem are written to disk.  Heavy data is written to HDF5 format using the XdmfHDF5Writer and light
 * data is written to XML.
18 19
 */
class XdmfWriter : public XdmfVisitor,
20
	public Loki::Visitor<XdmfArray> {
21 22 23

public:

24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
	template <typename T> friend void boost::checked_delete(T * x);

	/**
	 * Create a new XdmfWriter to write Xdmf data to disk.  This will create its own hdf5 writer based on the xmlFileName.
	 * For example, if supplied "output.xmf" the created hdf5 writer would write to file "output.h5".
	 *
	 * @param xmlFilePath the path to the xml file to write to.
	 * @return the new XdmfWriter.
	 */
	static boost::shared_ptr<XdmfWriter> New(const std::string & xmlFilePath)
	{
		boost::shared_ptr<XdmfWriter> p(new XdmfWriter(xmlFilePath));
		return p;
	}

	/**
	 * Create a new XdmfWriter to write Xdmf data to disk.  This will utilize the supplied hdf5Writer to write any
	 * heavy data to disk.
	 *
	 * @param xmlFilePath the path to the xml file to write to.
	 * @param hdf5Writer the heavy data writer to use when writing.
	 * @return the new XdmfWriter.
	 */
	static boost::shared_ptr<XdmfWriter> New(const std::string & xmlFilePath, boost::shared_ptr<XdmfHDF5Writer> hdf5Writer)
	{
		boost::shared_ptr<XdmfWriter> p(new XdmfWriter(xmlFilePath, hdf5Writer));
		return p;
	}
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69

	/**
	 * Get the number of values that this writer writes to light data (XML) before switching to a heavy data format.
	 *
	 * @return an unsigned int containing the number of values.
	 */
	unsigned int getLightDataLimit() const;

	/**
	 * Set the number of values that this writer writes to light data (XML) before switching to a heavy data format.
	 *
	 * @param numValues an unsigned int containing the number of values.
	 */
	void setLightDataLimit(unsigned int numValues);

	/**
	 * Write an XdmfArray to disk
	 *
70 71
	 * @param array an XdmfArray to write to disk.
	 * @param visitor a smart pointer to this visitor --- aids in grid traversal.
72 73 74 75
	 */
	void visit(XdmfArray & array, boost::shared_ptr<Loki::BaseVisitor> visitor);

	/**
76
	 * Write an XdmfItem to disk
77
	 *
78 79
	 * @param item an XdmfItem to write to disk.
	 * @param visitor a smart pointer to this visitor --- aids in grid traversal.
80
	 */
81
	void visit(XdmfItem & item, boost::shared_ptr<Loki::BaseVisitor> visitor);
82

83

84 85
protected:

86 87
	XdmfWriter(const std::string & xmlFilePath);
	XdmfWriter(const std::string & xmlFilePath, boost::shared_ptr<XdmfHDF5Writer> hdf5Writer);
88 89 90 91
	virtual ~XdmfWriter();

private:

92 93 94 95 96
	/**
	 * PIMPL
	 */
	class XdmfWriterImpl;

97 98 99
	XdmfWriter(const XdmfWriter & writer);  // Not implemented.
	void operator=(const XdmfWriter & writer);  // Not implemented.

100 101 102
	void closeFile();
	void openFile();

103
	XdmfWriterImpl * mImpl;
104 105 106
};

#endif /* XDMFWRITER_HPP_ */