/* Header for the definition of a characteristic type*/
/*//////////////////////////////////////////////////////*/
/*	A characteristic type is an abstract class which defines*/
/*	some common functions of specific characteristics (like Booleans,*/
/*	numerical values, aso)*/
/*	Every specific type of characteristic will inherit of this class*/
/*/////////////////////////////////////////////////////////////////////*/
#ifndef _CTL_DATA_
#define _CTL_DATA_
 
#if _MSC_VER >= 1000
#pragma once
#endif /* _MSC_VER >= 1000*/
 
#include <afxtempl.h>
 
#include "CTL\Others\CTL_ODat.hpp"
#include "CTL\Others\CTL_ClBk.hpp"
 
class CTL_Editor_EnumDescriptor;
class CTL_Editor_MaskDescriptor;
class CTL_Editor_Control;
class CTL_Editor_DataList;
 
/*#########################################################*/
typedef enum CTL_eEditorDataType
{
	CTL_DATA_TYPE__INTEGER = 0,
	CTL_DATA_TYPE__DECIMAL,
	CTL_DATA_TYPE__BOOLEAN,
	CTL_DATA_TYPE__MASKED,
	CTL_DATA_TYPE__ENUM,
	CTL_DATA_TYPE__TEXT,
	CTL_DATA_TYPE__VECTOR,
	/* BEGIN ROMTEAM Cristi Petrescu 98-11-*/
	CTL_DATA_TYPE__ARRAY,
	CTL_DATA_TYPE__ARRAY_ENUM,
	CTL_DATA_TYPE__ARRAY_VECTOR,
	CTL_DATA_TYPE__ARRAY_DECIMAL,
	CTL_DATA_TYPE__ARRAY_INTEGER,
	/* END ROMTEAM Cristi Petrescu 98-11-*/
 
	CTL_DATA_TYPE__USE_USER_DEFINED_TYPE,
 
} CTL_tdeEditorDataType;
 
/*#########################################################*/
typedef enum CTL_eUpdateReason
{
	CTL_UPDATE_REASON__NO_REASON_GIVEN = 0,
	CTL_UPDATE_REASON__DATA_MODIFIED_BY_USER,
	CTL_UPDATE_REASON__DATA_READ_FROM_MOTOR,
	
	CTL_UPDATE_REASON__USE_USER_DEFINED_REASON,
 
} CTL_tdeUpdateReason;
 
/*#########################################################*/
/*-----------------------*/
#define D_BIFIELD_ON_CHAR
/*#define D_BIFIELD_ON_SHORT	 //not enabled yet !!*/
/*#define D_BIFIELD_ON_LONG		 //not enabled yet !!*/
 
#ifdef D_BIFIELD_ON_CHAR
typedef unsigned char tdBitFieldCoder;
#endif /*D_BIFIELD_ON_CHAR*/
#ifdef D_BIFIELD_ON_SHORT
typedef unsigned short tdBitFieldCoder; /*not enabled yet !!*/
#endif /*D_BIFIELD_ON_SHORT*/
#ifdef D_BIFIELD_ON_LONG
typedef unsigned long tdBitFieldCoder;  /*not enabled yet !!*/
#endif /*D_BIFIELD_ON_LONG*/
/*-----------------------*/
 
 
/*#########################################################*/
class CPA_EXPORT CTL_Editor_Data
{
public:
	/*Constructor*/
 	CTL_Editor_Data(CTL_tdeEditorDataType _tdeType,
									CString _csDataName,
									CTL_Editor_DataList *_pclParentList,
									CTL_Editor_Data *_pclCurrentBaseData = NULL,
									long _lUSerDefinedDataType = 0);
 
	/* Destructor*/
	virtual ~CTL_Editor_Data();
 
/*Attributes*/
public:
 
protected:
	/*Indicates wether current value is different from the old one or not*/
	/* (used during motor run)*/
	BOOL m_pro_bDataHasChanged;
 
	/*The Parent Control*/
	CTL_Editor_Control *m_pro_pclParentControl;
 
	/*The name*/
	CString m_pro_csDataName;
 
	/*The type of the Data*/
	CTL_tdeEditorDataType m_pro_tdeDataType;
 
	/*Pointer on motor's data*/
	void *m_pro_pvMotorData;
 	char m_pro_cDataLength;
 
	/*The string list to return and get save datas*/
	CStringList m_csStringList;
 
	/*CallBack function : called when edited Data has changed*/
	CTL_td_p_fn_vCallBackWhenDataHasChanged m_pro_td_p_fn_vDataHasChangedCallBack;
	CTL_td_p_fn_vCallBackWhenDataHasChanged m_pro_td_p_fn_vDataHasChangedSpecialCallBack;
 
	/*Modification Functions*/
	CTL_tdp_fn_vDataModificationFunction m_pro_td_p_fn_vDataModifWhenRead;
	CTL_tdp_fn_vDataModificationFunction m_pro_td_p_fn_vDataModifWhenWrite;
 
	/*When Data must be Read or Write*/
	CTL_td_p_fn_bCallBackWhenDataMustBeReadOrWritten m_pro_td_p_fn_bDataMustBeRead;
	CTL_td_p_fn_bCallBackWhenDataMustBeReadOrWritten m_pro_td_p_fn_bDataMustBeWritten;
 
	/*User Defined Data type*/
	long m_pro_lUSerDefinedDataType;
 
private:
	/*Link between initial and current Data*/
	/*The associated current Data*/
	CTL_Editor_Data *m_pclAssociatedCurrentData;
	/*The associated Initial Data*/
	CTL_Editor_Data *m_pclAssociatedInitialData;
 
