//============================================================================ // NCache::SetValue : Set a value. //---------------------------------------------------------------------------- void NCache::SetValue(const NCacheKey &theKey, NCacheValue *theValue) { // Validate our parameters NN_ASSERT(theValue->GetCost() >= 0); // Prepare to set if (HasKey(theKey)) RemoveKey(theKey); if (NeedsPurge()) Purge(); // Set the value mCache[theKey] = theValue; mCacheCost += theValue->GetCost(); theValue->SetAccessTime(); theValue->Retain(); }
inline void MoveKeyTo(const std::string &k, SVMap &other) { if (OK_LIKELY(HasKey(k))) { other.entrymap_[k] = std::move(this->entrymap_.at(k)); ClearKey(k); } }
string SDP::GetStreamName() { if (!HasKey(SDP_SESSION)) return ""; if (!(*this)[SDP_SESSION].HasKey(SDP_S)) return ""; return (string) (*this)[SDP_SESSION][SDP_S]; }
void ConfigFile::SetStringList(CTSTR lpSection, CTSTR lpKey, StringList &StrList) { while(HasKey(lpSection, lpKey)) Remove(lpSection, lpKey); for(unsigned int i=0; i<StrList.Num(); i++) AddString(lpSection, lpKey, StrList[i]); }
void ConfigFile::SetColorList(CTSTR lpSection, CTSTR lpKey, List<Color4> &ColorList) { while(HasKey(lpSection, lpKey)) Remove(lpSection, lpKey); for(unsigned int i=0; i<ColorList.Num(); i++) AddColor(lpSection, lpKey, ColorList[i]); }
void ConfigFile::SetFloatList(CTSTR lpSection, CTSTR lpKey, List<float> &FloatList) { while(HasKey(lpSection, lpKey)) Remove(lpSection, lpKey); for(unsigned int i=0; i<FloatList.Num(); i++) AddFloat(lpSection, lpKey, FloatList[i]); }
std::vector<plString> plKeysAndValues::GetAllValues(const plString & key) { std::vector<plString> result; if (HasKey(key)) for (Values::const_iterator vi=fKeys[key].begin(); vi!=fKeys[key].end(); ++vi) result.push_back(*vi); return result; }
void ConfigFile::SetIntList(CTSTR lpSection, CTSTR lpKey, List<int> &IntList) { while(HasKey(lpSection, lpKey)) Remove(lpSection, lpKey); for(unsigned int i=0; i<IntList.Num(); i++) AddInt(lpSection, lpKey, IntList[i]); }
ISkinObj* SSkinPool::GetSkin(LPCWSTR strSkinName) { if(!HasKey(strSkinName)) { return NULL; } return GetKeyObject(strSkinName); }
bool plKeysAndValues::AddValue(const std::string & key, const std::string & value, KAddValueMode mode) { switch (mode) { case kFailIfExists: if (HasKey(key)) return false; break; case kReplaceIfExists: if (HasKey(key)) RemoveKey(key); break; default: break; } fKeys[key.c_str()].push_front(value.c_str()); return true; }
std::vector<std::string> plKeysAndValues::GetAllValues(const std::string & key) { std::vector<std::string> result; xtl::istring xkey = key.c_str(); if (HasKey(key)) for (Values::const_iterator vi=fKeys[xkey].begin(); vi!=fKeys[xkey].end(); ++vi) result.push_back(vi->c_str()); return result; }
bool ConfigAPI::HasKey(const ConfigData &data, QString key) const { if (data.file.isEmpty() || data.section.isEmpty()) { LogWarning("ConfigAPI::HasKey: ConfigData does not have enough information (file, and section)."); return false; } return HasKey(data.file, data.section, key); }
LPCTSTR DuiStringPool::Get( UINT uID ) { m_strTmp=_T(""); if(HasKey(uID)) { m_strTmp=GetKeyObject(uID); BuildString(m_strTmp); } return m_strTmp; }
void execAttributesCheck() { auto c = TClass::GetClass("TestDictProperties"); for (auto dm: *c->GetListOfDataMembers()){ auto dmAM = static_cast<TDataMember*>(dm)->GetAttributeMap(); for (auto const key : {"mapping","persistency"}){ if (dmAM->HasKey(key)) std::cout << "Found property \"" << key << "\" and its value is " << dmAM->GetPropertyAsString(key) << "\n"; } } }
void Dictionary<TKey, TValue>::Add(const TKey &key, const TValue &value) { // if the key has already been added if (!dic_bAllowDuplicateKeys && HasKey(key)) { ASSERT(false); return; } // add it dic_saPairs.Push(new DictionaryPair<TKey, TValue>(key, value)); }
void DictionaryValue::SetWithoutPathExpansion(const std::string& key, Value* in_value) { // 如果值存在需要先删除, 因为拥有子对象的所有权. if(HasKey(key)) { DCHECK(dictionary_[key] != in_value); // 只是一个假设. delete dictionary_[key]; } dictionary_[key] = in_value; }
QVariant ConfigAPI::DeclareSetting(const QString &file, const QString §ion, const QString &key, const QVariant &defaultValue) { if (HasKey(file, section, key)) { return Read(file, section, key); } else { Write(file, section, key, defaultValue); return defaultValue; } }
pugi::xml_node SObjDefAttr::_GetDefAttribute(LPCWSTR pszClassName ) { if(!HasKey(pszClassName)) { LPCWSTR pszBaseClassName=SApplication::getSingleton().BaseClassNameFromClassName(pszClassName); if(!pszBaseClassName) return pugi::xml_node(); return _GetDefAttribute(pszBaseClassName); }else { return GetKeyObject(pszClassName); } }
PdfObject* PdfDictionary::GetKey( const PdfName & key ) { TIKeyMap it; if( HasKey( key ) ) { it = m_mapKeys.find( key ); return (*it).second; } return NULL; }
void Dictionary<TKey, TValue>::Add(const TKey &key, const TValue &value) { // if the key has already been added if(!dic_bAllowDuplicateKeys && HasKey(key)) { ASSERT(FALSE); return; } // add it dic_saKeys.Push() = key; dic_saValues.Push() = value; }
bool PdfDictionary::RemoveKey( const PdfName & identifier ) { if( HasKey( identifier ) ) { delete m_mapKeys[identifier]; m_mapKeys.erase( identifier ); m_bDirty = true; return true; } return false; }
LPCWSTR SWindowFactoryMgr::BaseClassNameFromClassName( LPCWSTR pszClassName ) { if(!HasKey(pszClassName)) { STraceW(L"BaseClassNameFromClassName, Warning: no window type:%s in SOUI!!",pszClassName); return NULL; } LPCWSTR pszBaseClassName=GetKeyObject(pszClassName)->SWindowBaseName(); if(!pszBaseClassName) return NULL; //注意,baseClassName可能与ClassName相同,为了避免死循环,这里需要判断一下。 if(wcscmp(pszBaseClassName,pszClassName)==0) return NULL; return pszBaseClassName; }
std::int64_t AudioService::getCurrentPlaybackTrackId() const { auto settingsValues = Windows::Storage::ApplicationData::Current->LocalSettings->Values; if (!settingsValues->HasKey(L"CurrentPlaybackTrackId")) { return -1; } auto box = dynamic_cast<Platform::IBox<std::int64_t>^> (settingsValues->Lookup(L"CurrentPlaybackTrackId")); if (!box) { return -1; } return box->Value; }
/** \fn Action::AddKey(const QString&) * \brief Add a key sequence to this action. * * We don't add empty keys nor duplicates, and cannot * add more than kMaximumNumberOfBindings. If any of * these restrictions are a problem we return false and * do not add the binding. * * \param key The key to add to the action. * \return true if the key was added otherwise, false. */ bool Action::AddKey(const QString &key) { if (key.isEmpty() || HasKey(key) || ((uint)m_keys.size() >= kMaximumNumberOfBindings)) { return false; } QString tmp = key; tmp.detach(); m_keys.push_back(tmp); return true; }
/** \fn Action::ReplaceKey(const QString&, const QString&) * \brief Replace a key. * \param newkey The new key. * \param oldkey The old key, which is being replaced. */ bool Action::ReplaceKey(const QString &newkey, const QString &oldkey) { // make sure that the key list doesn't already have the new key if (HasKey(newkey)) return false; int idx = m_keys.indexOf(oldkey); if (idx < 0) return false; QString tmp = newkey; tmp.detach(); m_keys[idx] = tmp; return true; }
api::TrackInfo AudioService::getCurrentPlaybackTrack() const { auto settingsValues = Windows::Storage::ApplicationData::Current->LocalSettings->Values; if (!settingsValues->HasKey(L"CurrentPlaybackTrack")) { api::TrackInfo ti; ti.id = -1; return ti; } else { auto jsonString = dynamic_cast<Platform::String^>(settingsValues->Lookup(L"CurrentPlaybackTrack")); tools::strings::WindowsWIStream stream(jsonString); auto jsonVal = web::json::value::parse(stream); return api::TrackInfo(jsonVal); } }
SWindow * SWindowFactoryMgr::CreateWindowByName( LPCWSTR pszClassName ) { if(!HasKey(pszClassName)) { STraceW(L"Warning: no window type:%s in SOUI!!",pszClassName); return NULL; } SWindow * pRet = GetKeyObject(pszClassName)->NewWindow(); SASSERT(pRet); if(pRet) { SetSwndDefAttr(pRet); } return pRet; }
const Data& Data::operator[](const Data& key) const { if(!IsList()) throw Error::Invalid("Data::operator[](const Data&)","Not a dictionary."); if(!HasKey(key)) return Null; bool is_old; size_t i; i=KeyLookup(key,is_old); return ((const cow_vector<Data>&)(vec))[size_t(i)][1]; }
char KeyWait(int col, int row) { // Clear keyboard and keywait get_console(1); unsigned t = 0; while(!HasKey()) { if (read_ticks() > t + 1000) { DisplayBattery(col, row); t = read_ticks(); } SVC_WAIT(50); } return GetKey(); }
void SObjDefAttr::BuildClassAttribute( pugi::xml_node & xmlNode, LPCWSTR pszClassName) { LPCWSTR pszBaseClassName=SApplication::getSingleton().BaseClassNameFromClassName(pszClassName); if(!pszBaseClassName) return; if(HasKey(pszBaseClassName)) { pugi::xml_node xmlNodeAttrs = GetKeyObject(pszBaseClassName); pugi::xml_attribute attr=xmlNodeAttrs.first_attribute(); while(attr) { if(!xmlNode.attribute(attr.name())) xmlNode.append_attribute(attr.name()).set_value(attr.value()); attr=attr.next_attribute(); } } BuildClassAttribute(xmlNode,pszBaseClassName); }