-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathactionLoader.cpp
130 lines (99 loc) · 2.05 KB
/
actionLoader.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "actionLoader.h"
#include <QStringList>
ActionLoader::ActionLoader(const QString &fileName) :
mIsFileCorrect(true),
mIsFileEnd(false)
{
mFile.setFileName(fileName);
mFile.open(QFile::ReadOnly | QFile::Truncate);
mStream.setDevice(&mFile);
propertiesParse();
}
ActionLoader::~ActionLoader()
{
mFile.close();
}
bool ActionLoader::isFileCorrect() const
{
return mIsFileCorrect;
}
bool ActionLoader::isFileEnd() const
{
return mIsFileEnd;
}
QList<int> ActionLoader::data()
{
QStringList strList = mStream.readLine().split(" ");
QList<int> intList;
for (int i = 0; i < mNumberOfDOF; i++) {
intList.prepend(0);
}
if (strList.at(0) == ActionFileStructure::endActionKeyWord()) {
mIsFileEnd = true;
return intList;
}
if (strList.size() != mNumberOfDOF) {
mIsFileCorrect = false;
return intList;
}
for (int i = 0; i < mNumberOfDOF; i++) {
int val = strList.at(i).toInt();
if (!isValueCorrect(val)) {
mIsFileCorrect = false;
return intList;
}
intList[i] = val;
}
return intList;
}
void ActionLoader::propertiesParse()
{
if (mStream.readLine() != ActionFileStructure::header()) {
mIsFileCorrect = false;
return;
}
readFrequency();
readNumberOfDOF();
if (mStream.readLine() != ActionFileStructure::startActionKeyWord()) {
mIsFileCorrect = false;
return;
}
}
void ActionLoader::readFrequency()
{
QString str;
mStream >> str;
if (str != ActionFileStructure::freqKeyWord()) {
mIsFileCorrect = false;
return;
}
int freq = 0;
mStream >> freq;
if (freq < FreqLimits::minFreq || freq > FreqLimits::maxFreq) {
mIsFileCorrect = false;
return;
}
mFreq = freq;
mStream.readLine();
}
void ActionLoader::readNumberOfDOF()
{
QString str;
mStream >> str;
if (str != ActionFileStructure::DOFKeyWord()) {
mIsFileCorrect = false;
return;
}
int DOF = 0;
mStream >> DOF;
if (DOF < DOFLimits::minDOFs || DOF > DOFLimits::maxDOFs) {
mIsFileCorrect = false;
return;
}
mNumberOfDOF = DOF;
mStream.readLine();
}
bool ActionLoader::isValueCorrect(const int &val) const
{
return (val >= 0 && val <= 180);
}