BodiesAbstract.cpp
2.49 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
106
107
#include "BodiesAbstract.h"
#include <iostream>
#include <cstring>
#include "../Common/Toolbox.h"
#include "../TimeManager/TimeManager.h"
using namespace std;
using namespace TREPS::Common;
using namespace TREPS::File;
using namespace TREPS::TimeManager;
namespace TREPS
{
namespace Bodies
{
BodiesAbstractClass::BodiesAbstractClass(RequestAbstractClass *trepsRequest) : app(NULL), trepsRequest(trepsRequest),
errorMsg(""), request(NULL), result(NULL)
{
this->app = ApplicationClass::getInstance();
this->request = new BodiesRequestClass();
this->result = new BodiesResultClass();
}
BodiesAbstractClass::~BodiesAbstractClass(void)
{
if (this->request != NULL)
{
delete this->request;
this->request = NULL;
}
if (this->result != NULL)
{
delete this->result;
this->result = NULL;
}
}
bool BodiesAbstractClass::init(const bool isSc, const t_Time *startTime, const t_Time *endTime)
{
this->trepsRequest->setStatus("Initialize bodies abstract class");
if (this->request == NULL)
{
LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot init bodies request");
return false;
}
this->request->setIsSc(isSc);
this->request->setTimes(startTime, endTime);
//save request file
/* if (!this->request->saveToFile(bodiesRequest))
{
LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot save bodies request file");
return false;
}
*/
return true;
}
bool BodiesAbstractClass::writeResult(const char *resultPath)
{
this->trepsRequest->setStatus("Finalize getbodies XML result");
FileWriterBodiesClass *fileWriter = new FileWriterBodiesClass();
map<string,string> attributes;
attributes.clear();
//init the file writer
if (!fileWriter->init(resultPath, &attributes))
{
LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Error to init the file to write " << resultPath);
delete fileWriter;
return false;
}
//write file data
if (!fileWriter->writeData(result->getBodies()))
{
LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Error to write data");
delete fileWriter;
return false;
}
//save file
bool res = fileWriter->save();
if (!res)
{
LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Error to save file");
}
delete fileWriter;
return res;
}
string BodiesAbstractClass::getLastError(void)
{
return this->errorMsg;
}
}
}