111 lines
2.5 KiB
C++
111 lines
2.5 KiB
C++
/*
|
|
ZXMLWriter.hpp
|
|
Author: James Russell <jcrussell@762studios.com>
|
|
Created: 5/13/2012
|
|
|
|
Purpose:
|
|
|
|
Interprets a ZKVTree as XML, writing the node structure and values into XML elements. Acts as
|
|
an inverse of ZXMLReader (see header for details on format).
|
|
|
|
Note that the same ambiguity is present for elements with no attributes and body data - they will
|
|
be written out as attributes. For example, consider the following ZKVTree structure:
|
|
|
|
Root
|
|
|
|
|
+-> node (This is a particle emitter node.)
|
|
| |
|
|
| +-> type (emitter)
|
|
| |
|
|
| +-> position ()
|
|
| | |
|
|
| | +-> x (100)
|
|
| | +-> y (100)
|
|
| | +-> z (1)
|
|
| |
|
|
| +-> facing ()
|
|
| | |
|
|
| | +-> x (0)
|
|
| | +-> y (0)
|
|
| | +-> z (1)
|
|
| |
|
|
| +-> flags (1)
|
|
|
|
|
+-> node
|
|
|
|
|
+-> type (time)
|
|
+-> value (2200)
|
|
|
|
The above will be written out as follows:
|
|
|
|
<node type="emitter" flags="1">
|
|
<position x="100" y="100" z="1" />
|
|
<facing x="0" y="0" z="1" />
|
|
This is a particle emitter node.
|
|
</node>
|
|
<node type="time" value="2200" />
|
|
|
|
Notice that the ambiguous case described in ZXMLReader.hpp for an attribute of an XML
|
|
element and the body of an attribute-free element will always be written out as an
|
|
attribute.
|
|
|
|
The body of 'node' is not ambiguous because the 'node' element has attributes and child
|
|
elements.
|
|
|
|
License:
|
|
|
|
TODO
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#ifndef _ZXMLWRITER_HPP
|
|
#define _ZXMLWRITER_HPP
|
|
|
|
#include <ZUtil/ZKVTree.hpp>
|
|
|
|
class ZXMLWriter
|
|
{
|
|
private:
|
|
DISABLE_COPY_AND_ASSIGN(ZXMLWriter);
|
|
|
|
//Error message (if an error has happened)
|
|
ZString ErrorMessage;
|
|
|
|
// recursive functions for writing XML
|
|
bool writeAttributes(ZString& _output, const ZKVTree::Iterator& _itr);
|
|
bool writeElements(ZString& _output, bool _useNewlines, const ZKVTree::Iterator& _itr);
|
|
|
|
public:
|
|
/*
|
|
Default Constructor.
|
|
*/
|
|
ZXMLWriter() { }
|
|
|
|
/*
|
|
public ZXMLWriter::GetErrorString
|
|
|
|
Gets the error message generated while writing the data if writing failed. If writing
|
|
the data was successful, this returns an empty string.
|
|
|
|
@return (const ZString&)
|
|
*/
|
|
const ZString& GetErrorString();
|
|
|
|
/*
|
|
public ZXMLWriter::Write
|
|
|
|
Writes the data from the registry into the provided output string in XML format.
|
|
|
|
@param _input - the KVTree we wish to represent as XML
|
|
@param _output - the string to write the data into (the data is appended)
|
|
@param _useNewlines - indicates whether or not we should use newlines in the output
|
|
@return (bool) - true if successful, false otherwise
|
|
*/
|
|
bool Write(const ZKVTree& _input, ZString& _output, bool _useNewlines);
|
|
};
|
|
|
|
#endif
|
|
|