当前位置: 首页>>代码示例>>C++>>正文


C++ Hash::contains方法代码示例

本文整理汇总了C++中Hash::contains方法的典型用法代码示例。如果您正苦于以下问题:C++ Hash::contains方法的具体用法?C++ Hash::contains怎么用?C++ Hash::contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Hash的用法示例。


在下文中一共展示了Hash::contains方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: setValue

void GasInfoSettings::setValue(const QString & key, const QVariant & value)
{
    Hash* h = reg();
    if (h->contains(key))
    {
        (*h)[key] = value;
    }

    QSettings::setValue(key, value);
}
开发者ID:Quenii,项目名称:adcevm,代码行数:10,代码来源:gasinfosettings.cpp

示例2: archivePeriodF

uint GasInfoSettings::archivePeriodF()
{
    Hash* h = reg();
    if (!h->contains(archivePeriodKey))
    {
        (*h)[archivePeriodKey] = GasInfoSettings().archivePeriod();
    }

    return (*h)[archivePeriodKey].toInt();
}
开发者ID:Quenii,项目名称:adcevm,代码行数:10,代码来源:gasinfosettings.cpp

示例3: loadConfiguration

void SDLApp::loadConfiguration(int argc, char** argv) {
   const char* config_file = "config/config.txt";
   if (argc > 1) {
      config_file = argv[1];
   }
   std::ifstream fin(config_file, std::ios::in);
   
   Tokenizer tok(&fin);
   Parser parser(&tok);

   tok.nextToken();
   Hash *h = parser.readValue()->getHash();
   int width = h->getInteger("width");
   int height = h->getInteger("height");

   int threadCount = h->getInteger("threads");
   int boxw = h->getInteger("boxWidth");
   int boxh = h->getInteger("boxHeight");

   surface = SDL_SetVideoMode(width, height, 24, SDL_HWSURFACE | SDL_DOUBLEBUF);
   if (surface == NULL) {
		fprintf(stderr, "Couldn't set video mode: %s\n", SDL_GetError());
		SDL_Quit();
		exit(2);
	}

   setupCamera(h->getString("camera"), width, height);
   camera->setSurface(surface);
   camera->setThreadParameters(threadCount, boxw, boxh);

   if(h->contains("mesh")) {
      MeshManager::instance().loadMeshes(h->getString("mesh"));
   }

   LightManager::instance().loadLights(h->getString("lights"));
   GeometryManager::instance().loadObjects(h->getString("objects"));

   if(h->contains("animation")) {
      animation = new Animation(camera, surface);
      animation->setup(h->getString("animation"));
   }
}
开发者ID:dicta,项目名称:ray,代码行数:42,代码来源:SDLApp.cpp

示例4: reg

double GasInfoSettings::h2sAlarmThresF()
{
    Hash* h = reg();
    if (!h->contains(h2sAlarmThresKey))
    {
        GasInfoSettings settings;
        (*h)[h2sAlarmThresKey] = settings.h2sAlarmThres();
    }

    return  (*h)[h2sAlarmThresKey].toDouble();
}
开发者ID:Quenii,项目名称:adcevm,代码行数:11,代码来源:gasinfosettings.cpp

示例5: activeIntervalF

int GasInfoSettings::activeIntervalF()
{
    Hash* h = reg();
    if (!h->contains(activeIntervalKey))
    {
        GasInfoSettings settings;
        (*h)[activeIntervalKey] = settings.activeInterval();
    }

    return  (*h)[activeIntervalKey].toInt();
}
开发者ID:Quenii,项目名称:adcevm,代码行数:11,代码来源:gasinfosettings.cpp

示例6: terminalAlarmWindowOpenF

bool GasInfoSettings::terminalAlarmWindowOpenF(int id)
{
    QString key = terminalAlarmWindowOpenKey(id);

    Hash* h = reg();

    if (!h->contains(key))
    {
        (*h)[key] = false;
    }

     return   (*h)[key].toBool();
}
开发者ID:Quenii,项目名称:adcevm,代码行数:13,代码来源:gasinfosettings.cpp

示例7: replaceVariables

