-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMeasurementPeriod.cpp
executable file
·90 lines (72 loc) · 2.55 KB
/
MeasurementPeriod.cpp
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
#include "MeasurementPeriod.h"
#include "stdlib.h"
#include "Algoritmos.h"
std::vector<int>& MeasurementPeriod::getDayOfTheWeek()
{
return this->dayOfTheWeek;
}
std::vector<struct tm*>& MeasurementPeriod::getStartTimes()
{
return this->startTime;
}
std::vector<struct tm*>& MeasurementPeriod::getEndTimes()
{
return this->endTime;
}
void MeasurementPeriod::setDayOfTheWeek(std::vector<int> v)
{
this->dayOfTheWeek = v;
}
void MeasurementPeriod::setStartTimes(std::vector<struct tm* > s)
{
this->startTime = s;
}
void MeasurementPeriod::setEndTimes(std::vector<struct tm* > e)
{
this->endTime = e;
}
MeasurementPeriod::~MeasurementPeriod()
{
for(int i = 0; i < this->endTime.size(); i++)
free(this->endTime.at(i));
for(int i = 0; i < this->startTime.size(); i++)
free(this->startTime.at(i));
}
MeasurementPeriod::MeasurementPeriod()
{
}
void MeasurementPeriod::parsingMeasurementPeriod(DOMElement *raiz, bool def)
{
DOMElement *element = NULL;
std::string start, day, endd;
if(def){
start = "DefaultMeasurementStartTime";
endd = "DefaultMeasurementEndTime";
day = "DefaultDayOfTheWeek";
}else{
start = "StartTime";
endd = "EndTime";
day = "DayOfTheWeek";
}
for(int i = 0; i < raiz->getElementsByTagName(XMLString::transcode(day.c_str()))->getLength(); i++){
element = dynamic_cast<DOMElement*> (raiz->getElementsByTagName(
XMLString::transcode(day.c_str()))->item(i));
this->dayOfTheWeek.push_back(stoi(XMLString::transcode(element->getTextContent()), nullptr, 10));
}
for(int i = 0; i < raiz->getElementsByTagName(XMLString::transcode(start.c_str()))->getLength(); i++){
element = dynamic_cast<DOMElement*> (raiz->getElementsByTagName(
XMLString::transcode(start.c_str()))->item(i));
std::string value = XMLString::transcode(element->getTextContent());
struct tm* time = (struct tm*)malloc(sizeof(struct tm));
setTimeAndDate(time, value);
this->startTime.push_back(time);
}
for(int i = 0; i < raiz->getElementsByTagName(XMLString::transcode(endd.c_str()))->getLength(); i++){
element = dynamic_cast<DOMElement*> (raiz->getElementsByTagName(
XMLString::transcode(endd.c_str()))->item(i));
std::string value = XMLString::transcode(element->getTextContent());
struct tm* time = (struct tm*)malloc(sizeof(struct tm));
setTimeAndDate(time, value);
this->endTime.push_back(time);
}
}