|
@@ -34,17 +34,64 @@ namespace artis {
|
|
|
namespace observer {
|
|
|
|
|
|
template<typename Time>
|
|
|
+struct EventIterator
|
|
|
+{
|
|
|
+ typedef artis::observer::Iterator<Time> iterator_type;
|
|
|
+
|
|
|
+ double begin(const std::vector <Iterator<Time>> &its) const
|
|
|
+ { return next_time(0, its); }
|
|
|
+
|
|
|
+ iterator_type build(const typename View<Time>::Values &view) const
|
|
|
+ { return iterator_type(view); }
|
|
|
+
|
|
|
+ bool is_valid(double time, const iterator_type &it) const
|
|
|
+ { return (*it).first == time; }
|
|
|
+
|
|
|
+ double next_time(double /* time */, const std::vector <Iterator<Time>> &its) const
|
|
|
+ {
|
|
|
+ double min = std::numeric_limits<double>::max();
|
|
|
+
|
|
|
+ for (const auto &it: its) {
|
|
|
+ if (min > (*it).first) {
|
|
|
+ min = (*it).first;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return min;
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+template<typename Time>
|
|
|
+struct TimedIterator
|
|
|
+{
|
|
|
+ typedef artis::observer::DiscreteTimeIterator<Time> iterator_type;
|
|
|
+ double _begin;
|
|
|
+ double _step;
|
|
|
+
|
|
|
+ double begin(const std::vector <DiscreteTimeIterator<Time>> &its) const
|
|
|
+ { return _begin; }
|
|
|
+
|
|
|
+ iterator_type build(const typename View<Time>::Values &view) const
|
|
|
+ { return iterator_type(view, _begin, _step); }
|
|
|
+
|
|
|
+ bool is_valid(double /* time */, const iterator_type & /* it */) const
|
|
|
+ { return true; }
|
|
|
+
|
|
|
+ double next_time(double time, const std::vector <DiscreteTimeIterator<Time>> & /* its */) const
|
|
|
+ { return time + _step; }
|
|
|
+};
|
|
|
+
|
|
|
+template<typename Time, typename Iterator>
|
|
|
class Output
|
|
|
{
|
|
|
public:
|
|
|
- Output(const Observer<Time> &observer)
|
|
|
+ Output(const Observer <Time> &observer)
|
|
|
: _observer(observer)
|
|
|
{}
|
|
|
|
|
|
virtual ~Output()
|
|
|
{}
|
|
|
|
|
|
- void operator()(double begin, double end, double step) const
|
|
|
+ void operator()(double /* begin */, double end, const Iterator &iterator) const
|
|
|
{
|
|
|
const typename Observer<Time>::Views &views = _observer.views();
|
|
|
|
|
@@ -52,7 +99,7 @@ public:
|
|
|
views.begin(); it != views.end(); ++it) {
|
|
|
std::ofstream o((boost::format("%1%.csv") % it->first).str());
|
|
|
const typename View<Time>::SelectorValues &values = it->second->values();
|
|
|
- std::vector<artis::observer::DiscreteTimeIterator<artis::common::DoubleTime>> its;
|
|
|
+ std::vector<typename Iterator::iterator_type> its;
|
|
|
|
|
|
o.precision(10);
|
|
|
// write header
|
|
@@ -64,22 +111,20 @@ public:
|
|
|
for (typename View<Time>::VariableValues::const_iterator itvv = vv.begin();
|
|
|
itvv != vv.end(); ++itvv) {
|
|
|
o << ";" << itvv->first;
|
|
|
- its.push_back(
|
|
|
- artis::observer::DiscreteTimeIterator<artis::common::DoubleTime>(
|
|
|
- itvv->second, begin, step));
|
|
|
+ its.push_back(iterator.build(itvv->second));
|
|
|
}
|
|
|
}
|
|
|
o << std::endl;
|
|
|
|
|
|
// write values
|
|
|
bool more = true;
|
|
|
- double t = begin;
|
|
|
+ double t = iterator.begin(its);
|
|
|
|
|
|
while (more and t <= end) {
|
|
|
more = false;
|
|
|
o << t;
|
|
|
for (auto &dtt: its) {
|
|
|
- if (dtt.has_next()) {
|
|
|
+ if (dtt.has_next() and iterator.is_valid(t, dtt)) {
|
|
|
o << ";" << (*dtt).second.to_string();
|
|
|
++dtt;
|
|
|
more = true;
|
|
@@ -88,13 +133,13 @@ public:
|
|
|
}
|
|
|
}
|
|
|
o << std::endl;
|
|
|
- t += step;
|
|
|
+ t = iterator.next_time(t, its);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private:
|
|
|
- const Observer<Time> &_observer;
|
|
|
+ const Observer <Time> &_observer;
|
|
|
};
|
|
|
|
|
|
}
|