QString RpmBuildPlugin::replaceVariables(const QString &str, const Hash &variables) const
{
    const int size = str.size();
    QString result;

    for (int i = 0; i < size; i++)
    {
        QString toAppend(str[i]);

        if ( i < (size - static_cast<int>(sizeof("__a__"))) )  // enought chars to create shortest variable?
        {
            if (str[i] == '_' && str[i + 1] == '_')  //prefix matches? (__)
            {
                const int j = i + 2;
                i = j;                               //jump over prefix
                toAppend += '_';

                while ( (i + 1) < size && (str[i] != '_' || str[i + 1] != '_') )  //wait for suffix (__)
                    toAppend += str[i++];

                if (i + 1 < size && str[i] == '_' && str[i + 1] == '_')
                {
                    toAppend += "__";
                    i++;

                    //we got it!
                    const int k = i - 2;  //name without suffix

                    const QString varName = str.mid(j, k - j + 1);

                    if (variables.contains(varName))
                    {
                        toAppend = variables[varName];
                        debug(DebugLevel::Info) << "Variable \"" << varName << "\" used in spec file. (value = \"" << variables[varName] << "\")";
                    }
                    else
                        debug(DebugLevel::Warning) << "Unknown variable \"" << varName << "\" used in spec file.";
                }
            }
        }

        result.append(toAppend);
    }

    return result;
}
开发者ID:Kicer86,项目名称:builder,代码行数:46,代码来源:rpmbuildplugin.cpp

示例8: printMemStats

void FW::printMemStats(void)
{
#if FW_MEM_DEBUG
    // Create snapshot of the alloc list.

    s_lock.enter();
    AllocHeader* first = NULL;
    for (AllocHeader* src = s_memAllocs.next; src != &s_memAllocs; src = src->next)
    {
        AllocHeader* alloc = (AllocHeader*)::malloc(sizeof(AllocHeader));
        *alloc = *src;
        alloc->next = first;
        first = alloc;
    }
    s_lock.leave();

    // Calculate total size per owner.

    Hash<String, S64> owners;
    for (AllocHeader* alloc = first; alloc;)
    {
        if (!owners.contains(alloc->ownerID))
            owners.add(alloc->ownerID, 0);
        owners[alloc->ownerID] += alloc->size;

        AllocHeader* next = alloc->next;
        ::free(alloc);
        alloc = next;
    }

    // Print.

    printf("\n");
    printf("%-32s%.2f\n", "Memory usage / megs", (F32)s_memoryUsed * exp2(-20));
    for (int slot = owners.firstSlot(); slot != -1; slot = owners.nextSlot(slot))
    {
        const HashEntry<String, S64>& entry = owners.getSlot(slot);
        printf("  %-30s%-12.2f%.0f%%\n",
            entry.key.getPtr(),
            (F32)entry.value * exp2(-20),
            (F32)entry.value / (F32)s_memoryUsed * 100.0f);
    }
    printf("\n");
#endif
}
开发者ID:AllioNicholas,项目名称:CG_AS3,代码行数:45,代码来源:Defs.cpp

示例9: downscaleTextures

void App::downscaleTextures(MeshBase* mesh)
{
    FW_ASSERT(mesh);
    Hash<const Image*, Texture> hash;
    for (int submeshIdx = 0; submeshIdx < mesh->numSubmeshes(); submeshIdx++)
    for (int textureIdx = 0; textureIdx < MeshBase::TextureType_Max; textureIdx++)
    {
        Texture& tex = mesh->material(submeshIdx).textures[textureIdx];
        if (tex.exists())
        {
            const Image* orig = tex.getImage();
            if (!hash.contains(orig))
            {
                Image* scaled = orig->downscale2x();
                hash.add(orig, (scaled) ? Texture(scaled, tex.getID()) : tex);
            }
            tex = hash.get(orig);
        }
    }
}
开发者ID:Zerphed,项目名称:advanced-computer-graphics-course,代码行数:20,代码来源:App.cpp

示例10: malloc

void* FW::malloc(size_t size)
{
    FW_ASSERT(size >= 0);

#if FW_MEM_DEBUG
    s_lock.enter();

    AllocHeader* alloc = (AllocHeader*)::malloc(sizeof(AllocHeader) + size);
    if (!alloc)
        fail("Out of memory!");

    void* ptr           = alloc + 1;
    alloc->prev         = s_memAllocs.prev;
    alloc->next         = &s_memAllocs;
    alloc->prev->next   = alloc;
    alloc->next->prev   = alloc;
    alloc->size         = size;
    alloc->ownerID      = "Uncategorized";
    s_memoryUsed        += size;

    if (!s_memPushingOwner)
    {
        U32 threadID = Thread::getID();
        if (s_memOwnerStacks.contains(threadID) && s_memOwnerStacks[threadID].getSize())
               alloc->ownerID = s_memOwnerStacks[threadID].getLast();
    }

    s_lock.leave();

#else
    void* ptr = ::malloc(size);
    if (!ptr)
        fail("Out of memory!");

    s_lock.enter();
    s_memoryUsed += _msize(ptr);
    s_lock.leave();
#endif

    return ptr;
}
开发者ID:AllioNicholas,项目名称:CG_AS3,代码行数:41,代码来源:Defs.cpp

示例11: exportWavefrontMesh

