add RideFileInterval

Eventually, I'm going to remove interval as a member of RideFilePoint, and
only use RideFileIntervals.  But I have to rework a bunch of other code first,
so for now the two will coexist.
This commit is contained in:
Sean Rhea
2009-11-01 07:53:37 -05:00
parent 522824bb40
commit 1dc513e7a9
2 changed files with 60 additions and 0 deletions

View File

@@ -21,8 +21,51 @@
#include "Settings.h"
#include "Units.h"
#include <QtXml/QtXml>
#include <algorithm> // for std::lower_bound
#include <assert.h>
#define mark() \
{ \
addInterval(start, previous->secs + recIntSecs_, \
QString("%1").arg(interval)); \
++interval; \
start = point->secs; \
}
void
RideFile::fillInIntervals()
{
if (dataPoints_.empty())
return;
intervals_.clear();
double start = 0.0;
int interval = dataPoints().first()->interval;
const RideFilePoint *point, *previous;
foreach (point, dataPoints()) {
if (point->interval != interval)
mark();
previous = point;
}
mark();
}
struct ComparePoints {
bool operator()(const RideFilePoint *p1, const RideFilePoint *p2) {
return p1->secs < p2->secs;
}
};
int
RideFile::intervalBegin(const RideFileInterval &interval) const
{
RideFilePoint p;
p.secs = interval.start;
QVector<RideFilePoint*>::const_iterator i = std::lower_bound(
dataPoints_.begin(), dataPoints_.end(), &p, ComparePoints());
assert(i != dataPoints_.end());
return i - dataPoints_.begin();
}
void RideFile::writeAsCsv(QFile &file, bool bIsMetric) const
{

View File

@@ -63,6 +63,15 @@ struct RideFileDataPresent
kph(false), nm(false), watts(false), alt(false), interval(false) {}
};
struct RideFileInterval
{
double start, stop;
QString name;
RideFileInterval() : start(0.0), stop(0.0) {}
RideFileInterval(double start, double stop, QString name) :
start(start), stop(stop), name(name) {}
};
class RideFile
{
private:
@@ -72,6 +81,7 @@ class RideFile
QVector<RideFilePoint*> dataPoints_;
RideFileDataPresent dataPresent;
QString deviceType_;
QList<RideFileInterval> intervals_;
public:
@@ -99,6 +109,13 @@ class RideFile
double kph, double nm, double watts, double alt,
int interval, double bs=0.0);
const QList<RideFileInterval> &intervals() const { return intervals_; }
void addInterval(double start, double stop, const QString &name) {
intervals_.append(RideFileInterval(start, stop, name));
}
void fillInIntervals();
int intervalBegin(const RideFileInterval &interval) const;
void writeAsCsv(QFile &file, bool bIsMetric) const;
void resetDataPresent();