#pragma warning (disable : 4786)
#include "stdafx.h"
#include "data.hpp"
#include <cstdio>
#include <vector>

using namespace std;
	
CDataEntry::CDataEntry (int runnumber,int version,int type,double time)
{
	m_RunNumber = runnumber;
	m_DataType = type;
	m_Version = version;
	m_Time = time;
	m_ObjectID = 0;
	m_PosX = 0;
	m_PosY = 0;
	m_PosZ = 0;
	m_Int1 = 0;
	m_Int2 = 0;
	m_Int3 = 0;
	m_Int4 = 0;
	m_Float1 = 0;
	m_Float2 = 0;
	m_Float3 = 0;
	m_Float4 = 0;
	m_String = NULL;
}

CDataEntry::CDataEntry (int run,int version,int type,double time,int objid,float posx,float posy,float posz,int int1,int int2,int int3,int int4,float float1,float float2,float float3,float float4,const char *str)
{
	m_RunNumber = run;
	m_DataType = type;
	m_Version = version;
	m_Time = time;
	m_ObjectID = objid;
	m_PosX = posx;
	m_PosY = posy;
	m_PosZ = posz;
	m_Int1 = int1;
	m_Int2 = int2;
	m_Int3 = int3;
	m_Int4 = int4;
	m_Float1 = float1;
	m_Float2 = float2;
	m_Float3 = float3;
	m_Float4 = float4;
	m_String = NULL;
	if (str)
	{
		m_String = new char[strlen (str)+1];
		strcpy (m_String,str);
	}
}

CDataEntry::CDataEntry (const CDataEntry& p1)
{
	m_RunNumber 		= p1.m_RunNumber;
	m_DataType 			= p1.m_DataType;
	m_Version 			= p1.m_Version;
	m_Time					= p1.m_Time;
	m_ObjectID 			= p1.m_ObjectID;
	m_PosX 					= p1.m_PosX;
	m_PosY 					= p1.m_PosY;
	m_PosZ          = p1.m_PosZ;
	m_Int1          = p1.m_Int1;
	m_Int2          = p1.m_Int2;
	m_Int3          = p1.m_Int3;
	m_Int4				 	= p1.m_Int4;
	m_Float1 				= p1.m_Float1;
	m_Float2 				= p1.m_Float2;
	m_Float3 				= p1.m_Float3;
	m_Float4 				= p1.m_Float4;
	if (p1.m_String)
	{
		m_String = new char[strlen(p1.m_String)+1];
		strcpy (m_String,p1.m_String);
	}
	else
		m_String = NULL;
}

CDataEntry::~CDataEntry (void)
{
	delete[] m_String;
}

CDataEntry &CDataEntry::operator= (const CDataEntry &p1)
{
	delete[] m_String;

	m_RunNumber 		= p1.m_RunNumber;
	m_DataType 			= p1.m_DataType;
	m_Version 			= p1.m_Version;
	m_Time					= p1.m_Time;
	m_ObjectID 			= p1.m_ObjectID;
	m_PosX 					= p1.m_PosX;
	m_PosY 					= p1.m_PosY;
	m_PosZ          = p1.m_PosZ;
	m_Int1          = p1.m_Int1;
	m_Int2          = p1.m_Int2;
	m_Int3          = p1.m_Int3;
	m_Int4				 	= p1.m_Int4;
	m_Float1 				= p1.m_Float1;
	m_Float2 				= p1.m_Float2;
	m_Float3 				= p1.m_Float3;
	m_Float4 				= p1.m_Float4;
	if (p1.m_String)
	{
		m_String = new char[strlen(p1.m_String)+1];
		strcpy (m_String,p1.m_String);
	}
	else
		m_String = NULL;
	return *this;
}

bool CDataEntry::DumpData (HANDLE file) const
{
	char *string;
	DWORD written;
	if (m_String)
		string = new char[strlen (m_String) + 128];
	else
		string = new char[128];

	sprintf (string,"%d,%d,%d,%f,%d,%f,%f,%f,%d,%d,%d,%d,%f,%f,%f,%f,\"%s\"\n",	m_RunNumber,m_DataType,m_Version,m_Time,m_ObjectID,
								m_PosX,m_PosY,m_PosZ,m_Int1,m_Int2,m_Int3,m_Int4,m_Float1,m_Float2,m_Float3,m_Float4,m_String);

	WriteFile (file,string,strlen (string),&written,NULL);
	delete[] string;
	if (written != strlen (string))
		return false;
	return true;
}