void FW::exportWavefrontMesh(BufferedOutputStream& stream, const MeshBase* mesh, const String& fileName)
{
    FW_ASSERT(mesh);
    Mesh<VertexPNT> pnt(*mesh);

    // Extract base name.

    String dirName = fileName.getDirName();
    String baseName = fileName.getFileName();
    int idx = baseName.indexOf('.');
    if (idx != -1)
        baseName = baseName.substring(0, idx);

    // Write OBJ file.

    if (baseName.getLength())
    {
        stream.writef("mtllib %s.mtl\n", baseName.getPtr());
        stream.writef("\n");
    }

    for (int i = 0; i < pnt.numVertices(); i++)
    {
        const VertexPNT& v = pnt.vertex(i);
        stream.writef("v %g %g %g\n", v.p.x, v.p.y, v.p.z);
    }
    stream.writef("\n");

    for (int i = 0; i < pnt.numVertices(); i++)
    {
        const VertexPNT& v = pnt.vertex(i);
        stream.writef("vt %g %g\n", v.t.x, 1.0f - v.t.y);
    }
    stream.writef("\n");

    for (int i = 0; i < pnt.numVertices(); i++)
    {
        const VertexPNT& v = pnt.vertex(i);
        stream.writef("vn %g %g %g\n", v.n.x, v.n.y, v.n.z);
    }

    for (int i = 0; i < pnt.numSubmeshes(); i++)
    {
        stream.writef("\n");
        if (baseName.getLength())
            stream.writef("usemtl %d\n", i);

        const Array<Vec3i>& tris = pnt.indices(i);
        for (int j = 0; j < tris.getSize(); j++)
        {
            Vec3i v = tris[j] + 1;
            stream.writef("f %d/%d/%d %d/%d/%d %d/%d/%d\n",
                v.x, v.x, v.x,
                v.y, v.y, v.y,
                v.z, v.z, v.z);
        }
    }

    // No base name => do not write materials.

    if (!baseName.getLength())
        return;

    // Hash textures and determine file names.

    Hash<const Image*, String> texImageHash;
    Set<String> texNameSet;

    for (int i = 0; i < pnt.numSubmeshes(); i++)
    {
        const MeshBase::Material& mat = pnt.material(i);
        for (int j = 0; j < MeshBase::TextureType_Max; j++)
        {
            const Texture& tex = mat.textures[j];
            if (!tex.exists() || texImageHash.contains(tex.getImage()))
                continue;

            // Extract name from ID.

            String name = tex.getID().getFileName();
            int idx = name.indexOf('.');
            if (idx != -1)
                name = name.substring(0, idx);

            // No name => generate one.

            if (!name.getLength())
                name = sprintf("tex%d", texImageHash.getSize());

            // Ensure that the name is unique.

            String oldName = name;
            for (int k = 0; texNameSet.contains(name); k++)
                name = sprintf("%s_%d", oldName.getPtr(), k);

            // Append format postfix.

            name += ".png";

            // Record.
//.........这里部分代码省略.........
开发者ID:AllioNicholas,项目名称:CG_AS1,代码行数:101,代码来源:MeshWavefrontIO.cpp

示例12: QVERIFY


//.........这里部分代码省略.........
            hash2.remove(0);
            QVERIFY(hash2.size() == 1);
            hash2.remove(2);
            QVERIFY(hash2.size() == 0);
            QVERIFY(hash.size() == 2);
        }

        hash.detach();

        {
            Hash::iterator it1 = hash.find(1);
            QVERIFY(it1 != hash.end());

            Hash::iterator it2 = hash.find(0);
            QVERIFY(it2 != hash.begin());
            QVERIFY(it2 == hash.end());

            *it1 = monde;
            QVERIFY(*it1 == monde);
            QVERIFY(hash[1] == monde);

            *it1 = hello;
            QVERIFY(*it1 == hello);
            QVERIFY(hash[1] == hello);

            hash[1] = monde;
            QVERIFY(it1.key() == 1);
            QVERIFY(it1.value() == monde);
            QVERIFY(*it1 == monde);
            QVERIFY(hash[1] == monde);

            hash[1] = hello;
            QVERIFY(*it1 == hello);
            QVERIFY(hash[1] == hello);
        }

        {
            const Hash hash2 = hash;

            Hash::const_iterator it1 = hash2.find(1);
            QVERIFY(it1 != hash2.end());
            QVERIFY(it1.key() == 1);
            QVERIFY(it1.value() == hello);
            QVERIFY(*it1 == hello);

            Hash::const_iterator it2 = hash2.find(2);
            QVERIFY(it1 != it2);
            QVERIFY(it1 != hash2.end());
            QVERIFY(it2 != hash2.end());

            int count = 0;
            it1 = hash2.begin();
            while (it1 != hash2.end()) {
                count++;
                ++it1;
            }
            QVERIFY(count == 2);

            count = 0;
            it1 = hash.begin();
            while (it1 != hash.end()) {
                count++;
                ++it1;
            }
            QVERIFY(count == 2);
        }

        {
            QVERIFY(hash.contains(1));
            QVERIFY(hash.contains(2));
            QVERIFY(!hash.contains(0));
            QVERIFY(!hash.contains(3));
        }

        {
            QVERIFY(hash.value(1) == hello);
            QVERIFY(hash.value(2) == world);
            QVERIFY(hash.value(3) == 0);
            QVERIFY(hash.value(1, allo) == hello);
            QVERIFY(hash.value(2, allo) == world);
            QVERIFY(hash.value(3, allo) == allo);
            QVERIFY(hash.value(0, monde) == monde);
        }

        {
            QHash<int,Foo> hash;
            for (int i = 0; i < 10; i++)
                hash.insert(i, Foo());
            QVERIFY(Foo::count == 10);
            hash.remove(7);
            QVERIFY(Foo::count == 9);

        }
        QVERIFY(Foo::count == 0);
        {
            QHash<int, int*> hash;
            QVERIFY(((const QHash<int,int*>*) &hash)->operator[](7) == 0);
        }
    }
}
开发者ID:husninazer,项目名称:qt,代码行数:101,代码来源:tst_qhash.cpp

