XdmfWriter.hpp 3.49 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
	virtual ~XdmfWriter();
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

	/**
	 * 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.
	 */
47
	static boost::shared_ptr<XdmfWriter> New(const std::string & xmlFilePath, const boost::shared_ptr<XdmfHDF5Writer> hdf5Writer)
48 49 50 51
	{
		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
	/**
	 * Get the hdf5 writer that this XdmfWriter uses to write heavy data to disk.
	 *
	 * @return the requested hdf5 writer.
	 */
	boost::shared_ptr<XdmfHDF5Writer> getHDF5Writer();

	/**
	 * Get the hdf5 writer that this XdmfWriter uses to write heavy data to disk (const version).
	 *
	 * @return the requested hdf5 writer.
	 */
	boost::shared_ptr<const XdmfHDF5Writer> getHDF5Writer() const;

67 68 69 70 71 72 73 74 75 76 77 78
	/**
	 * 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.
	 */
79
	void setLightDataLimit(const unsigned int numValues);
80 81 82 83

	/**
	 * Write an XdmfArray to disk
	 *
84 85
	 * @param array an XdmfArray to write to disk.
	 * @param visitor a smart pointer to this visitor --- aids in grid traversal.
86
	 */
87
	void visit(XdmfArray & array, const boost::shared_ptr<XdmfBaseVisitor> visitor);
88 89

	/**
90
	 * Write an XdmfItem to disk
91
	 *
92 93
	 * @param item an XdmfItem to write to disk.
	 * @param visitor a smart pointer to this visitor --- aids in grid traversal.
94
	 */
95
	void visit(XdmfItem & item, const boost::shared_ptr<XdmfBaseVisitor> visitor);
96

97

98 99
protected:

100 101
	XdmfWriter(const std::string & xmlFilePath);
	XdmfWriter(const std::string & xmlFilePath, boost::shared_ptr<XdmfHDF5Writer> hdf5Writer);
102 103 104

private:

105 106 107 108 109
	/**
	 * PIMPL
	 */
	class XdmfWriterImpl;

110 111 112
	XdmfWriter(const XdmfWriter & writer);  // Not implemented.
	void operator=(const XdmfWriter & writer);  // Not implemented.

113 114 115
	void closeFile();
	void openFile();

116
	XdmfWriterImpl * mImpl;
117 118 119
};

#endif /* XDMFWRITER_HPP_ */