#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 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; } }