VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/xpcom/ds/nsHashSets.h@ 4837

Last change on this file since 4837 was 1, checked in by vboxsync, 54 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
Line 
1/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is Mozilla Communicator client code.
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38#ifndef __nsHashSets_h__
39#define __nsHashSets_h__
40
41#include "nsDoubleHashtable.h"
42
43/*
44 * HASH SETS
45 *
46 * These hash classes describe hashtables that contain keys without values.
47 * This is useful when you want to store things and then just test for their
48 * existence later. We have defined standard ones for string, int and void.
49 *
50 * nsStringHashSet: nsAString&
51 * nsCStringHashSet: nsACString&
52 * nsInt32HashSet: PRInt32
53 * nsVoidHashSet: void*
54 *
55 * USAGE:
56 * Put(): put a thing of the given type into the set
57 * Contains(): whether it contains a thing of the given type
58 * To use, you just do: (for example)
59 *
60 * #include "nsDoubleHashtable.h"
61 * nsInt32HashSet mySet;
62 * mySet.Init(1);
63 * mySet.Put(5);
64 * if (mySet.Contains(5)) {
65 * printf("yay\n");
66 * }
67 *
68 * There is a nice convenient macro for declaring empty map classes:
69 * DECL_DHASH_SET(CLASSNAME, ENTRY_CLASS, KEY_TYPE)
70 * - CLASSNAME: the name of the class
71 * - ENTRY_CLASS: the name of the entry class with the key in it
72 * - KEY_TYPE: the type of key for Put() and Contains()
73 *
74 * DHASH_SET(CLASSNAME, ENTRY_CLASS, KEY_TYPE) is the companion macro
75 * you must put in the .cpp (implementation) code.
76 */
77
78#define DECL_DHASH_SET(CLASSNAME,ENTRY_CLASS,KEY_TYPE) \
79DECL_DHASH_WRAPPER(CLASSNAME##Super,ENTRY_CLASS,KEY_TYPE) \
80class DHASH_EXPORT CLASSNAME : public CLASSNAME##Super { \
81public: \
82 CLASSNAME() : CLASSNAME##Super() { } \
83 ~CLASSNAME() { } \
84 nsresult Put(const KEY_TYPE aKey) { \
85 return AddEntry(aKey) ? NS_OK : NS_ERROR_OUT_OF_MEMORY; \
86 } \
87 PRBool Contains(const KEY_TYPE aKey) { \
88 return GetEntry(aKey) ? PR_TRUE : PR_FALSE; \
89 } \
90};
91
92#define DHASH_SET(CLASSNAME,ENTRY_CLASS,KEY_TYPE) \
93DHASH_WRAPPER(CLASSNAME##Super,ENTRY_CLASS,KEY_TYPE)
94
95#undef DHASH_EXPORT
96#define DHASH_EXPORT NS_COM
97
98DECL_DHASH_SET(nsStringHashSet, PLDHashStringEntry, nsAString&)
99DECL_DHASH_SET(nsCStringHashSet,PLDHashCStringEntry,nsACString&)
100DECL_DHASH_SET(nsInt32HashSet, PLDHashInt32Entry, PRInt32)
101DECL_DHASH_SET(nsVoidHashSet, PLDHashVoidEntry, void*)
102
103#undef DHASH_EXPORT
104#define DHASH_EXPORT
105
106
107#endif
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use