TransformationResult.cpp 2.51 KB
#include "TransformationResult.h"

namespace TREPS
{
	namespace Transformation
	{
		TransformationResultClass::TransformationResultClass(void) : app(NULL), exportMgr(NULL)
		{
			this->app = ApplicationClass::getInstance();

			//create export manager to write transformation result file
			this->exportMgr = new ExportManagerClass();

			this->dstFields.clear();
			this->dstData.clear();
		}

		TransformationResultClass::~TransformationResultClass(void)
		{
			if (this->exportMgr != NULL)
			{
				delete this->exportMgr;
				this->exportMgr = NULL;
			}
			this->dstFields.clear();
			this->dstData.clear();
		}

		DataRecordListClass *TransformationResultClass::getDstDataRecordList(void) const
		{
			return const_cast<DataRecordListClass *>(&this->dstData);
		}

		t_FieldList *TransformationResultClass::getDstFieldList(void) const
		{
			return const_cast<t_FieldList *>(&this->dstFields);
		}

		bool TransformationResultClass::init(t_TimeFormat timeFormat, const DataRecordListClass *srcData)
		{
			//reset result
			this->dstFields.clear();
			this->dstData.clear();

			DataRecordClass *crtRecord = srcData->getFirstRecord();
			while (crtRecord != NULL)
			{
				DataRecordClass *newRecord = this->dstData.addNew();
				if (timeFormat != TF_NONE)
					newRecord->setTime(crtRecord->getTime());
				newRecord->setTag(crtRecord->getTag());
				crtRecord = crtRecord->getNextRecord();
			}

			return true;
		}

		bool TransformationResultClass::addFieldVector(const char *fieldId, const DataRecordListClass *data,
							const char *comp_1, const char *comp_2, const char *comp_3, const char *frame)
		{
			//add a vector as a field in result data
			t_Field vecField = this->exportMgr->initNewFieldVector(fieldId, fieldId, FT_DOUBLE, frame);

                        return this->exportMgr->addFieldVector(&vecField, data, comp_1, comp_2, comp_3, &(this->dstFields), &(this->dstData));
		}

		void TransformationResultClass::clone(const t_FieldList *fields, const DataRecordListClass *data, const char *timeFieldId)
		{
			//clone data in result data
			this->dstFields.clear();
			this->dstData.clear();

			for (t_FieldList::const_iterator field = fields->begin(); field != fields->end(); ++field)
			{
				// 9639 update starting index copy, escape all time fields
				// if (/*((*field).type == FT_TIME) &&*/ ((*field).id.compare(timeFieldId) == 0))
				if (/*((*field).type == FT_TIME) &&*/ ( atoi((*field).id.c_str()) <= atoi(timeFieldId) ))
					continue;
				this->dstFields.push_back((*field));
			}
			data->clone(&(this->dstData));
		}
	}
}