content/base/src/nsPropertyTable.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 * vim:cindent:ts=2:et:sw=2:
michael@0 3 *
michael@0 4 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 5 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 7 *
michael@0 8 * This Original Code has been modified by IBM Corporation. Modifications made by IBM
michael@0 9 * described herein are Copyright (c) International Business Machines Corporation, 2000.
michael@0 10 * Modifications to Mozilla code or documentation identified per MPL Section 3.3
michael@0 11 *
michael@0 12 * Date Modified by Description of modification
michael@0 13 * 04/20/2000 IBM Corp. OS/2 VisualAge build.
michael@0 14 */
michael@0 15
michael@0 16 /**
michael@0 17 * nsPropertyTable allows a set of arbitrary key/value pairs to be stored
michael@0 18 * for any number of nodes, in a global hashtable rather than on the nodes
michael@0 19 * themselves. Nodes can be any type of object; the hashtable keys are
michael@0 20 * nsIAtom pointers, and the values are void pointers.
michael@0 21 */
michael@0 22
michael@0 23 #ifndef nsPropertyTable_h_
michael@0 24 #define nsPropertyTable_h_
michael@0 25
michael@0 26 #include "mozilla/MemoryReporting.h"
michael@0 27 #include "nscore.h"
michael@0 28
michael@0 29 class nsIAtom;
michael@0 30
michael@0 31 typedef void
michael@0 32 (*NSPropertyFunc)(void *aObject,
michael@0 33 nsIAtom *aPropertyName,
michael@0 34 void *aPropertyValue,
michael@0 35 void *aData);
michael@0 36
michael@0 37 /**
michael@0 38 * Callback type for property destructors. |aObject| is the object
michael@0 39 * the property is being removed for, |aPropertyName| is the property
michael@0 40 * being removed, |aPropertyValue| is the value of the property, and |aData|
michael@0 41 * is the opaque destructor data that was passed to SetProperty().
michael@0 42 **/
michael@0 43 typedef NSPropertyFunc NSPropertyDtorFunc;
michael@0 44 class nsINode;
michael@0 45 class nsIFrame;
michael@0 46
michael@0 47 class nsPropertyOwner
michael@0 48 {
michael@0 49 public:
michael@0 50 nsPropertyOwner(const nsPropertyOwner& aOther) : mObject(aOther.mObject) {}
michael@0 51
michael@0 52 // These are the types of objects that can own properties. No object should
michael@0 53 // inherit more then one of these classes.
michael@0 54 // To add support for more types just add to this list.
michael@0 55 nsPropertyOwner(const nsINode* aObject) : mObject(aObject) {}
michael@0 56 nsPropertyOwner(const nsIFrame* aObject) : mObject(aObject) {}
michael@0 57
michael@0 58 operator const void*() { return mObject; }
michael@0 59 const void* get() { return mObject; }
michael@0 60
michael@0 61 private:
michael@0 62 const void* mObject;
michael@0 63 };
michael@0 64
michael@0 65 class nsPropertyTable
michael@0 66 {
michael@0 67 public:
michael@0 68 /**
michael@0 69 * Get the value of the property |aPropertyName| for node |aObject|.
michael@0 70 * |aResult|, if supplied, is filled in with a return status code.
michael@0 71 **/
michael@0 72 void* GetProperty(nsPropertyOwner aObject,
michael@0 73 nsIAtom *aPropertyName,
michael@0 74 nsresult *aResult = nullptr)
michael@0 75 {
michael@0 76 return GetPropertyInternal(aObject, aPropertyName, false, aResult);
michael@0 77 }
michael@0 78
michael@0 79 /**
michael@0 80 * Set the value of the property |aPropertyName| to
michael@0 81 * |aPropertyValue| for node |aObject|. |aDtor| is a destructor for the
michael@0 82 * property value to be called if the property is removed. It can be null
michael@0 83 * if no destructor is required. |aDtorData| is an optional pointer to an
michael@0 84 * opaque context to be passed to the property destructor. Note that the
michael@0 85 * destructor is global for each property name regardless of node; it is an
michael@0 86 * error to set a given property with a different destructor than was used
michael@0 87 * before (this will return NS_ERROR_INVALID_ARG). If aOldValue is non-null
michael@0 88 * it will contain the old value after the function returns (the destructor
michael@0 89 * for the old value will not be run in that case). If |aTransfer| is true
michael@0 90 * the property will be transfered to the new table when the property table
michael@0 91 * for |aObject| changes (currently the tables for nodes are owned by their
michael@0 92 * ownerDocument, so if the ownerDocument for a node changes, its property
michael@0 93 * table changes too). If |aTransfer| is false the property will just be
michael@0 94 * deleted instead.
michael@0 95 */
michael@0 96 NS_HIDDEN_(nsresult) SetProperty(nsPropertyOwner aObject,
michael@0 97 nsIAtom *aPropertyName,
michael@0 98 void *aPropertyValue,
michael@0 99 NSPropertyDtorFunc aDtor,
michael@0 100 void *aDtorData,
michael@0 101 bool aTransfer = false,
michael@0 102 void **aOldValue = nullptr)
michael@0 103 {
michael@0 104 return SetPropertyInternal(aObject, aPropertyName, aPropertyValue,
michael@0 105 aDtor, aDtorData, aTransfer, aOldValue);
michael@0 106 }
michael@0 107
michael@0 108 /**
michael@0 109 * Delete the property |aPropertyName| in the global category for object
michael@0 110 * |aObject|. The property's destructor function will be called.
michael@0 111 */
michael@0 112 NS_HIDDEN_(nsresult) DeleteProperty(nsPropertyOwner aObject,
michael@0 113 nsIAtom *aPropertyName);
michael@0 114
michael@0 115 /**
michael@0 116 * Unset the property |aPropertyName| in the global category for object
michael@0 117 * |aObject|, but do not call the property's destructor function. The
michael@0 118 * property value is returned.
michael@0 119 */
michael@0 120 void* UnsetProperty(nsPropertyOwner aObject,
michael@0 121 nsIAtom *aPropertyName,
michael@0 122 nsresult *aStatus = nullptr)
michael@0 123 {
michael@0 124 return GetPropertyInternal(aObject, aPropertyName, true, aStatus);
michael@0 125 }
michael@0 126
michael@0 127 /**
michael@0 128 * Deletes all of the properties for object |aObject|, calling the
michael@0 129 * destructor function for each property.
michael@0 130 */
michael@0 131 NS_HIDDEN_(void) DeleteAllPropertiesFor(nsPropertyOwner aObject);
michael@0 132
michael@0 133 /**
michael@0 134 * Transfers all properties for object |aObject| that were set with the
michael@0 135 * |aTransfer| argument as true to |aTable|. Deletes the other properties
michael@0 136 * for object |aObject|, calling the destructor function for each property.
michael@0 137 * If transfering a property fails, this deletes all the properties for
michael@0 138 * object |aObject|.
michael@0 139 */
michael@0 140 NS_HIDDEN_(nsresult)
michael@0 141 TransferOrDeleteAllPropertiesFor(nsPropertyOwner aObject,
michael@0 142 nsPropertyTable *aOtherTable);
michael@0 143
michael@0 144 /**
michael@0 145 * Enumerate the properties for object |aObject|.
michael@0 146 * For every property |aCallback| will be called with as arguments |aObject|,
michael@0 147 * the property name, the property value and |aData|.
michael@0 148 */
michael@0 149 NS_HIDDEN_(void) Enumerate(nsPropertyOwner aObject,
michael@0 150 NSPropertyFunc aCallback, void *aData);
michael@0 151
michael@0 152 /**
michael@0 153 * Enumerate all the properties.
michael@0 154 * For every property |aCallback| will be called with arguments the owner,
michael@0 155 * the property name, the property value and |aData|.
michael@0 156 */
michael@0 157 NS_HIDDEN_(void) EnumerateAll(NSPropertyFunc aCallback, void *aData);
michael@0 158
michael@0 159 /**
michael@0 160 * Deletes all of the properties for all objects in the property
michael@0 161 * table, calling the destructor function for each property.
michael@0 162 */
michael@0 163 NS_HIDDEN_(void) DeleteAllProperties();
michael@0 164
michael@0 165 nsPropertyTable() : mPropertyList(nullptr) {}
michael@0 166 ~nsPropertyTable() {
michael@0 167 DeleteAllProperties();
michael@0 168 }
michael@0 169
michael@0 170 /**
michael@0 171 * Function useable as destructor function for property data that is
michael@0 172 * XPCOM objects. The function will call NS_IF_RELASE on the value
michael@0 173 * to destroy it.
michael@0 174 */
michael@0 175 static void SupportsDtorFunc(void *aObject, nsIAtom *aPropertyName,
michael@0 176 void *aPropertyValue, void *aData);
michael@0 177
michael@0 178 class PropertyList;
michael@0 179
michael@0 180 size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
michael@0 181
michael@0 182 private:
michael@0 183 NS_HIDDEN_(void) DestroyPropertyList();
michael@0 184 NS_HIDDEN_(PropertyList*) GetPropertyListFor(nsIAtom *aPropertyName) const;
michael@0 185 NS_HIDDEN_(void*) GetPropertyInternal(nsPropertyOwner aObject,
michael@0 186 nsIAtom *aPropertyName,
michael@0 187 bool aRemove,
michael@0 188 nsresult *aStatus);
michael@0 189 NS_HIDDEN_(nsresult) SetPropertyInternal(nsPropertyOwner aObject,
michael@0 190 nsIAtom *aPropertyName,
michael@0 191 void *aPropertyValue,
michael@0 192 NSPropertyDtorFunc aDtor,
michael@0 193 void *aDtorData,
michael@0 194 bool aTransfer,
michael@0 195 void **aOldValue);
michael@0 196
michael@0 197 PropertyList *mPropertyList;
michael@0 198 };
michael@0 199 #endif

mercurial