Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXHashOf.h
1 /********************************************************************************
2 * *
3 * H a s h T a b l e O f P o i n t e r s T o T y p e *
4 * *
5 *********************************************************************************
6 * Copyright (C) 2003,2024 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXHASHOF_H
22 #define FXHASHOF_H
23 
24 namespace FX {
25 
26 
33 template<typename KEYTYPE,typename VALUETYPE>
34 class FXHashOf : public FXHash {
35 public:
36 
39 
42 
45 
48 
50  FXival find(KEYTYPE* ky) const { return FXHash::find(ky); }
51 
53  FXbool has(KEYTYPE* ky) const { return FXHash::has(ky); }
54 
56  VALUETYPE*& at(KEYTYPE* ky){ return reinterpret_cast<VALUETYPE*&>(FXHash::at(ky)); }
57 
59  VALUETYPE *const& at(KEYTYPE* ky) const { return reinterpret_cast<VALUETYPE *const&>(FXHash::at(ky)); }
60 
62  VALUETYPE*& operator[](KEYTYPE* ky){ return reinterpret_cast<VALUETYPE*&>(FXHash::at(ky)); }
63 
65  VALUETYPE *const& operator[](KEYTYPE* ky) const { return reinterpret_cast<VALUETYPE *const&>(FXHash::at(ky)); }
66 
68  VALUETYPE* insert(KEYTYPE* ky,VALUETYPE* ptr=nullptr){ return reinterpret_cast<VALUETYPE*>(FXHash::insert(ky,ptr)); }
69 
71  VALUETYPE* remove(KEYTYPE* ky){ return reinterpret_cast<VALUETYPE*>(FXHash::remove(ky)); }
72 
74  VALUETYPE* erase(FXival pos){ return reinterpret_cast<VALUETYPE*>(FXHash::erase(pos)); }
75 
77  KEYTYPE* key(FXival pos) const { return reinterpret_cast<KEYTYPE*>(FXHash::key(pos)); }
78 
80  VALUETYPE*& data(FXival pos){ return reinterpret_cast<VALUETYPE*&>(FXHash::data(pos)); }
81 
83  VALUETYPE *const& data(FXival pos) const { return reinterpret_cast<VALUETYPE *const&>(FXHash::data(pos)); }
84  };
85 
86 }
87 
88 #endif
VALUETYPE *const & data(FXival pos) const
Return constant reference to slot at position pos.
Definition: FXHashOf.h:83
FXHashOf()
Default constructor.
Definition: FXHashOf.h:38
VALUETYPE *& operator[](KEYTYPE *ky)
Return reference to slot assocated with given key.
Definition: FXHashOf.h:62
VALUETYPE * insert(KEYTYPE *ky, VALUETYPE *ptr=nullptr)
Insert association with given key; return old value, if any.
Definition: FXHashOf.h:68
VALUETYPE *const & at(KEYTYPE *ky) const
Return constant reference to slot assocated with given key.
Definition: FXHashOf.h:59
KEYTYPE * key(FXival pos) const
Return key at position pos.
Definition: FXHashOf.h:77
VALUETYPE *& at(KEYTYPE *ky)
Return reference to slot assocated with given key.
Definition: FXHashOf.h:56
VALUETYPE * erase(FXival pos)
Erase data at pos in the table; return old value, if any.
Definition: FXHashOf.h:74
FXival find(KEYTYPE *ky) const
Find position of given key, returning -1 if not found.
Definition: FXHashOf.h:50
FXHashOf< KEYTYPE, VALUETYPE > & operator=(const FXHashOf< KEYTYPE, VALUETYPE > &other)
Assignment operator.
Definition: FXHashOf.h:44
A hash table for mapping pointers to pointers.
Definition: FXHash.h:33
void * erase(FXival pos)
Erase entry from table at pos, returning old value.
FXHash & operator=(const FXHash &other)
Assign from another table.
FXHash & adopt(FXHash &other)
Adopt table from another; the other table becomes empty.
FXbool has(KEYTYPE *ky) const
Check if key is mapped.
Definition: FXHashOf.h:53
Definition: FX4Splitter.h:28
void * remove(const void *ky)
Remove key from the table.
VALUETYPE *& data(FXival pos)
Return reference to slot at position pos.
Definition: FXHashOf.h:80
FXival find(const void *ky) const
Find position of given key, returning -1 if not found.
FXHashOf(const FXHashOf< KEYTYPE, VALUETYPE > &other)
Copy constructor.
Definition: FXHashOf.h:41
A hash table mapping pointers to KEYTYPE to pointers of VALUETYPE.
Definition: FXHashOf.h:34
VALUETYPE *const & operator[](KEYTYPE *ky) const
Return constant reference to slot assocated with given key.
Definition: FXHashOf.h:65
const void * key(FXival pos) const
Return key at position pos.
Definition: FXHash.h:150
void * insert(const void *ky, void *ptr=nullptr)
Replace key in table, overwriting the old value if the given key already exists.
Definition: FXHash.h:130
FXbool has(const void *ky) const
Check if key is mapped.
Definition: FXHash.h:104
void *& data(FXival pos)
Return reference to data pointer at position pos.
Definition: FXHash.h:155
void *& at(const void *ky)
Return reference to slot assocated with given key.
FXHashOf< KEYTYPE, VALUETYPE > & adopt(FXHashOf< KEYTYPE, VALUETYPE > &other)
Adopt objects from orig, leaving orig empty.
Definition: FXHashOf.h:47

Copyright © 1997-2022 Jeroen van der Zijp