1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-01-19 04:02:09 +01:00

Cleanup the remaining parser that stores temporary data

This commit is contained in:
Martin Tůma 2020-01-23 23:22:04 +01:00
parent d035a307d8
commit cb01c0b590
2 changed files with 26 additions and 23 deletions

View File

@ -96,7 +96,7 @@ static bool readARecord(const char *line, qint64 len)
return true; return true;
} }
bool IGCParser::readHRecord(const char *line, int len) bool IGCParser::readHRecord(CTX &ctx, const char *line, int len)
{ {
if (len < 11 || ::strncmp(line, "HFDTE", 5)) if (len < 11 || ::strncmp(line, "HFDTE", 5))
return true; return true;
@ -112,9 +112,9 @@ bool IGCParser::readHRecord(const char *line, int len)
return false; return false;
} }
_date = QDate(y + 2000 <= QDate::currentDate().year() ? 2000 + y : 1900 + y, ctx.date = QDate(y + 2000 <= QDate::currentDate().year()
m, d); ? 2000 + y : 1900 + y, m, d);
if (!_date.isValid()) { if (!ctx.date.isValid()) {
_errorString = "Invalid date"; _errorString = "Invalid date";
return false; return false;
} }
@ -122,8 +122,8 @@ bool IGCParser::readHRecord(const char *line, int len)
return true; return true;
} }
bool IGCParser::readBRecord(SegmentData &segment, const char *line, bool IGCParser::readBRecord(CTX &ctx, const char *line, int len,
int len) SegmentData &segment)
{ {
qreal lat, lon, ele; qreal lat, lon, ele;
QTime time; QTime time;
@ -152,20 +152,20 @@ bool IGCParser::readBRecord(SegmentData &segment, const char *line,
return false; return false;
} }
if (time < _time && !segment.isEmpty() if (time < ctx.time && !segment.isEmpty()
&& _date == segment.last().timestamp().date()) && ctx.date == segment.last().timestamp().date())
_date = _date.addDays(1); ctx.date = ctx.date.addDays(1);
_time = time; ctx.time = time;
Trackpoint t(Coordinates(lon, lat)); Trackpoint t(Coordinates(lon, lat));
t.setTimestamp(QDateTime(_date, _time, Qt::UTC)); t.setTimestamp(QDateTime(ctx.date, ctx.time, Qt::UTC));
t.setElevation(ele); t.setElevation(ele);
segment.append(t); segment.append(t);
return true; return true;
} }
bool IGCParser::readCRecord(RouteData &route, const char *line, int len) bool IGCParser::readCRecord(const char *line, int len, RouteData &route)
{ {
qreal lat, lon; qreal lat, lon;
@ -202,6 +202,7 @@ bool IGCParser::parse(QFile *file, QList<TrackData> &tracks,
qint64 len; qint64 len;
char line[76 + 2 + 1 + 1]; char line[76 + 2 + 1 + 1];
bool route = false, track = false; bool route = false, track = false;
CTX ctx;
_errorLine = 1; _errorLine = 1;
@ -225,28 +226,28 @@ bool IGCParser::parse(QFile *file, QList<TrackData> &tracks,
} }
} else { } else {
if (line[0] == 'H') { if (line[0] == 'H') {
if (!readHRecord(line, len)) if (!readHRecord(ctx, line, len))
return false; return false;
} else if (line[0] == 'C') { } else if (line[0] == 'C') {
if (route) { if (route) {
if (!readCRecord(routes.last() ,line, len)) if (!readCRecord(line, len, routes.last()))
return false; return false;
} else { } else {
route = true; route = true;
routes.append(RouteData()); routes.append(RouteData());
} }
} else if (line[0] == 'B') { } else if (line[0] == 'B') {
if (_date.isNull()) { if (ctx.date.isNull()) {
_errorString = "Missing date header"; _errorString = "Missing date header";
return false; return false;
} }
if (!track) { if (!track) {
tracks.append(TrackData()); tracks.append(TrackData());
tracks.last().append(SegmentData()); tracks.last().append(SegmentData());
_time = QTime(0, 0); ctx.time = QTime(0, 0);
track = true; track = true;
} }
if (!readBRecord(tracks.last().last(), line, len)) if (!readBRecord(ctx, line, len, tracks.last().last()))
return false; return false;
} }
} }

View File

@ -17,15 +17,17 @@ public:
int errorLine() const {return _errorLine;} int errorLine() const {return _errorLine;}
private: private:
bool readHRecord(const char *line, int len); struct CTX {
bool readBRecord(SegmentData &segment, const char *line, int len); QDate date;
bool readCRecord(RouteData &route, const char *line, int len); QTime time;
};
bool readHRecord(CTX &ctx, const char *line, int len);
bool readBRecord(CTX &ctx, const char *line, int len, SegmentData &segment);
bool readCRecord(const char *line, int len, RouteData &route);
int _errorLine; int _errorLine;
QString _errorString; QString _errorString;
QDate _date;
QTime _time;
}; };
#endif // IGCPARSER_H #endif // IGCPARSER_H