示例13: solveVariables

RpmBuildPlugin::Hash RpmBuildPlugin::solveVariables(const List &variables,         //variables to solve
                                                    const List &constants          //constants (solved)
                                                   ) const
{
    Hash hash;

    append(hash, constants);    //fill list of solved constants/variables with constants

    std::function<bool(const Pair &var)> resolveVariable;

    resolveVariable = [&](const Pair &var) -> bool
    {

        auto error = [&](const QString &variable, const QString &value, const QString &message)
        {
            debug(DebugLevel::Error) << "Could not resolve variable \"" << variable << "\""
                                     << "with value \"" << value << "\""
                                     << ". Error message: " << message;
        };

        assert(hash.contains(var.first) == false);

        //check first char of value
        if (var.second.size() == 0)
            hash[var.first] = var.second;
        else
        {
            const char operation = var.second[0].toAscii() ;

            switch (operation)
            {
                case '=':       //just use variable's value
                    hash[var.first] = replaceVariables(var.second.mid(1), hash);   //do not use first char which is '='
                    break;

                case 'r':       //regexp
                {
                    //Format for this operation:
                    //  "r:expression:regexp:result"
                    // ie: "r:abc:a(.*):_%1_" will return "_bc_".  (%1 is equivalent of \1)
                    // This operation is +- equivalent of:
                    // echo $expression | sed -e "s/$regexp/$result/"
                    // Instead of ":" as separator, any other char may be used.

                    const QString value = var.second.mid(1);   //all chars except 1. char
                    const size_t size = value.size();
                    if (size >= sizeof(":::"))                 //minimal regexp is: ":::"
                    {
                        const QString solvedValue = replaceVariables(value, hash);  //replace all variables with theirs values
                        const char splitter = solvedValue[0].toAscii();  //use first char as splitter

                        //do splitting
                        const QStringList regexpParts = solvedValue.mid(1).split(splitter);  //ommit first ':'

                        //we are expecting 3 parts
                        if (regexpParts.size() == 3)
                        {
                            QRegExp regexp(regexpParts[1]);        //second part is a pattern

                            if (regexp.exactMatch(regexpParts[0])) //enter string to be matched (first part)
                            {
                                //now try to commit matched expression to result
                                const QStringList captured = regexp.capturedTexts();  //list of captured texts "(.*)"
                                QString result = regexpParts[2];

                                for (int i = 1; i < captured.size(); i++)
                                {
                                    //this operation will replace each "%n" in result part of regexp with corresponding captured text.
                                    //This is why we use %n instead of \n, as %n is used by QString algorithms to replace args
                                    result = result.arg(captured[i]);
                                }

                                hash[var.first] = result;
                            }
                            else
                                error(var.first, var.second, "Could not match regular expression.");
                        }
                        else
                            error(var.first, var.second,
                                  QString("Variable's value should consist of 3 parts, but %1 were found.")
                                  .arg(regexpParts.size()));
                    }
                    else
                        error(var.first, var.second, "Variable's value is too short even for simples regular expression.");
                }
                break;

                default:
                    debug(DebugLevel::Error) << "unknown variable operator: \"" << operation << "\"";
                    break;
            }
        }

        return true;
    };

    for (const Pair &var: variables)
    {
        //try to resolve value

//.........这里部分代码省略.........
开发者ID:Kicer86,项目名称:builder,代码行数:101,代码来源:rpmbuildplugin.cpp


注:本文中的Hash::contains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。