-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrame.cpp
More file actions
98 lines (72 loc) · 1.84 KB
/
Frame.cpp
File metadata and controls
98 lines (72 loc) · 1.84 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
#include "Frame.h"
#include <fstream>
using std::string;
using std::stringstream;
using std::ifstream;
Frame::Frame(ifstream* in_fp) {
// Naming convenience.
ifstream& fp = *in_fp;
char line[1024];
fp.getline(line, 1024);
string lines(line);
stringstream s(lines);
int count = 0;
while (!s.eof()) {
double junk;
s >> junk;
count++;
}
numFields_ = count - 1;
fields_ = new double[count];
stringstream s2(lines);
double tempTime;
s2 >> tempTime;
//convert from sec to ms
time_ = static_cast<long>(ceil(tempTime * 1000));
for (int i = 0; i < count; ++i)
s2 >> fields_[i];
}
Frame::Frame(int nf) : numFields_(nf) {
fields_ = new double[numFields_];
}
Frame::Frame(const Frame& rhs) {
numFields_ = rhs.numFields_;
time_ = rhs.time_;
fields_ = new double[numFields_];
for (int i = 0; i < numFields_; ++i)
fields_[i] = rhs.fields_[i];
}
Frame::~Frame() {
delete [] fields_;
}
int Frame::getNumFields() const
{
return numFields_;
}
const double* Frame::getFields() const {
return fields_;
}
unsigned long Frame::getTimeInMS() const {
return time_;
}
Frame Frame::operator+(const Frame& rhs) const {
Frame temp(this->getNumFields());
for (int i = 0; i < this->getNumFields(); ++i)
temp.fields_[i] = this->fields_[i] + rhs.fields_[i];
temp.time_ = this->time_ + rhs.time_;
return temp;
}
Frame Frame::operator-(const Frame& rhs) const {
Frame temp(this->getNumFields());
for (int i = 0; i < this->getNumFields(); ++i)
temp.fields_[i] = this->fields_[i] - rhs.fields_[i];
temp.time_ = this->time_ - rhs.time_;
return temp;
}
Frame Frame::operator*(double scalar) const {
Frame temp(this->getNumFields());
for (int i = 0; i < this->getNumFields(); ++i)
temp.fields_[i] = this->fields_[i] * scalar;
temp.time_ = floorl(this->time_ * scalar);
return temp;
}