Пример #1
0
/** Reimplementation. */
void CLexiconKeyChooser::refreshContent() {
    if (m_modules.count() == 1) {
        m_widget->reset(&m_modules.first()->entries(), 0, true);
        //     qWarning("resetted");
    }
    else {
        using EntryMap = std::multimap<unsigned int, QStringList const *>;
        EntryMap entryMap;

        QListIterator<const CSwordLexiconModuleInfo*> mit(m_modules);
        while (mit.hasNext()) {
            const QStringList &entries = mit.next()->entries();
            entryMap.insert( std::make_pair(entries.count(), &entries) );
        }

        QStringList goodEntries; //The string list which contains the entries which are available in all modules

        EntryMap::iterator it = entryMap.begin(); //iterator to go thoigh all selected modules
        QStringList refEntries = *(it->second); //copy the items for the first time
        const QStringList *cmpEntries = (++it)->second; //list for comparision, starts with the second module in the map

        // Testing for refEntries being empty is not needed for the set union
        // of all keys, but is a good idea since it is being updated in the
        // loop.  It is necessary for set intersection and prevents a crash.
        while (it != entryMap.end() && (refEntries.begin() != refEntries.end())) {
            std::set_union(
                refEntries.begin(), --(refEntries.end()), //--end() is the last valid entry
                cmpEntries->begin(), --(cmpEntries->end()),
                std::back_inserter(goodEntries), //append valid entries to the end of goodEntries
                my_cmpEntries  //ci_cmpEntries is the comparision function
            );

            cmpEntries = ( ++it )->second; //this is a pointer to the string list of a new module

            /*
            * use the good entries for next comparision,
            * because the final list can only have the entries of goodEntries as maxiumum
            */
            refEntries = goodEntries;
        };

        m_widget->reset(goodEntries, 0, true); //write down the entries
    } //end of ELSE

}
Пример #2
0
void BackendSelection::Init(void)
{
    EntryMap::Iterator  it;
    EntryMap            ourMap;
    DeviceLocation     *pDevLoc;

    SSDPCacheEntries *pEntries = SSDPCache::Instance()->Find( gBackendURI );

    if (!pEntries)
    {
        VERBOSE(VB_GENERAL, "Found zero backends, bailing");
        return;
    }

    pEntries->AddRef();
    pEntries->Lock();

    EntryMap *pMap = pEntries->GetEntryMap();

    for (it = pMap->begin(); it != pMap->end(); ++it)
    {
        pDevLoc = (DeviceLocation *)*it;

        if (!pDevLoc)
            continue;

        pDevLoc->AddRef();
        ourMap.insert(pDevLoc->m_sUSN, pDevLoc);
    }

    pEntries->Unlock();
    pEntries->Release();

    for (it = ourMap.begin(); it != ourMap.end(); ++it)
    {
        pDevLoc = (DeviceLocation *)*it;
        AddItem(pDevLoc);   // this does a Release()
    }
}