/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/** * nsPropertyTable allows a set of arbitrary key/value pairs to be stored * for any number of nodes, in a global hashtable rather than on the nodes * themselves. Nodes can be any type of object; the hashtable keys are * nsAtom pointers, and the values are void pointers.
*/
RefPtr<nsAtom> mName; // property name
PLDHashTable mObjectValueMap; // map of object/value pairs
NSPropertyDtorFunc mDtorFunc; // property specific value dtor function void* mDtorData; // pointer to pass to dtor bool mTransfer; // whether to transfer in // TransferOrRemoveAllPropertiesFor
PropertyList* mNext;
};
void nsPropertyTable::RemoveAllProperties() { while (mPropertyList) {
PropertyList* tmp = mPropertyList;
if (propertyList) { // Make sure the dtor function and data and the transfer flag match if (aPropDtorFunc != propertyList->mDtorFunc ||
aPropDtorData != propertyList->mDtorData ||
aTransfer != propertyList->mTransfer) {
NS_WARNING("Destructor/data mismatch while setting property"); return NS_ERROR_INVALID_ARG;
}
// The current property value (if there is one) is replaced and the current // value is destroyed
nsresult result = NS_OK; auto entry = static_cast<PropertyListMapEntry*>(
propertyList->mObjectValueMap.Add(aObject, mozilla::fallible)); if (!entry) return NS_ERROR_OUT_OF_MEMORY; // A nullptr entry->key is the sign that the entry has just been allocated // for us. If it's non-nullptr then we have an existing entry. if (entry->key) { if (propertyList->mDtorFunc) {
propertyList->mDtorFunc(const_cast<void*>(entry->key), aPropertyName,
entry->value, propertyList->mDtorData);
}
result = NS_PROPTABLE_PROP_OVERWRITTEN;
}
entry->key = aObject;
entry->value = aPropertyValue;
void nsPropertyTable::PropertyList::Destroy() { // Enumerate any remaining object/value pairs and destroy the value object. if (mDtorFunc) { for (auto iter = mObjectValueMap.ConstIter(); !iter.Done(); iter.Next()) { auto entry = static_cast<PropertyListMapEntry*>(iter.Get());
mDtorFunc(const_cast<void*>(entry->key), mName, entry->value, mDtorData);
}
}
}
bool nsPropertyTable::PropertyList::RemovePropertyFor(nsPropertyOwner aObject) { auto entry = static_cast<PropertyListMapEntry*>(mObjectValueMap.Search(aObject)); if (!entry) returnfalse;
void* value = entry->value;
mObjectValueMap.RemoveEntry(entry);
if (mDtorFunc)
mDtorFunc(const_cast<void*>(aObject.get()), mName, value, mDtorData);
returntrue;
}
size_t nsPropertyTable::PropertyList::SizeOfIncludingThis(
mozilla::MallocSizeOf aMallocSizeOf) {
size_t n = aMallocSizeOf(this);
n += mObjectValueMap.ShallowSizeOfExcludingThis(aMallocSizeOf); return n;
}
size_t nsPropertyTable::SizeOfExcludingThis(
mozilla::MallocSizeOf aMallocSizeOf) const {
size_t n = 0;
for (PropertyList* prop = mPropertyList; prop; prop = prop->mNext) {
n += prop->SizeOfIncludingThis(aMallocSizeOf);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.