FileLoaderAbstract.cpp
2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#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;
}
}
}