diff -r dfefb6003498 -r c55e1f2a4db4 igc.cc --- a/igc.cc Sun Jan 29 00:38:40 2012 +0100 +++ b/igc.cc Sun Jan 29 01:51:02 2012 +0100 @@ -1,5 +1,51 @@ #include "igc.h" +Fix::Fix(const QString &s) +{ + int pos = 0; + + time_ = QTime::fromString(s.mid(pos, 6), "hhmmss"); + pos += 6; + + gps_.lat = s.mid(pos, 8); pos += 8; // DDMMmmm[NS] + gps_.lon = s.mid(pos, 9); pos += 9; // DDDMMmmm[EW] + + is3d_ = s.mid(pos, 1) == "A"; + pos += 1; + + alt_[baro] = s.mid(pos, 5).toInt(); pos += 5; + alt_[gps] = s.mid(pos, 5).toInt(); pos += 5; +} + + +IGC::IGC() +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + : altitude_({0}) +#endif +{ +#ifndef __GXX_EXPERIMENTAL_CXX0X__ + memset(altitude_, 0, sizeof(altitude_)); +#endif +} + +IGC::IGC(QTextStream &s) +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + : altitude_({0}) +#endif +{ +#ifndef __GXX_EXPERIMENTAL_CXX0X__ + memset(altitude_, 0, sizeof(altitude_)); +#endif + read(s); +} + +IGC::~IGC() +{ + for (size_t i = 0; i < sizeof(altitude_)/sizeof(altitude_[0]); ++i) { + delete altitude_[i]; + } +} + void IGC::read(QTextStream &in) { while (!in.atEnd()) { @@ -37,19 +83,19 @@ } } -Fix::Fix(const QString &s) +const QVector& IGC::altitude(Fix::Source src) const { - int pos = 0; + + // optimization: if already allocated, return the allocated vector + if (altitude_[src]) return *altitude_[src]; - time_ = QTime::fromString(s.mid(pos, 6), "hhmmss"); - pos += 6; + altitude_[src] = new QVector; - gps_.lat = s.mid(pos, 8); pos += 8; // DDMMmmm[NS] - gps_.lon = s.mid(pos, 9); pos += 9; // DDDMMmmm[EW] + for (Fixes::const_iterator i = fixes_.begin(); + i != fixes_.end(); + i++) { + *altitude_[src] << QPointF(QTime().secsTo(i->time()), i->altitude(src)); + } - is3d_ = s.mid(pos, 1) == "A"; - pos += 1; - - alt_[baro] = s.mid(pos, 5).toInt(); pos += 5; - alt_[gps] = s.mid(pos, 5).toInt(); pos += 5; + return *altitude_[src]; }