Esempio n. 1
0
int CyPy_Task::setattro(const Py::String& name, const Py::Object& attr)
{

    auto nameStr = name.as_string();
    if (nameStr == "progress") {
        m_value->progress() = verifyNumeric(attr);
        return 0;
    }
    if (nameStr == "duration") {
        m_value->m_duration = verifyNumeric(attr);
        return 0;
    }
    if (nameStr == "tick_interval") {
        m_value->m_tick_interval = verifyNumeric(attr);
        return 0;
    }
    if (nameStr == "name") {
        m_value->name() = verifyString(attr);
        return 0;
    }

    auto element = CyPy_Element::asElement(attr);
    m_value->setAttr(nameStr, element);
    return 0;
}
Esempio n. 2
0
Py::Object CyPy_WorldTime::getattro(const Py::String& name)
{
    auto element = get_value()[name.as_string()];
    if (!element.empty()) {
        return Py::String(element);
    }
    return PythonExtensionBase::getattro(name);
}
Esempio n. 3
0
int CyPy_ElementMap::setattro(const Py::String& name, const Py::Object& attr)
{
    m_value.emplace(name.as_string(), CyPy_Element::asElement(attr));

    return 0;
}
Esempio n. 4
0
Py::Object CyPy_Task::getattro(const Py::String& name)
{
    auto nameStr = name.as_string();
    if (nameStr == "usage") {
        return CyPy_UsageInstance::wrap(m_value->m_usageInstance);
    }
    if (nameStr == "actor") {
        return CyPy_LocatedEntity::wrap(m_value->m_usageInstance.actor);
    }
    if (nameStr == "tool") {
        return CyPy_LocatedEntity::wrap(m_value->m_usageInstance.tool);
    }
//    if (nameStr == "targets") {
//        Py::List list(m_value->m_usageInstance.targets.size());
//        for (size_t i = 0; i < m_value->m_usageInstance.targets.size(); ++i) {
//            list[i] = CyPy_EntityLocation::wrap(m_value->m_usageInstance.targets[i]);
//        }
//        return list;
//    }
//    if (nameStr == "consumed") {
//        Py::List list(m_value->m_usageInstance.consumed.size());
//        for (size_t i = 0; i < m_value->m_usageInstance.consumed.size(); ++i) {
//            list[i] = CyPy_EntityLocation::wrap(m_value->m_usageInstance.consumed[i]);
//        }
//        return list;
//    }
    if (nameStr == "definition") {
        return CyPy_Usage::wrap(m_value->m_usageInstance.definition);
    }
    if (nameStr == "op") {
        return CyPy_Operation::wrap(m_value->m_usageInstance.op);
    }


    if (nameStr == "progress") {
        return Py::Float(m_value->progress());
    }
    if (nameStr == "duration") {
        if (!m_value->m_duration) {
            return Py::None();
        }
        return Py::Float(*m_value->m_duration);
    }
    if (nameStr == "tick_interval") {
        if (!m_value->m_tick_interval) {
            return Py::None();
        }
        return Py::Float(*m_value->m_tick_interval);
    }
    if (nameStr == "name") {
        return Py::String(m_value->name());
    }
    Atlas::Message::Element val;
    if (m_value->getAttr(name, val) == 0) {
        if (val.isNone()) {
            return Py::None();
        } else {
            return CyPy_Element::wrap(val);
        }
    }

    return PythonExtensionBase::getattro(name);
}