/*
	ZBinaryBufferWriter.hpp
	Author: Patrick Baggett <ptbaggett@762studios.com>
	Created: 6/05/2013

	Purpose: 

	Writes a binary stream to memory

	License:

	TODO

*/

#pragma once

#ifndef _ZBINARYBUFFERWRITER_HPP
#define _ZBINARYBUFFERWRITER_HPP

#include <ZUtil/ZBinaryWriter.hpp>

class ZBinaryBufferWriter : public ZBinaryWriter
{
	public:
		ZBinaryBufferWriter(void* data,  size_t _size, SST_ByteOrder bo) :
		ZBinaryWriter(bo), Data((uint8_t*)data), Size(_size), Offset(0)
		{

		}

		//Subclass implementation
		void WriteU8(uint8_t v);

		//Subclass implementation
		void WriteU16(uint16_t v);

		//Subclass implementation
		void WriteU32(uint32_t v);

		//Subclass implementation
		void WriteU64(uint64_t v);

		//Subclass implementation
		void WriteU8Array(const uint8_t* v, size_t count);

		//Subclass implementation
		void WriteU16Array(const uint16_t* v, size_t count);

		//Subclass implementation
		void WriteU32Array(const uint32_t* v, size_t count);

		//Subclass implementation
		void WriteU64Array(const uint64_t* v, size_t count);

		//Subclass implementation
		size_t GetOffset() const { return Offset; }

		//Subclass implementation
		void SeekTo(size_t offset) { Offset = offset; }

		//Specific to ZBinaryBufferWriter, returns next write address
		const void* GetBufferWriteAddress() const { return &Data[Offset]; }

		//Specific to ZBinaryBufferWriter, returns base address
		void* GetBufferBaseAddress() const { return Data; }

		//Specific to ZBinaryBufferWriter, writes a pointer
		void WritePointer(void* pointer);

	private:
		uint8_t* Data;
		size_t Size;	//TODO: no safe ops ?
		size_t Offset;
};

#endif

