// LabRatDoc.h : interface of the CLabRatDoc class
//
/////////////////////////////////////////////////////////////////////////////


#if !defined (LABRATDOC_HPP)
#	define LABRATDOC_HPP

class CObarrayHolder;
class CLabRatDoc;


#include "LoadingLogDlg.h"
#include "storage.hpp"
#include "traceline.hpp"



extern Logical BigEndian;


class CObjString : public CObject
{
	

public:
	CString name;

	CObjString(char *value)
	{
		name = value;
		CObject::CObject();
	}
	~CObjString(void)
	{
		CObject::~CObject();
	}
};

class ClassIDList : public CObject 
{
public:

	CString entityName;
	int messageCount;
	int classID;
	CObArray *messageList;

};



class CObarrayHolder : public CObject 
{
public:

	//
	// Each one has it's own heap for the data storage
	//

	DWORD size;

	TraceStorage *data;
	CString name;
	int traceType;
	int traceEntryCount;
	CObarrayHolder();
	~CObarrayHolder();
};

class CLabRatDoc : public CDocument
{
protected: // create from serialization only
	CLabRatDoc();
	DECLARE_DYNCREATE(CLabRatDoc)

// Attributes
public:
	int traceCount;
	CObArray	*dataArray;
	CObList	*classIDList;
	Time firstTrace;
	Time lastTrace;
	BOOL stillLoading;

	long sampleSize;

	Logical failedOpen;


	

public:
	enum {
				GoingUpFlag=			0,
				GoingDownFlag=			1,
				MarkerFlag=				2,
				IntegerSnapShotFlag=	3,
				ScalarSnapShotFlag=	4,
				Suspend=					5,
				Resume=					6,
				Queing=					7,
				Dispatching=         8
			};

		enum {
				LogicalTraceType = 0,
				IntegerTraceType = 1,
				ScalarTraceType =  2,
				ReceiverMessageTraceType= 3,
				MarkerTraceType,
				DefaultTraceType
			};

// Operations
public:
	void LoadResource(CArchive& ar, CLoadingLogDlg *dialog_box);
	void LoadOldResource(CArchive& ar, CLoadingLogDlg *dialog_box, int file_start = 0);
	void LoadOnePointZeroResource(CArchive& ar, CLoadingLogDlg *dialog_box);
	void LoadTwoPointZeroResource(CArchive& ar, CLoadingLogDlg *dialog_box);

	void LoadOnePointZeroResourceBackward(CArchive& ar, CLoadingLogDlg *dialog_box);
	void LoadTwoPointZeroResourceBackward(CArchive& ar, CLoadingLogDlg *dialog_box);
	
	void LoadHeader(CArchive& ar, LONG position, CLoadingLogDlg *dialog_box);
	void LoadTracesOne(CArchive& ar, LONG position, CLoadingLogDlg *dialog_box);
	void LoadTracesTwo(CArchive& ar, LONG position, CLoadingLogDlg *dialog_box);
	void LoadMessages(CArchive& ar, LONG position, CLoadingLogDlg *dialog_box, LONG message_size);


	void LoadTracesTwo8Byte(CArchive& ar, LONG position, CLoadingLogDlg *dialog_box);


	ClassIDList * FindClass(int id);

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CLabRatDoc)
	public:
	virtual BOOL OnNewDocument();
	virtual void Serialize(CArchive& ar);
	virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);
	virtual void DeleteContents();
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CLabRatDoc();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
	//{{AFX_MSG(CLabRatDoc)
		// NOTE - the ClassWizard will add and remove member functions here.
		//    DO NOT EDIT what you see in these blocks of generated code !
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};


#define SKIPPY_CAST(Type,var)	(*((Type*)&(var)))

void BigEndianConvert(LONG &value);
void BigEndianConvert(WORD &value);
void BigEndianConvert(DWORD &value);
void BigEndianConvert(int &value);
void BigEndianConvert(float &value);
void BigEndianConvert(BYTE &value);

/////////////////////////////////////////////////////////////////////////////
#endif