![]() |
Vault
4.1
|
This class simplifies using the VFSNode::safelyOverwriteFile() API, by relieving you of the need to manually create a temporary buffer stream, etc. More...
#include <vfilewriter.h>
Public Member Functions | |
| VFileWriter (const VFSNode &target) | |
| Creates the helper objects, pointing to a specific file node. | |
| VTextIOStream & | getTextOutputStream () |
| VBinaryIOStream & | getBinaryOutputStream () |
| void | save () |
This class simplifies using the VFSNode::safelyOverwriteFile() API, by relieving you of the need to manually create a temporary buffer stream, etc.
You just instantiate the VFileWriter with the target file node, then write to either a text or binary stream obtained by one of the getter APIs, and finally 'save' the data. The reason for the explicit save call is so that nothing is written if an exception is thrown during your serialization, unless you want to catch it and still write whatever data you did put in the output stream (perhaps after first manipulating the stream further). Normally you want such exceptions to propagate up and avoid writing entirely.
This initial version always does your writes to a VMemoryStream and then uses that with the VFSNode::safelyOverwriteFile() API. It would be good to enhance this with an option (or default behavior) that actually writes to a temporary file directly, and then swaps it the way that VFSNode::safelyOverwriteFile() does with the buffered data.
So it can look like this,if you had text data for example:
void Thing::saveMyData() { VFileWriter writer(mMyFileNode); mMyData.writeToTextStream(writer.getTextOutputStream()); writer.save(); }
Definition at line 41 of file vfilewriter.h.
| VFileWriter::VFileWriter | ( | const VFSNode & | target | ) |
Creates the helper objects, pointing to a specific file node.
| target | the file node that will be written to |
Definition at line 13 of file vfilewriter.cpp.