| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440 | #include "stdafx.h"#include "GridData.h"namespace OTSDATA {//CGridRow:	// constructor	CGridRow::CGridRow()											// constructor	{		Init();	}	CGridRow::CGridRow(const CGridRow& a_oSource)							// copy constructor	{		// can't copy itself		if (&a_oSource == this)		{			return;		}		// copy data over		Duplicate(a_oSource);	}	CGridRow::CGridRow(CGridRow* a_poSource)								// copy constructor	{		// input check		ASSERT(a_poSource);		if (!a_poSource)		{			return;		}		// can't copy itself		if (a_poSource == this)		{			return;		}		// copy data over		Duplicate(*a_poSource);	}	CGridRow& CGridRow::operator=(const CGridRow&  a_oSource)				// =operator	{		// cleanup		Cleanup();		// copy the class data over		Duplicate(a_oSource);		// return class		return *this;	}	BOOL CGridRow::operator==(const CGridRow& a_oSource)						// ==operator	{		return (m_strValue.Compare(a_oSource.m_strValue) == 0 &&			  *(m_oParticle.get()) == *(a_oSource.m_oParticle.get()) &&			    m_nDataType == a_oSource.m_nDataType && 			    m_nIntValue == a_oSource.m_nIntValue && 			    m_dFloatValue == a_oSource.m_dFloatValue);	}	CGridRow::~CGridRow()									// destructor	{		// cleanup		Cleanup();	}	BOOL CGridRow::SetParticle(COTSParticlePtr a_oParticle)	{		ASSERT(a_oParticle);		if (!a_oParticle)		{			return FALSE;		}		m_oParticle = COTSParticlePtr(new COTSParticle(*a_oParticle.get()));		return TRUE;	}//protected	// cleanup	void CGridRow::Cleanup()	{	}	// initialization	void CGridRow::Init()	{		// data type		m_nDataType = REPORT_GRID_DATA_TYPE::INVALID;		// string data		m_strValue = _T("");		// particle data		m_oParticle = COTSParticlePtr(new COTSParticle());		// int value		m_nIntValue = -1;		// float value		m_dFloatValue = 0.0;	}	// duplication 	void CGridRow::Duplicate(const CGridRow& a_oSource)	{		// initialization		Init();		m_nDataType = a_oSource.m_nDataType;		// string data		m_strValue = a_oSource.m_strValue;		// particle data		m_oParticle = COTSParticlePtr(new COTSParticle(*a_oSource.m_oParticle.get()));		// int value		m_nIntValue = a_oSource.m_nIntValue;		// float value		m_dFloatValue = a_oSource.m_dFloatValue;	}//CGridColumn	// constructor	CGridColumn::CGridColumn()											// constructor	{		Init();	}	CGridColumn::CGridColumn(const CGridColumn& a_oSource)							// copy constructor	{		// can't copy itself		if (&a_oSource == this)		{			return;		}		// copy data over		Duplicate(a_oSource);	}	CGridColumn::CGridColumn(CGridColumn* a_poSource)								// copy constructor	{		// input check		ASSERT(a_poSource);		if (!a_poSource)		{			return;		}		// can't copy itself		if (a_poSource == this)		{			return;		}		// copy data over		Duplicate(*a_poSource);	}	CGridColumn& CGridColumn::operator=(const CGridColumn& a_oSource)				// =operator	{		// cleanup		Cleanup();		// copy the class data over		Duplicate(a_oSource);		// return class		return *this;	}	BOOL CGridColumn::operator==(const CGridColumn& a_oSource)						// ==operator	{		CGridRowsList listGridRows = a_oSource.m_listGridRows;		if ((int)listGridRows.size() != (int)m_listGridRows.size())		{			return FALSE;		}		for (int i = 0; i< (int)m_listGridRows.size(); i++)		{			if (*(m_listGridRows[i].get()) == *(listGridRows[i].get()))			{				return FALSE;			}		}		return (m_strName.Compare(a_oSource.m_strName) == 0);	}	CGridColumn::~CGridColumn()									// destructor	{	}	BOOL CGridColumn::SetGridRowsList(CGridRowsList a_listGridRows, BOOL a_bClear/* = TRUE*/)	{		if (a_bClear)		{			m_listGridRows.clear();		}		for (auto pGridRows : a_listGridRows)		{			CGridRowPtr pGridRowNew = CGridRowPtr(new CGridRow(*pGridRows.get()));			m_listGridRows.push_back(pGridRowNew);		}		return TRUE;	}//protected	// cleanup	void CGridColumn::Cleanup()	{	}	// initialization	void CGridColumn::Init()	{		// name		m_strName = _T("");		// list of rows		m_listGridRows.clear();	}	// duplication 	void CGridColumn::Duplicate(const CGridColumn& a_oSource)	{		m_strName = a_oSource.m_strName;		// list of rows		m_listGridRows.clear();		for (auto pGridRows : a_oSource.m_listGridRows)		{			CGridRowPtr pGridRowNew = CGridRowPtr(new CGridRow(*pGridRows.get()));			m_listGridRows.push_back(pGridRowNew);		}	}// CGridColunm	// constructor	CGridData::CGridData()											// constructor	{		Init();	}	CGridData::CGridData(const CGridData& a_oSource)							// copy constructor	{		// can't copy itself		if (&a_oSource == this)		{			return;		}		// copy data over		Duplicate(a_oSource);	}	CGridData::CGridData(CGridData* a_poSource)								// copy constructor	{		// input check		ASSERT(a_poSource);		if (!a_poSource)		{			return;		}		// can't copy itself		if (a_poSource == this)		{			return;		}		// copy data over		Duplicate(*a_poSource);	}	CGridData& CGridData::operator=(const CGridData& a_oSource)				// =operator	{		// cleanup		Cleanup();		// copy the class data over		Duplicate(a_oSource);		// return class		return *this;	}	BOOL CGridData::operator==(const CGridData& a_oSource)						// ==operator	{		CGridColumnsList listGridColumns = a_oSource.m_listGridColumn;		if ((int)listGridColumns.size() != (int)m_listGridColumn.size())		{			return FALSE;		}		for (int i = 0; i < (int)m_listGridColumn.size(); i++)		{			if (*(m_listGridColumn[i].get()) == *(listGridColumns[i].get()))			{				return FALSE;			}		}		return TRUE;	}	CGridData::~CGridData()									// destructor	{	}	BOOL CGridData::SetGridColumnList(CGridColumnsList a_listGridColumn, BOOL a_bClear/* = TRUE*/)	{		if (a_bClear)		{			m_listGridColumn.clear();		}		for (auto pGridColumn : a_listGridColumn)		{			CGridColumnPtr pGridColumnNew = CGridColumnPtr(new CGridColumn(*pGridColumn.get()));			m_listGridColumn.push_back(pGridColumnNew);		}		return TRUE;	}	// data source id	BOOL CGridData::SetDataSourceList(std::vector<CString> a_listDataSource)	{		// data source count is reduced? 		if (m_listDataSource.size() > a_listDataSource.size())		{			// need to check if data source id has to be changed			// data source count is 0			if ((int)a_listDataSource.size() == 0)			{				// set data source id to -1, no working data source				m_nDataSourceId = -1;			}			// need to set data source id to 0? 			else if (m_nDataSourceId >= (int)a_listDataSource.size())			{				// set data source id to 0, the first data source is the working data source				m_nDataSourceId = 0;			}			else if (m_nDataSourceId == -1 && (int)a_listDataSource.size() > 0)			{				// set data source id to 0, the first data source is the working data source				m_nDataSourceId = 0;			}		}		// set data source count		m_listDataSource = a_listDataSource;		// ok, return TRUE		return TRUE;	}	BOOL CGridData::SetDataSourceId(int a_nDataSourceId)	{		// data source id can't be < -1, -1 means no working data source		if (a_nDataSourceId < -1)		{			return FALSE;		}		// data source id >= data source count		/*else if (a_nDataSourceId >= (int)m_listDataSource.size())		{			return FALSE;		}*/		m_nDataSourceId = a_nDataSourceId;		// ok, return TRUE		return TRUE;	}//protected	// cleanup	void CGridData::Cleanup()	{	}	// initialization	void CGridData::Init()	{		// list of rows		m_listGridColumn.clear();	}	// duplication 	void CGridData::Duplicate(const CGridData& a_oSource)	{		Init();			// list of rows		m_listGridColumn.clear();		for (auto pGridColumn : a_oSource.m_listGridColumn)		{			CGridColumnPtr pGridColumnNew = CGridColumnPtr(new CGridColumn(*pGridColumn.get()));			m_listGridColumn.push_back(pGridColumnNew);		}		// data source id		for (auto strDataSource : a_oSource.m_listDataSource)		{			m_listDataSource.push_back(strDataSource);		}		m_nDataSourceId = a_oSource.m_nDataSourceId;	}}
 |