Exemplo n.º 1
0
PyObject* ShapeInputHandler::getValue() const
{
    // Otherwise, OR together all of the input shapes
    // (or return NULL if any of them are invalid)
    PyObject* out = NULL;
    bool valid = true;
    PyObject* or_function = PyUnicode_FromString("__or__");
    for (auto i : in)
    {
        // We check to see if the pointer has been deleted or has been reduced
        // to a QObject (because destroyed is emitted before complete destruction,
        // see note above in SingleInputHandler::hasInput)
        if (i.isNull() || dynamic_cast<Datum*>(i->parent()) == NULL)
        {
            continue;
        }

        // Link source and target
        Q_ASSERT(dynamic_cast<Datum*>(i->parent()));
        Datum* source = static_cast<Datum*>(i->parent());
        Q_ASSERT(dynamic_cast<Datum*>(parent()));
        Datum* target = static_cast<Datum*>(parent());

        valid &= target->connectUpstream(source) && source->getValid();

        if (!valid)
            continue;

        if (out == NULL)
        {
            out = source->getValue();
            Py_INCREF(out);
        }
        else
        {
            PyObject* next = PyObject_CallMethodObjArgs(
                                 out, or_function, source->getValue(), NULL);
            Py_DECREF(out);
            out = next;

        }
    }

    Py_DECREF(or_function);
    if (valid)
    {
        return out;
    }
    else
    {
        Py_XDECREF(out);
        return NULL;
    }
}
Exemplo n.º 2
0
PyObject* SingleInputHandler::getValue() const
{
    Q_ASSERT(!in.isNull());

    Q_ASSERT(dynamic_cast<Datum*>(in->parent()));
    Datum* source = static_cast<Datum*>(in->parent());

    Q_ASSERT(dynamic_cast<Datum*>(parent()));
    Datum* target = static_cast<Datum*>(parent());

    if (target->connectUpstream(source) && source->getValid())
    {
        PyObject* v = source->getValue();
        Py_INCREF(v);
        return v;
    }
    else
    {
        return NULL;
    }
}