本文整理汇总了C++中HashMap::contains方法的典型用法代码示例。如果您正苦于以下问题:C++ HashMap::contains方法的具体用法?C++ HashMap::contains怎么用?C++ HashMap::contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HashMap
的用法示例。
在下文中一共展示了HashMap::contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addAccessibilityNotificationHandler
void addAccessibilityNotificationHandler(AccessibilityNotificationHandler* notificationHandler)
{
if (!notificationHandler)
return;
#if PLATFORM(GTK)
JSGlobalContextRef jsContext = webkit_web_frame_get_global_context(mainFrame);
#else
JSContextRef jsContext = 0;
#endif
if (!jsContext)
return;
JSValueProtect(jsContext, notificationHandler->notificationFunctionCallback());
// Check if this notification handler is related to a specific element.
if (notificationHandler->platformElement()) {
if (notificationHandlers.contains(notificationHandler->platformElement())) {
JSValueUnprotect(jsContext, notificationHandlers.find(notificationHandler->platformElement())->value->notificationFunctionCallback());
notificationHandlers.remove(notificationHandler->platformElement());
}
notificationHandlers.add(notificationHandler->platformElement(), notificationHandler);
} else {
if (notificationHandlers.contains(GlobalNotificationKey)) {
JSValueUnprotect(jsContext, notificationHandlers.find(GlobalNotificationKey)->value->notificationFunctionCallback());
notificationHandlers.remove(GlobalNotificationKey);
}
notificationHandlers.add(GlobalNotificationKey, notificationHandler);
}
connectAccessibilityCallbacks();
}
示例2:
TEST(TestHashMapCopyConstructor, copyHashMapHasSameData)
{
HashMap first;
first.add("Ford", "Tang");
HashMap second = first;
ASSERT_EQ(first.size(), second.size());
ASSERT_EQ(first.contains("Ford"), second.contains("Ford"));
ASSERT_EQ(first.value("Ford"), second.value("Ford"));
}
示例3: testContains
static std::string testContains()
{
HashMap<std::size_t,double> map;
for(std::size_t ii = 1; ii != 100; ++ii) {
map[ii] = 0;
for(std::size_t jj = ii; jj; --jj) {
if( !map.contains(jj) ) {
return "Contains failed on inserted item.";
}
}
for(std::size_t jj = 101; jj != 150; ++jj) {
if( map.contains(jj) ) {
return "Contains failed on uninserted item.";
}
}
}
return "";
}
示例4: integerObjectReference
ObjectReference BinaryPropertyListPlan::integerObjectReference(int integer) const
{
ASSERT(integer >= 0);
if (!integer) {
ASSERT(m_integerZeroObjectReference != invalidObjectReference());
return m_integerZeroObjectReference;
}
ASSERT(m_integers.contains(integer));
return m_integers.get(integer);
}
示例5: adoptWK
TEST(WebKit2, WKRetainPtr)
{
WKRetainPtr<WKStringRef> string1 = adoptWK(WKStringCreateWithUTF8CString("a"));
WKRetainPtr<WKStringRef> string2 = adoptWK(WKStringCreateWithUTF8CString("a"));
WKRetainPtr<WKStringRef> string3 = adoptWK(WKStringCreateWithUTF8CString("a"));
WKRetainPtr<WKStringRef> string4 = adoptWK(WKStringCreateWithUTF8CString("a"));
HashMap<WKRetainPtr<WKStringRef>, int> map;
map.set(string2, 2);
map.set(string1, 1);
EXPECT_TRUE(map.contains(string1));
EXPECT_TRUE(map.contains(string2));
EXPECT_FALSE(map.contains(string3));
EXPECT_FALSE(map.contains(string4));
EXPECT_EQ(1, map.get(string1));
EXPECT_EQ(2, map.get(string2));
}
示例6: forClipboard
DataObjectGtk* DataObjectGtk::forClipboard(GtkClipboard* clipboard)
{
static HashMap<GtkClipboard*, RefPtr<DataObjectGtk> > objectMap;
if (!objectMap.contains(clipboard)) {
RefPtr<DataObjectGtk> dataObject = DataObjectGtk::create();
objectMap.set(clipboard, dataObject);
return dataObject.get();
}
HashMap<GtkClipboard*, RefPtr<DataObjectGtk> >::iterator it = objectMap.find(clipboard);
return it->value.get();
}
示例7:
// Test string version.
TEST(HashTest, STRINGHash) {
using namespace eoaix;
HashMap<std::string, TestKey> htable;
TestKey t1(1, "1str");
TestKey t2(2, "2str");
TestKey t4(4, "4str");
htable.insert(std::string("2"), t2);
htable.insert(std::string("1"), t1);
TestKey* t3 = htable.find_val(std::string("1"));
EXPECT_EQ(t3->toString(), t1.toString());
EXPECT_EQ(htable.contains(std::string("1")), true);
EXPECT_EQ(htable.contains(std::string("4")), false) << "htable.contains(t4) != true\n";
}
示例8: loadMappings
void Keymap::loadMappings(const HardwareInputSet *hwKeys) {
if (!_configDomain)
return;
if (_actions.empty())
return;
Common::KeymapperDefaultBindings *defaults = g_system->getKeymapperDefaultBindings();
HashMap<String, const HardwareInput *> mappedInputs;
List<Action*>::iterator it;
String prefix = KEYMAP_KEY_PREFIX + _name + "_";
for (it = _actions.begin(); it != _actions.end(); ++it) {
Action* ua = *it;
String actionId(ua->id);
String confKey = prefix + actionId;
String hwInputId = _configDomain->getVal(confKey);
bool defaulted = false;
// fall back to the platform-specific defaults
if (hwInputId.empty() && defaults) {
hwInputId = defaults->getDefaultBinding(_name, actionId);
if (!hwInputId.empty())
defaulted = true;
}
// there's no mapping
if (hwInputId.empty())
continue;
const HardwareInput *hwInput = hwKeys->findHardwareInput(hwInputId.c_str());
if (!hwInput) {
warning("HardwareInput with ID '%s' not known", hwInputId.c_str());
continue;
}
if (defaulted) {
if (mappedInputs.contains(hwInputId)) {
debug(1, "Action [%s] not falling back to hardcoded default value [%s] because the hardware input is in use", confKey.c_str(), hwInputId.c_str());
continue;
}
warning("Action [%s] fell back to hardcoded default value [%s]", confKey.c_str(), hwInputId.c_str());
}
mappedInputs.setVal(hwInputId, hwInput);
// map the key
ua->mapInput(hwInput);
}
}
示例9: deref
inline void CalculationValueMap::deref(unsigned handle)
{
ASSERT(m_map.contains(handle));
auto it = m_map.find(handle);
if (it->value.referenceCountMinusOne) {
--it->value.referenceCountMinusOne;
return;
}
// The adoptRef here is balanced by the leakRef in the insert member function.
Ref<CalculationValue> value { adoptRef(*it->value.value) };
m_map.remove(it);
}
示例10: customSerializeResolvingVariables
String CSSPrimitiveValue::customSerializeResolvingVariables(const HashMap<AtomicString, String>& variables) const
{
if (isVariableName() && variables.contains(m_value.string))
return variables.get(m_value.string);
if (CSSCalcValue* calcValue = cssCalcValue())
return calcValue->customSerializeResolvingVariables(variables);
if (Pair* pairValue = getPairValue())
return pairValue->serializeResolvingVariables(variables);
if (Rect* rectVal = getRectValue())
return rectVal->serializeResolvingVariables(variables);
if (Quad* quadVal = getQuadValue())
return quadVal->serializeResolvingVariables(variables);
if (CSSBasicShape* shapeValue = getShapeValue())
return shapeValue->serializeResolvingVariables(variables);
return customCssText();
}
示例11: setPluginLoadClientPolicy
void WebProcessPool::setPluginLoadClientPolicy(WebCore::PluginLoadClientPolicy policy, const String& host, const String& bundleIdentifier, const String& versionString)
{
#if ENABLE(NETSCAPE_PLUGIN_API)
HashMap<String, HashMap<String, uint8_t>> policiesByIdentifier;
if (m_pluginLoadClientPolicies.contains(host))
policiesByIdentifier = m_pluginLoadClientPolicies.get(host);
HashMap<String, uint8_t> versionsToPolicies;
if (policiesByIdentifier.contains(bundleIdentifier))
versionsToPolicies = policiesByIdentifier.get(bundleIdentifier);
versionsToPolicies.set(versionString, policy);
policiesByIdentifier.set(bundleIdentifier, versionsToPolicies);
m_pluginLoadClientPolicies.set(host, policiesByIdentifier);
#endif
sendToAllProcesses(Messages::WebProcess::SetPluginLoadClientPolicy(policy, host, bundleIdentifier, versionString));
}
示例12: constructFamilyFontFaces
static Vector<Ref<CSSFontFace>> constructFamilyFontFaces(const String& familyName, HashMap<String, Vector<Ref<CSSFontFace>>, CaseFoldingHash>& locallyInstalledFontFaces)
{
auto result = Vector<Ref<CSSFontFace>>();
ASSERT(!locallyInstalledFontFaces.contains(familyName));
Vector<FontTraitsMask> traitsMasks = FontCache::singleton().getTraitsInFamily(familyName);
if (!traitsMasks.isEmpty()) {
Vector<Ref<CSSFontFace>> faces = { };
for (auto mask : traitsMasks) {
Ref<CSSFontFace> face = CSSFontFace::create(mask, nullptr, true);
face->addSource(std::make_unique<CSSFontFaceSource>(familyName));
ASSERT(face->isValid());
faces.append(WTF::move(face));
}
locallyInstalledFontFaces.add(familyName, WTF::move(faces));
}
return result;
}
示例13: CSSStyleDeclaration
CSSMutableStyleDeclaration::CSSMutableStyleDeclaration(CSSRule* parent, const CSSProperty* const * properties, int numProperties)
: CSSStyleDeclaration(parent)
, m_node(0)
, m_strictParsing(!parent || parent->useStrictParsing())
#ifndef NDEBUG
, m_iteratorCount(0)
#endif
{
m_properties.reserveInitialCapacity(numProperties);
HashMap<int, bool> candidates;
for (int i = 0; i < numProperties; ++i) {
const CSSProperty *property = properties[i];
ASSERT(property);
bool important = property->isImportant();
if (candidates.contains(property->id())) {
if (!important && candidates.get(property->id()))
continue;
removeProperty(property->id(), false);
}
m_properties.append(*property);
candidates.set(property->id(), important);
}
}
示例14: mimeTypeForExtension
static String mimeTypeForExtension(const String& file)
{
static HashMap<String, String, CaseFoldingHash> extensionToMime;
if (extensionToMime.isEmpty()) {
extensionToMime.set("txt", "text/plain");
extensionToMime.set("html", "text/html");
extensionToMime.set("htm", "text/html");
extensionToMime.set("png", "image/png");
extensionToMime.set("jpeg", "image/jpeg");
extensionToMime.set("jpg", "image/jpeg");
extensionToMime.set("gif", "image/gif");
extensionToMime.set("ico", "image/x-icon");
extensionToMime.set("js", "text/javascript");
}
int dot = file.reverseFind('.');
String mime("text/plain");
if (dot != -1) {
String ext = file.substring(dot + 1);
if (extensionToMime.contains(ext))
mime = extensionToMime.get(ext);
}
return mime;
}
示例15:
static void testU32Map()
{
HashMap<U32, U32> map;
enum { maxI = 1024 * 1024 };
for(Uptr i = 0;i < maxI;++i)
{
errorUnless(!map.contains(U32(i)));
}
errorUnless(map.size() == 0);
for(Uptr i = 0;i < maxI;++i)
{
errorUnless(!map.contains(U32(i)));
errorUnless(!map.get(U32(i)));
errorUnless(map.add(U32(i),U32(i * 2)));
errorUnless(map.contains(U32(i)));
errorUnless(map.get(U32(i)));
errorUnless(*map.get(U32(i)) == U32(i * 2));
errorUnless(map.size() == i + 1);
}
for(Uptr i = 0;i < maxI;++i)
{
errorUnless(map.contains(U32(i)));
errorUnless(map.remove(U32(i)));
errorUnless(!map.contains(U32(i)));
errorUnless(map.size() == maxI - i - 1);
}
for(Uptr i = 0;i < maxI;++i)
{
errorUnless(!map.contains(U32(i)));
}
}