	/*List of OwnerData*/
	CTL_ListOfOwnerData m_pri_clListOfOwnerData;
	
	/*Parent List of Data*/
	CTL_Editor_DataList *m_pri_pclParentList;
 
/*Member functions*/
public:
	/*Returns the name of the Data*/
	CString m_pub_fn_csGetDataName();
	/*No 'Set' Function (Name is given to constructor)*/
 
	/*Get/Set for the Parent Control*/
	CTL_Editor_Control *m_pub_fn_pclGetParentControl();
	void m_pub_fn_vSetParentControl(CTL_Editor_Control *_pclParentControl);
	
	/*Get/Set for the pointer on motor's data*/
	void *m_pub_fn_pvGetMotorData();
 	void m_pub_fn_vSetMotorData(void *_p_vMotorData);
 	
	/*Indicates wether current value is different from the old one or not*/
	/* (used during motor run)*/
	BOOL m_pub_fn_bGetDataHasChanged();
	void m_pub_fn_vSetDataHasChanged(BOOL _bNewSate);
 
	CTL_tdeEditorDataType m_pub_fn_tdeGetDataType();
 
	/*Link between initial and current Data*/
	/*The associated current Data*/
	BOOL m_fn_bHasACurrentData();
	CTL_Editor_Data *m_fn_pclGetAssociatedCurrentData();
	void m_fn_vSetAssociatedCurrentData(CTL_Editor_Data *);
	/*The associated Initial Data*/
	BOOL m_fn_bHasAnInitialData();
	CTL_Editor_Data *m_fn_pclGetAssociatedInitialData();
	void m_fn_vSetAssociatedInitialData(CTL_Editor_Data *);
 
	void m_fn_vSetMotorDataPtr(void *p_vMotorData);
	void *m_fn_pvGetMotorDataPtr();
 
	/*Owner Data*/
	CTL_OwnerData *m_pub_fn_pclAddOwnerData(void *_pvDataPtr,
																					CString _csName);
	CTL_OwnerData *m_pub_fn_pclAddOwnerData(long _lData,
																					CString _csName);
	CTL_OwnerData *m_pub_fn_pclGetOwnerDataWithName(CString _csSearchedName);
 
	/*Parent List of Data*/
	CTL_Editor_DataList *m_pub_fn_pclGetParentList();
 
	/*User Defined Data type*/
	long m_pub_fn_lGetUSerDefinedDataType();
 
	/*CallBack Functions : when data is modifed*/
	void m_pub_fn_vSetDataChangedCallBackFunction(CTL_td_p_fn_vCallBackWhenDataHasChanged _td_p_fn_vDataHasChangedCallBack);
	void m_pub_fn_vSetDataChangedSpecialCallBackFunction(CTL_td_p_fn_vCallBackWhenDataHasChanged _td_p_fn_vDataHasChangedSpecialCallBack);
 
	/*Modification CallBack Functions*/
	void m_pub_fn_vSetModificationFunctionWhenRead(CTL_tdp_fn_vDataModificationFunction p_fn_vDataModifWhenRead);
	void m_pub_fn_vSetModificationFunctionWhenWrite(CTL_tdp_fn_vDataModificationFunction p_fn_vDataModifWhenWrite);
 
	/*When Data must be Read or Written*/
	void m_pub_fn_vSetDataMustBeRead_CallBack(CTL_td_p_fn_bCallBackWhenDataMustBeReadOrWritten _p_fn_CallBack);
	void m_pub_fn_vSetDataMustBeWritten_CallBack(CTL_td_p_fn_bCallBackWhenDataMustBeReadOrWritten _p_fn_CallBack);
 
	/*Function called to get a string representing the value of the data*/
	virtual CStringList *m_fn_pcslFormatDataValueString();
 
	/*Function called to set the value of the data acoording to a string representing it*/
	/*(This function is pure virtual)*/
	virtual void m_fn_vSetValueWithString(CStringList *) = 0;
 
	/*Function called to Init the data*/
	virtual void m_fn_vInitData();
 
	/*Function called to read associated motor's data*/
	/*(This function is pure virtual)*/
	virtual void m_fn_vGetMotorData() = 0;
 
	/*Function called to update associated motor's data*/
	/*(This function is pure virtual)*/
	virtual void m_fn_vUpdateMotorData(CTL_tdeUpdateReason eReason = CTL_UPDATE_REASON__NO_REASON_GIVEN,
																		 long _lUserDefinedReason = 0) = 0;
 
	/*Function called to update data with another one*/
	/*(This function is pure virtual)*/
	virtual void m_fn_vUpdateData(CTL_Editor_Data *pclSourceData,
																CTL_tdeUpdateReason eReason = CTL_UPDATE_REASON__NO_REASON_GIVEN,
																long _lUserDefinedReason = 0) = 0;
 
	/*Function called to look if data has been modified (by motor for example)*/
	/*(This function is pure virtual)*/
	virtual void m_fn_vLookIfDataHasBeenModified() = 0;
	/*CPA2 Stegaru Cristian 98/06/24*/
	virtual BOOL mfn_bEqualsModifiedDataOldValue (CTL_Editor_Data *pModifiedData) { return FALSE;}
	/*End CPA2 Stegaru Cristian 98/06/24*/
 
	void m_fn_vDataHasBeenChanged(CTL_tdeUpdateReason _eReason,
																long _lUserDefinedReason = 0);
 
protected:
 
private:
 
 
};
 
#endif /*_CTL_DATA_*/
