|
@@ -46,6 +46,8 @@ public:
|
|
|
typedef std::vector <std::pair<double, common::Value>> Values;
|
|
|
typedef std::map <std::string, Values> VariableValues;
|
|
|
typedef std::map <std::string, VariableValues> SelectorValues;
|
|
|
+ template<typename W>
|
|
|
+ using ValueVector = std::vector <std::pair<double, W>>;
|
|
|
|
|
|
enum vars
|
|
|
{
|
|
@@ -82,33 +84,6 @@ public:
|
|
|
return v;
|
|
|
}
|
|
|
|
|
|
-// double
|
|
|
-// get(double t, const std::string& selector_name, const std::string& variable_name) const
|
|
|
-// {
|
|
|
-// SelectorValues::const_iterator it = _values.find(selector_name);
|
|
|
-//
|
|
|
-// if (it != _values.end()) {
|
|
|
-// VariableValues::const_iterator itp = it->second.find(variable_name);
|
|
|
-//
|
|
|
-// if (itp != it->second.end()) {
|
|
|
-// Values::const_iterator itv = itp->second.begin();
|
|
|
-//
|
|
|
-// while (itv != itp->second.end() and itv->first < t) {
|
|
|
-// ++itv;
|
|
|
-// }
|
|
|
-// if (itv != itp->second.end()) {
|
|
|
-// // TODO: to improve
|
|
|
-// return boost::lexical_cast<double>(itv->second);
|
|
|
-// } else {
|
|
|
-// return 0;
|
|
|
-// }
|
|
|
-// } else {
|
|
|
-// return 0;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// return 0;
|
|
|
-// }
|
|
|
-
|
|
|
const Values &
|
|
|
get(const std::string &selector_name, const std::string &variable_name) const
|
|
|
{
|
|
@@ -123,7 +98,36 @@ public:
|
|
|
assert(false);
|
|
|
}
|
|
|
} else {
|
|
|
- assert(false);
|
|
|
+ throw std::range_error("selector name not found");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ template<typename W>
|
|
|
+ ValueVector<W>
|
|
|
+ get(const std::string &selector_name, const std::string &variable_name) const
|
|
|
+ {
|
|
|
+ SelectorValues::const_iterator it = _values.find(selector_name);
|
|
|
+
|
|
|
+ if (it != _values.end()) {
|
|
|
+ VariableValues::const_iterator itv = it->second.find(variable_name);
|
|
|
+
|
|
|
+ if (itv != it->second.end()) {
|
|
|
+ const Values &values = itv->second;
|
|
|
+ ValueVector<W> result;
|
|
|
+
|
|
|
+ for (const auto &value: values) {
|
|
|
+ W data;
|
|
|
+
|
|
|
+ value.second(data);
|
|
|
+ result.push_back(std::make_pair(value.first, data));
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+
|
|
|
+ } else {
|
|
|
+ assert(false);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw std::range_error("selector name not found");
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -140,6 +144,29 @@ public:
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ template<typename W>
|
|
|
+ ValueVector<W> get(const std::string &selector_name) const
|
|
|
+ {
|
|
|
+ SelectorValues::const_iterator it = _values.find(selector_name);
|
|
|
+
|
|
|
+ if (it != _values.end()) {
|
|
|
+ assert(it->second.size() == 1);
|
|
|
+
|
|
|
+ const Values &values = it->second.begin()->second;
|
|
|
+ ValueVector<W> result;
|
|
|
+
|
|
|
+ for (const auto &value: values) {
|
|
|
+ W data;
|
|
|
+
|
|
|
+ value.second(data);
|
|
|
+ result.push_back(std::make_pair(value.first, data));
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ } else {
|
|
|
+ throw std::range_error("selector name not found");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
void observe(double time, const common::Model <common::DoubleTime> *model,
|
|
|
const std::string &selector_name, unsigned int variable_index)
|
|
|
{
|