|
ug4
|
File writer allowing selective base64 encoding of arbitrary data. More...
#include <base64_file_writer.h>
Public Types | |
| enum | fmtflag { base64_ascii , base64_binary , normal } |
| Format flags to enable deactivation of base64 encoding selectivly. More... | |
Public Member Functions | |
| Base64FileWriter () | |
| Base64FileWriter (const char *filename, const std::ios_base::openmode mode=(std::ios_base::out|std::ios_base::trunc)) | |
| Constructor with name of file to write to. | |
| void | close () |
| Closes the file writer properly and encodes any remaining buffer content. | |
| fmtflag | format () const |
| gets the current set format | |
| void | open (const char *filename, const std::ios_base::openmode mode=std::ios_base::out) |
| Base64FileWriter & | operator<< (char c) |
| Base64FileWriter & | operator<< (const char *cstr) |
| Base64FileWriter & | operator<< (const fmtflag format) |
| Switch between normal and base64 encoded output. | |
| Base64FileWriter & | operator<< (const std::string &str) |
| Base64FileWriter & | operator<< (double d) |
| Base64FileWriter & | operator<< (float f) |
| Base64FileWriter & | operator<< (int i) |
| Base64FileWriter & | operator<< (long l) |
| Base64FileWriter & | operator<< (size_t s) |
| ~Base64FileWriter () | |
| Destructor, which properly flushs encoder's internal buffer and closes file stream. | |
Private Member Functions | |
| void | assertFileOpen () |
| Check on readiness of the file stream. | |
| template<typename T > | |
| void | dispatch (const T &value) |
| Writes given data to the output file and encodes it if Base64FileWriter::base64 is set. | |
| void | flushInputBuffer (bool force=false) |
| Flushes input buffer. | |
Private Attributes | |
| fmtflag | m_currFormat |
Current write format (base64 or normal) | |
| std::fstream | m_fStream |
| File stream to write everything to. | |
| std::stringstream | m_inBuffer |
| Internal input buffer for the encoder. | |
| size_t | m_lastInputByteSize |
| size_t | m_numBytesWritten |
| std::vector< char > | m_tmpBuff |
File writer allowing selective base64 encoding of arbitrary data.
This provides a convenient and well tested way of writing selectivly base64 encoded data to an arbitrary file.
After initialization with a file name
arbitrary data can be written to it solely using the <<-operator:
The default behaviour is to write base64 binary or ascii encoded data from the very beginning. This can be overridden by passing Base64FileWriter::normal as data to it:
Switching back to base64 encoding is simple as
To finish off writing, just close the writer: