std::unique_ptr<vv::Value> observation(const vd::ObservationEvent & /*event*/) const override { auto ptr = std::unique_ptr<vv::Value>(vv::Tuple::create()); auto& t = ptr->toTuple(); if (INIT != m_state) { t.add(m_downthreshold); t.add(m_upthreshold); t.add(m_upthreshold - m_downthreshold); t.add(m_adapt_state); } return ptr; }
QList<ZVariant> ZVariant::toList() const { if(type() == Tuple) { QList<ZVariant> list; for(const ZVariant *val : toTuple()) { list << *val; } return list; } return qvariant_cast<QList<ZVariant>>(m_data->variant); }
InternalArgument execute(const std::vector<InternalArgument>& args) const { auto pri = get<0>(args); auto tuple = toTuple(get<1>(args), *printmonitor()); switch (value_) { case SET_TRUE: pri->makeTrueExactly(tuple); break; case SET_FALSE: pri->makeFalseExactly(tuple); break; case SET_UNKNOWN: pri->makeUnknownExactly(tuple); break; default: break; } return nilarg(); }
ZVariant ZVariant::operator[](const ZVariant &value) const { switch (m_data->type) { case List: { bool ok = false; const ZVariant &val = toList().value(value.toInt(&ok)); if(!ok) return ZVariant(); else return val; } case Tuple: { bool ok; const ZVariant &val = *toTuple().value(value.toInt(&ok)); if(!ok) return ZVariant(); else return val; } case String: { bool ok; int index = value.toInt(&ok); const QString &str = toString(); if(!ok || index >= str.size()) return QString(); else return QString(str.at(index)); } case Function: case Object: return toObject()->property(value.toString().toLatin1().constData()); default: return Undefined; } }