michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsJSThingHashtable_h__ michael@0: #define nsJSThingHashtable_h__ michael@0: michael@0: #include "nsHashKeys.h" michael@0: #include "nsBaseHashtable.h" michael@0: michael@0: namespace JS { michael@0: template michael@0: class Heap; michael@0: } /* namespace JS */ michael@0: michael@0: /** michael@0: * A wrapper for hash keys that sets ALLOW_MEMMOVE to false. michael@0: * michael@0: * This is used in the implementation of nsJSThingHashtable and is not intended michael@0: * to be used directly. michael@0: * michael@0: * It is necessary for hash tables containing JS::Heap values as these must michael@0: * be copied rather than memmoved. michael@0: */ michael@0: template michael@0: class nsHashKeyDisallowMemmove : public T michael@0: { michael@0: public: michael@0: nsHashKeyDisallowMemmove(const T& key) : T(key) {} michael@0: enum { ALLOW_MEMMOVE = false }; michael@0: }; michael@0: michael@0: michael@0: /** michael@0: * Templated hashtable class for use on the heap where the values are JS GC things. michael@0: * michael@0: * Storing JS GC thing pointers on the heap requires wrapping them in a michael@0: * JS::Heap, and this class takes care of that while presenting an interface michael@0: * in terms of the wrapped type T. michael@0: * michael@0: * For example, to store a hashtable mapping strings to JSObject pointers, you michael@0: * can declare a data member like this: michael@0: * michael@0: * nsJSThingHashtable mStringToObjectMap; michael@0: * michael@0: * See nsBaseHashtable for complete declaration michael@0: * @param KeyClass a wrapper-class for the hashtable key, see nsHashKeys.h michael@0: * for a complete specification. michael@0: * @param DataType the datatype being wrapped, must be a JS GC thing. michael@0: * @see nsInterfaceHashtable, nsClassHashtable michael@0: */ michael@0: template michael@0: class nsJSThingHashtable : michael@0: public nsBaseHashtable, JS::Heap, DataType> michael@0: { }; michael@0: michael@0: #endif // nsJSThingHashtable_h__