equal
deleted
inserted
replaced
1 #include "igc.h" |
1 #include "igc.h" |
|
2 |
|
3 Fix::Fix(const QString &s) |
|
4 { |
|
5 int pos = 0; |
|
6 |
|
7 time_ = QTime::fromString(s.mid(pos, 6), "hhmmss"); |
|
8 pos += 6; |
|
9 |
|
10 gps_.lat = s.mid(pos, 8); pos += 8; // DDMMmmm[NS] |
|
11 gps_.lon = s.mid(pos, 9); pos += 9; // DDDMMmmm[EW] |
|
12 |
|
13 is3d_ = s.mid(pos, 1) == "A"; |
|
14 pos += 1; |
|
15 |
|
16 alt_[baro] = s.mid(pos, 5).toInt(); pos += 5; |
|
17 alt_[gps] = s.mid(pos, 5).toInt(); pos += 5; |
|
18 } |
|
19 |
|
20 |
|
21 IGC::IGC() |
|
22 #ifdef __GXX_EXPERIMENTAL_CXX0X__ |
|
23 : altitude_({0}) |
|
24 #endif |
|
25 { |
|
26 #ifndef __GXX_EXPERIMENTAL_CXX0X__ |
|
27 memset(altitude_, 0, sizeof(altitude_)); |
|
28 #endif |
|
29 } |
|
30 |
|
31 IGC::IGC(QTextStream &s) |
|
32 #ifdef __GXX_EXPERIMENTAL_CXX0X__ |
|
33 : altitude_({0}) |
|
34 #endif |
|
35 { |
|
36 #ifndef __GXX_EXPERIMENTAL_CXX0X__ |
|
37 memset(altitude_, 0, sizeof(altitude_)); |
|
38 #endif |
|
39 read(s); |
|
40 } |
|
41 |
|
42 IGC::~IGC() |
|
43 { |
|
44 for (size_t i = 0; i < sizeof(altitude_)/sizeof(altitude_[0]); ++i) { |
|
45 delete altitude_[i]; |
|
46 } |
|
47 } |
2 |
48 |
3 void IGC::read(QTextStream &in) |
49 void IGC::read(QTextStream &in) |
4 { |
50 { |
5 while (!in.atEnd()) { |
51 while (!in.atEnd()) { |
6 char c; |
52 char c; |
35 (void) in.readLine(); |
81 (void) in.readLine(); |
36 } |
82 } |
37 } |
83 } |
38 } |
84 } |
39 |
85 |
40 Fix::Fix(const QString &s) |
86 const QVector<QPointF>& IGC::altitude(Fix::Source src) const |
41 { |
87 { |
42 int pos = 0; |
88 |
|
89 // optimization: if already allocated, return the allocated vector |
|
90 if (altitude_[src]) return *altitude_[src]; |
43 |
91 |
44 time_ = QTime::fromString(s.mid(pos, 6), "hhmmss"); |
92 altitude_[src] = new QVector<QPointF>; |
45 pos += 6; |
|
46 |
93 |
47 gps_.lat = s.mid(pos, 8); pos += 8; // DDMMmmm[NS] |
94 for (Fixes::const_iterator i = fixes_.begin(); |
48 gps_.lon = s.mid(pos, 9); pos += 9; // DDDMMmmm[EW] |
95 i != fixes_.end(); |
|
96 i++) { |
|
97 *altitude_[src] << QPointF(QTime().secsTo(i->time()), i->altitude(src)); |
|
98 } |
49 |
99 |
50 is3d_ = s.mid(pos, 1) == "A"; |
100 return *altitude_[src]; |
51 pos += 1; |
|
52 |
|
53 alt_[baro] = s.mid(pos, 5).toInt(); pos += 5; |
|
54 alt_[gps] = s.mid(pos, 5).toInt(); pos += 5; |
|
55 } |
101 } |