|
@@ -40,7 +40,7 @@ public:
|
|
typedef std::map<std::string, View<Time> *> Views;
|
|
typedef std::map<std::string, View<Time> *> Views;
|
|
|
|
|
|
Observer(const common::Model<Time> *model)
|
|
Observer(const common::Model<Time> *model)
|
|
- : _step(0), _model(model) {}
|
|
|
|
|
|
+ : _step(0), _model(model), _last_time(0), _init(false) {}
|
|
|
|
|
|
virtual ~Observer() {
|
|
virtual ~Observer() {
|
|
for (typename Views::iterator it = _views.begin(); it != _views.end(); ++it) {
|
|
for (typename Views::iterator it = _views.begin(); it != _views.end(); ++it) {
|
|
@@ -54,13 +54,13 @@ public:
|
|
}
|
|
}
|
|
|
|
|
|
Views *cloneViews() const {
|
|
Views *cloneViews() const {
|
|
- Views *v = new Views();
|
|
|
|
|
|
+ auto view = new Views();
|
|
|
|
|
|
for (typename Views::const_iterator it = _views.begin();
|
|
for (typename Views::const_iterator it = _views.begin();
|
|
it != _views.end(); ++it) {
|
|
it != _views.end(); ++it) {
|
|
- (*v)[it->first] = it->second->clone();
|
|
|
|
|
|
+ (*view)[it->first] = it->second->clone();
|
|
}
|
|
}
|
|
- return v;
|
|
|
|
|
|
+ return view;
|
|
}
|
|
}
|
|
|
|
|
|
const View<Time> &view(const std::string &name) const {
|
|
const View<Time> &view(const std::string &name) const {
|
|
@@ -69,18 +69,27 @@ public:
|
|
|
|
|
|
const Views &views() const { return _views; }
|
|
const Views &views() const { return _views; }
|
|
|
|
|
|
- void init() {}
|
|
|
|
|
|
+ void init() { }
|
|
|
|
|
|
- void observe(double t, double next_t) {
|
|
|
|
|
|
+ void observe(double t, double next_t, bool finish) {
|
|
if (_step == 0) {
|
|
if (_step == 0) {
|
|
observe(t);
|
|
observe(t);
|
|
|
|
+ _last_time = t;
|
|
} else {
|
|
} else {
|
|
- double time = std::floor((t + epsilon) / _step) * _step;
|
|
|
|
|
|
+ if (not _init) {
|
|
|
|
+ observe(t);
|
|
|
|
+ _last_time = t;
|
|
|
|
+ _init = true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ double next_last_time = std::floor((_last_time + _step + epsilon) / _step) * _step;
|
|
|
|
|
|
- while (time < next_t and std::abs(time - next_t) > epsilon) {
|
|
|
|
- observe(time);
|
|
|
|
- time += _step;
|
|
|
|
- time = std::floor((time + epsilon) / _step) * _step;
|
|
|
|
|
|
+ if (t <= next_last_time and (next_t > next_last_time or finish)) {
|
|
|
|
+ do {
|
|
|
|
+ observe(next_last_time);
|
|
|
|
+ _last_time = next_last_time;
|
|
|
|
+ next_last_time = std::floor((_last_time + _step + epsilon) / _step) * _step;
|
|
|
|
+ } while (t < next_last_time and next_t > next_last_time);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -105,6 +114,8 @@ private:
|
|
double _step;
|
|
double _step;
|
|
const common::Model<Time> *_model;
|
|
const common::Model<Time> *_model;
|
|
Views _views;
|
|
Views _views;
|
|
|
|
+ double _last_time;
|
|
|
|
+ bool _init;
|
|
};
|
|
};
|
|
|
|
|
|
}
|
|
}
|