Пример #1
0
void Diagramm::setItems(const DiagrammItemList &_items) {
    ListBuilder builder;
    m_Items = builder.buildList(_items);
    calculateScale();
    repaint();
}
Пример #2
0
void
test_converter_for(Converter<V> *conv)
{
    V v, w, x;

    /* Convert from/to Integer */
    v = conv->fromInteger(123);
    QVERIFY(conv->type(v) == Converter<V>::INTEGER);
    QVERIFY(conv->integer(v) == 123);

    /* Convert from/to Float */
    v = conv->fromFloating(42.23);
    QVERIFY(conv->type(v) == Converter<V>::FLOATING);
    QVERIFY(conv->floating(v) == 42.23);

    /* Convert from/to Bool */
    v = conv->fromBoolean(true);
    QVERIFY(conv->type(v) == Converter<V>::BOOLEAN);
    QVERIFY(conv->boolean(v));
    v = conv->fromBoolean(false);
    QVERIFY(conv->type(v) == Converter<V>::BOOLEAN);
    QVERIFY(!conv->boolean(v));

    /* Convert from/to String */
    v = conv->fromString("Hello World");
    QVERIFY(conv->type(v) == Converter<V>::STRING);
    QVERIFY(strcmp(conv->string(v), "Hello World") == 0);

    /* Convert from/to List */
    ListBuilder<V> *builder = conv->newList();
    v = conv->fromInteger(444);
    builder->append(v);
    v = conv->fromString("Hello");
    builder->append(v);
    v = builder->value();
    delete builder;
    ListIterator<V> *iterator = conv->list(v);
    QVERIFY(iterator->next(&w));
    QVERIFY(conv->type(w) == Converter<V>::INTEGER);
    QVERIFY(conv->integer(w) == 444);
    QVERIFY(iterator->next(&w));
    QVERIFY(conv->type(w) == Converter<V>::STRING);
    QVERIFY(strcmp(conv->string(w), "Hello") == 0);
    delete iterator;

    /* Convert from/to Dict */
    DictBuilder<V> *builder2 = conv->newDict();
    v = conv->fromBoolean(true);
    builder2->set(conv->fromString("a"), v);
    v = builder2->value();
    delete builder2;
    DictIterator<V> *iterator2 = conv->dict(v);
    QVERIFY(iterator2->next(&w, &x));
    QVERIFY(conv->type(w) == Converter<V>::STRING);
    QVERIFY(strcmp(conv->string(w), "a") == 0);
    QVERIFY(conv->type(x) == Converter<V>::BOOLEAN);
    QVERIFY(conv->boolean(x) == true);
    delete iterator2;

    delete conv;
}
Пример #3
0
BuildList::BuildList(const PackageManifest& manifest, const BuildOptions& opts):
    m_root_manifest(manifest)
{
    struct ListBuilder {
        struct Ent {
            const PackageManifest* package;
            bool    native;
            unsigned level;
            };
        ::std::vector<Ent>  m_list;

        void add_package(const PackageManifest& p, unsigned level, bool include_build, bool is_native)
        {
            TRACE_FUNCTION_F(p.name());
            // TODO: If this is a proc macro, set `is_native`
            // If the package is already loaded
            for(auto& ent : m_list)
            {
                if(ent.package == &p && ent.native == is_native && ent.level >= level)
                {
                    // NOTE: Only skip if this package will be built before we needed (i.e. the level is greater)
                    return ;
                }
                // Keep searching (might already have a higher entry)
            }
            m_list.push_back({ &p, is_native, level });
            add_dependencies(p, level, include_build, is_native);
        }
        void add_dependencies(const PackageManifest& p, unsigned level, bool include_build, bool is_native)
        {
            for (const auto& dep : p.dependencies())
            {
                if( dep.is_disabled() )
                {
                    continue ;
                }
                DEBUG(p.name() << ": Dependency " << dep.name());
                add_package(dep.get_package(), level+1, include_build, is_native);
            }

            if( p.build_script() != "" && include_build )
            {
                for(const auto& dep : p.build_dependencies())
                {
                    if( dep.is_disabled() )
                    {
                        continue ;
                    }
                    DEBUG(p.name() << ": Build Dependency " << dep.name());
                    add_package(dep.get_package(), level+1, true, true);
                }
            }
        }
        void sort_list()
        {
            ::std::sort(m_list.begin(), m_list.end(), [](const auto& a, const auto& b){ return a.level > b.level; });

            // Needed to deduplicate after sorting (`add_package` doesn't fully dedup)
            for(auto it = m_list.begin(); it != m_list.end(); )
            {
                auto it2 = ::std::find_if(m_list.begin(), it, [&](const auto& x){ return x.package == it->package; });
                if( it2 != it )
                {
                    DEBUG((it - m_list.begin()) << ": Duplicate " << it->package->name() << " - Already at pos " << (it2 - m_list.begin()));
                    it = m_list.erase(it);
                }
                else
                {
                    DEBUG((it - m_list.begin()) << ": Keep " << it->package->name() << ", level = " << it->level);
                    ++it;
                }
            }
        }
    };

    bool cross_compiling = (opts.target_name != nullptr);
    ListBuilder b;
    b.add_dependencies(manifest, 0, !opts.build_script_overrides.is_valid(), !cross_compiling);
    if( manifest.has_library() )
    {
        b.m_list.push_back({ &manifest, !cross_compiling, 0 });
    }

    // TODO: Add the binaries too?
    // - They need slightly different treatment.

    b.sort_list();


    // Move the contents of the above list to this class's list
    m_list.reserve(b.m_list.size());
    for(const auto& e : b.m_list)
    {
        m_list.push_back({ e.package, e.native, {} });
    }
    // Fill in all of the dependents (i.e. packages that will be closer to being buildable when the package is built)
    for(size_t i = 0; i < m_list.size(); i++)
    {
        const auto* cur = m_list[i].package;
        for(size_t j = i+1; j < m_list.size(); j ++)
        {
            const auto& p = *m_list[j].package;
            for( const auto& dep : p.dependencies() )
            {
                if( !dep.is_disabled() && &dep.get_package() == cur )
                {
                    m_list[i].dependents.push_back(static_cast<unsigned>(j));
                }
            }
            if( p.build_script() != "" && !opts.build_script_overrides.is_valid() )
            {
                for(const auto& dep : p.build_dependencies())
                {
                    if( !dep.is_disabled() && &dep.get_package() == cur )
                    {
                        m_list[i].dependents.push_back(static_cast<unsigned>(j));
                    }
                }
            }
        }
    }
}
Пример #4
0
void
test_converter_for(Converter<V> *conv)
{
    V v, w, x;

    /* Convert from/to Integer */
    v = conv->fromInteger(123);
    QVERIFY(conv->type(v) == Converter<V>::INTEGER);
    QVERIFY(conv->integer(v) == 123);

    /* Convert from/to Float */
    v = conv->fromFloating(42.23);
    QVERIFY(conv->type(v) == Converter<V>::FLOATING);
    QVERIFY(conv->floating(v) == 42.23);

    /* Convert from/to Bool */
    v = conv->fromBoolean(true);
    QVERIFY(conv->type(v) == Converter<V>::BOOLEAN);
    QVERIFY(conv->boolean(v));
    v = conv->fromBoolean(false);
    QVERIFY(conv->type(v) == Converter<V>::BOOLEAN);
    QVERIFY(!conv->boolean(v));

    /* Convert from/to String */
    v = conv->fromString("Hello World");
    QVERIFY(conv->type(v) == Converter<V>::STRING);
    QVERIFY(strcmp(conv->string(v), "Hello World") == 0);

    /* Convert from/to List */
    ListBuilder<V> *builder = conv->newList();
    v = conv->fromInteger(444);
    builder->append(v);
    v = conv->fromString("Hello");
    builder->append(v);
    v = builder->value();
    delete builder;
    ListIterator<V> *iterator = conv->list(v);
    QVERIFY(iterator->next(&w));
    QVERIFY(conv->type(w) == Converter<V>::INTEGER);
    QVERIFY(conv->integer(w) == 444);
    QVERIFY(iterator->next(&w));
    QVERIFY(conv->type(w) == Converter<V>::STRING);
    QVERIFY(strcmp(conv->string(w), "Hello") == 0);
    delete iterator;

    /* Convert from/to Dict */
    DictBuilder<V> *builder2 = conv->newDict();
    v = conv->fromBoolean(true);
    builder2->set(conv->fromString("a"), v);
    v = builder2->value();
    delete builder2;
    DictIterator<V> *iterator2 = conv->dict(v);
    QVERIFY(iterator2->next(&w, &x));
    QVERIFY(conv->type(w) == Converter<V>::STRING);
    QVERIFY(strcmp(conv->string(w), "a") == 0);
    QVERIFY(conv->type(x) == Converter<V>::BOOLEAN);
    QVERIFY(conv->boolean(x) == true);
    delete iterator2;

    /* Convert from/to generic PyObject */
    PyObject *obj = PyCapsule_New(conv, "test", NULL);
    v = conv->fromPyObject(PyObjectRef(obj));
    QVERIFY(conv->type(v) == Converter<V>::PYOBJECT);

    // Check if getting a new reference works
    PyObject *o = conv->pyObject(v).newRef();
    QVERIFY(o == obj);
    Py_DECREF(o);

    Py_CLEAR(obj);

    delete conv;
}