Open Inventor Reference
SbDict.h
Go to the documentation of this file.
1/*
2 *
3 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 * Mountain View, CA 94043, or:
28 *
29 * http://www.sgi.com
30 *
31 * For further information regarding this notice, see:
32 *
33 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 *
35 */
36
37
38/*
39 * Copyright (C) 1990,91 Silicon Graphics, Inc.
40 *
41 _______________________________________________________________________
42 ______________ S I L I C O N G R A P H I C S I N C . ____________
43 |
44 | $Revision: 1.1.1.1 $
45 |
46 | Description:
47 | This file defines dictionaries. A dictionary maps some sort of
48 | unique key to a data pointer. Keys are size_t integers.
49 |
50 | Classes:
51 | SbDictEntry, SbDict
52 |
53 | Author(s) : Paul S. Strauss, Nick Thompson
54 |
55 ______________ S I L I C O N G R A P H I C S I N C . ____________
56 _______________________________________________________________________
57 */
58
59
60#ifndef _SB_DICT_
61#define _SB_DICT_
62
64
65#include <Inventor/SbBasic.h>
66#include <Inventor/SbString.h>
67#include <Inventor/SbPList.h>
68
78
80 private:
81 size_t key;
82 void * value;
83
84 SbDictEntry * next;
85
87 SbDictEntry(size_t k, void *v) { key = k; value = v; };
88
89friend class SbDict;
90};
91
100
102 public:
103
105 SbDict( int entries = 251 );
106
109
112 void applyToAll(void (*rtn)(size_t key, void *value) );
113
116 void applyToAll(void (*rtn)(size_t key, void *value, void *data),
117 void *data );
118
120 void clear();
121
124 bool enter(size_t key, void *value);
126 bool enter(const void* key, void* value) { return enter((size_t)key, value); }
127
130 bool find(size_t key, void *&value) const;
132 bool find(const void* key, void* &value) const { return find((size_t)key, value); }
133
136 void makePList(SbPList &keys, SbPList &values);
137
139 bool remove(size_t key);
141 bool remove(const void* key) { return remove((size_t)key); }
142
143 private:
145 int tableSize;
146 SbDictEntry * *buckets;
147
148 SbDictEntry *& findEntry(size_t key) const;
149 static void addEntryToPLists(size_t key, void *value, void *data);
150};
151
152#endif /* _SB_DICT_ */
#define SoEXTENDER
Provide inline template functions for abs, swap, min, max, and clamp.
Definition SbBasic.h:154
#define SoINTERNAL
Definition SbBasic.h:155
#define INVENTOR_API
Disable some annoying warnings on MSVC 6.
Definition SbSystem.h:77
A dictionary is stored as a collection of entries, each of which is an SbDictEntry.
Definition SbDict.h:79
This is a dictionary mapping (size_t) integer keys to (void *) data pointers.
Definition SbDict.h:101
bool remove(const void *key)
Convenience variant with pointer type as key:
Definition SbDict.h:141
bool find(const void *key, void *&value) const
Convenience variant with pointer type as key:
Definition SbDict.h:132
void clear()
Removes all entries from dictionary.
bool enter(const void *key, void *value)
Convenience variant with pointer type as key:
Definition SbDict.h:126
void applyToAll(void(*rtn)(size_t key, void *value))
Calls given routine (passing value) for each entry in dictionary.
void makePList(SbPList &keys, SbPList &values)
Makes two SbPLists, one for keys and the other for values.
bool find(size_t key, void *&value) const
Finds entry with given key, setting value to point to value.
SbDict(int entries=251)
Constructor.
bool enter(size_t key, void *value)
Enters a key,value pair into the dictionary.
~SbDict()
Destructor.
bool remove(size_t key)
Removes the entry with the given key. Returns FALSE if no such entry.
void applyToAll(void(*rtn)(size_t key, void *value, void *data), void *data)
Calls given routine (passing value,data) for each entry in dictionary.
List of generic (void *) pointers.
Definition SbPList.h:78