athena/include/athena/VectorWriter.hpp
2018-08-24 22:38:23 -10:00

64 lines
1.9 KiB
C++

#ifndef VECTORWRITER_HPP
#define VECTORWRITER_HPP
#include <string>
#include <memory>
#include <functional>
#include <vector>
#include "athena/IStreamWriter.hpp"
namespace athena::io
{
/*! @class VectorWriter
* @brief A Stream class for writing data to a STL vector
*
* A Class for writing binary data to an STL vector,
* all work is done using a std::vector, and not written directly to the disk
* @sa Stream
*/
class VectorWriter : public IStreamWriter
{
public:
/*! @brief Sets the buffers position relative to the specified position.<br />
* It seeks relative to the current position by default.
* @param position where in the buffer to seek
* @param origin The Origin to seek @sa SeekOrigin
*/
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
/*! @brief Returns the current position in the stream.
*
* @return Int64 The current position in the stream.
*/
inline atUint64 position() const { return m_position; }
/*! @brief Returns the length of the stream.
*
* @return Int64 The length of the stream.
*/
inline atUint64 length() const { return m_data.size(); }
inline bool isOpen() const { return true; }
/*! @brief Obtains reference to underlying std::vector store */
const std::vector<uint8_t>& data() const { return m_data; }
/*! @brief Writes the given buffer with the specified length, buffers can be bigger than the length
* however it's undefined behavior to try and write a buffer which is smaller than the given length.
* If you are needing to fill in an area please use IStreamWriter::fill(atUint64) instead.
*
* @param data The buffer to write
* @param length The amount to write
*/
void writeUBytes(const atUint8* data, atUint64 len);
protected:
std::vector<uint8_t> m_data;
atUint64 m_position = 0;
};
}
#endif // VECTORWRITER_HPP