#pragma once
#include <QString>
#include <QByteArray>

#define IGNORE_ALL_FF_RECORDS
#define HEX_RECORD_HEADER (int)0xDEADBEEF
class CHexRecord
{
public:

	enum eRecordTypes
	{
		DATA_RECORD_TYPE,				//0x00
		EOF_RECORD_TYPE,				//0x01
		EXTENDED_ADDRESS_TYPE,			//0x02
		START_SEGMENT_ADDRESS_TYPE,		//0x03
		EXTENDED_LINEAR_ADDRESS_TYPE,	//0x04
		START_LINEAR_ADDRESS_TYPE,		//0x05
		MAX_RECORD_TYPE
	};

	enum eRetValues
	{
		RET_DATA_RECORD,				
		RET_EOF_RECORD,				
		RET_EXTENDED_ADDRESS,		
		RET_START_SEGMENT_ADDRESS,		
		RET_EXTENDED_LINEAR_ADDRESS,
		RET_IGNORED_ALL_FF_RECORD,
		RET_START_LINEAR_ADDRESS,		
		RET_UNKNOWN_RECORD_TYPE,
		RET_INVALID_RECORD,
		RET_BAD_RECORD_CHECKSUM,
		RET_UNMANAGED_RECORD_TYPE
	};

    //char *mRecordData;
    QByteArray mRecordData;
	unsigned int mStartAddress;
    unsigned int mRecordSize;
	unsigned int mRecordType;
    unsigned int mExtendedAddress;


	CHexRecord(void);
	~CHexRecord(void);

	int SetRecordStartAddress(unsigned int Address);
	int SetRecordSize(unsigned int size);
    int DecodeRawRecord(QString *RawRecordData, unsigned int HighAddress);

	unsigned int GetExtenedAddress(void){return mExtendedAddress;}
	unsigned int GetStartAddress(void){return mStartAddress;}
    char *GetDataBuffer(void){return mRecordData.data();}
    QByteArray GetData(void){return mRecordData;}
    unsigned int GetRecordSize(void){return mRecordData.size()/4;}
    unsigned int GetRecordSizeInBytes(void){return mRecordData.size();}
	unsigned int GetRecordType(void){return mRecordType;}
	unsigned int AppendRecord(CHexRecord *RecordToAppend);
    QByteArray GetRecord();

	CHexRecord& operator=(const CHexRecord &rhs);


};
