FileLoaderAbstract.cpp 2.58 KB
#include "FileLoaderAbstract.h"

#include "../Common/Toolbox.h"

using namespace TREPS::Common;

namespace TREPS
{
	namespace File
	{
		FileLoaderAbstractClass::FileLoaderAbstractClass(void) : app(NULL), frameMgr(NULL)
		{
			this->app = ApplicationClass::getInstance();

			this->frameMgr = new FrameManagerClass();
		}

		FileLoaderAbstractClass::~FileLoaderAbstractClass(void)
		{
			if (this->frameMgr != NULL)
			{
				delete this->frameMgr;
				this->frameMgr = NULL;
			}
		}

		bool FileLoaderAbstractClass::getInfo(t_FileInfo &info)
		{
			info.format = this->getFormat();

			//get frames list file path
			string framesPath = this->app->getConf()->getFramesFilePath();

			if (framesPath.compare("") != 0)
				//init frame manager
				frameMgr->init(framesPath.c_str());

			//get nb of records
			info.nbRecords = this->getNbRecords();

			//get fields
                        info.fields = this->getFields(info.nbRecords);

			//detect frames
			info.frames = this->getFrames(&info.fields);

			//detect vectors
			info.vectors = this->getVectors(&info.fields);

			//get file attributes
			info.attributes = this->getAttributes();

                        return (!info.fields.empty());
                }

		t_VectorList FileLoaderAbstractClass::getVectors(const t_FieldList *fields)
		{
			//get common vectors
			t_VectorList vectors;
			vectors.clear();

			int vecIndex = 0;
			for (t_FieldList::const_iterator field = fields->begin(); field != fields->end(); ++field)
			{
				//a string field or a time field cannot be considerate as a vector
				if (((*field).type == FT_UNKNOWN) || ((*field).type == FT_TIME))
					continue;
				//no dimension => it's a scalar
				if ((*field).dims.empty())
					continue;
				//more than one dimension => it's not a vector
				if ((*field).dims.size() > 1)
					continue;
				//if the dimension size is 3 => it's a vector
				if ((*field).dims.begin()->size == 3)
				{
					//use the field id for the vector id
					t_Vector vec;
					vec.id  = "v_";
					vec.id += intToStr(vecIndex);

					//define the 3 components
					vec.fieldId[0] = (*field).id;
					vec.fieldId[0] += "_TREPSID0";

					vec.fieldId[1] = (*field).id;
					vec.fieldId[1] += "_TREPSID1";

					vec.fieldId[2] = (*field).id;
					vec.fieldId[2] += "_TREPSID2";

					vec.nbRecords = (*field).nbRecords;

					vectors.push_back(vec);
					++vecIndex;
				}
			}

			//add specific possibility to define a vector for a format file
			this->addSpecificFormatVectors(fields, vectors);

			return vectors;
		}
	}
}