//Serializer.h

#include "Vector.h"
#include "Scene.h"

#pragma once

#define XML 1
#define BIN 2

class ISerializer
{
public:
	FILE * f;
	bool bSave;
	int ID; // 1 for XML, 2 for Binary format

	CString FileName;

	ISerializer();
	~ISerializer();

	void Init();
	void Destroy();

	virtual bool StartSerialize(char * FileName, bool bSave) = 0;

	virtual void SerializeString(char * Value, char * Name = "String") = 0;
	virtual void SerializeBool(bool &Value, char * Name = "Bool") = 0;
	virtual void SerializeInt(int &Value, char * Name = "Int") = 0;
	virtual void SerializeFloat(float &Value, char * Name = "Float") = 0;
	virtual void SerializeVector(CVector3 &Value, char * Name = "Vector") = 0;
	void SerializeCamera(CCamera &Camera, char * Name = "Camera");
	void SerializeMaterial(CMaterial &Material, char * Name = "Material");
	void SerializeFlat(CFlat &Flat, char * Name = "Flat");
	void SerializeSphere(CSphere &Sphere, char *Name = "Sphere");
	void SerializeLight(CLight &Light, char *Name = "Light");

	virtual void EndSerialize() = 0;
};

class CXMLSerializer : public ISerializer
{
public:
	CXMLSerializer();
	~CXMLSerializer();

	virtual bool StartSerialize(char * FileName, bool bSave);

	virtual void SerializeString(char * Value, char * Name = "String");
	virtual void SerializeBool(bool &Value, char * Name = "Bool");
	virtual void SerializeInt(int &Value, char * Name = "Int");
	virtual void SerializeFloat(float &Value, char * Name = "Float");
	virtual void SerializeVector(CVector3 &Value, char * Name = "Vector");

	virtual void EndSerialize();
};

class CBinSerializer : public ISerializer
{
public:
	CBinSerializer();
	~CBinSerializer();

	virtual bool StartSerialize(char * FileName, bool bSave);

	virtual void SerializeString(char * Value, char * Name = "String");
	virtual void SerializeBool(bool &Value, char * Name = "Bool");
	virtual void SerializeInt(int &Value, char * Name = "Int");
	virtual void SerializeFloat(float &Value, char * Name = "Float");
	virtual void SerializeVector(CVector3 &Value, char * Name = "Vector");

	virtual void EndSerialize();
};
