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

FXStringDictionary.h
1 /********************************************************************************
2 * *
3 * S t r i n g D i c t i o n a r y C l a s s *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1998,2022 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 FXSTRINGDICTIONARY_H
22 #define FXSTRINGDICTIONARY_H
23 
24 namespace FX {
25 
26 
31 class FXAPI FXStringDictionary {
32 protected:
33  struct Entry {
34  FXString key; // Key
35  FXString data; // Value
36  FXuint hash; // Hash of key
37  FXuint mark; // Mark flag
38  };
39 protected:
40  Entry* table; // Hash table
41 protected:
42 
43  // Change size of the table
44  FXbool no(FXival n);
45 
46  // Change number of used entries
47  void used(FXival u){ ((FXival*)table)[-2]=u; }
48 
49  // Change number of free entries
50  void free(FXival f){ ((FXival*)table)[-3]=f; }
51 
52  // Resize the table to the given size, keeping contents
53  FXbool resize(FXival n);
54 public:
55 
57  FXStringDictionary();
58 
60  FXStringDictionary(const FXStringDictionary& other);
61 
63  FXival no() const { return ((FXival*)table)[-1]; }
64 
66  FXival used() const { return ((FXival*)table)[-2]; }
67 
69  FXival free() const { return ((FXival*)table)[-3]; }
70 
72  FXbool empty() const { return ((FXival*)table)[-1]<=1; }
73 
75  FXStringDictionary& operator=(const FXStringDictionary& other);
76 
79 
81  FXival find(const FXchar* ky) const;
82 
84  FXival find(const FXString& ky) const { return find(ky.text()); }
85 
87  FXbool has(const FXchar* ky) const { return 0<=find(ky); }
88 
90  FXbool has(const FXString& ky) const { return has(ky.text()); }
91 
93  FXString& at(const FXchar* ky,FXbool mrk=false);
94 
96  const FXString& at(const FXchar* ky) const;
97 
99  FXString& at(const FXString& ky,FXbool mrk=false){ return at(ky.text(),mrk); }
100 
102  const FXString& at(const FXString& ky) const { return at(ky.text()); }
103 
105  FXString& operator[](const FXchar* ky){ return at(ky,false); }
106 
108  const FXString& operator[](const FXchar* ky) const { return at(ky); }
109 
111  FXString& operator[](const FXString& ky){ return at(ky,false); }
112 
114  const FXString& operator[](const FXString& ky) const { return at(ky); }
115 
117  FXbool insert(const FXchar* ky,const FXchar* str,FXbool mrk=false){ at(ky,mrk)=str; return true; }
118 
120  FXbool insert(const FXString& ky,const FXchar* str,FXbool mrk=false){ at(ky,mrk)=str; return true; }
121 
123  FXbool insert(const FXString& ky,const FXString& str,FXbool mrk=false){ at(ky,mrk)=str; return true; }
124 
126  FXbool remove(const FXchar* ky);
127 
129  FXbool remove(const FXString& ky){ return remove(ky.text()); }
130 
132  FXbool erase(FXival pos);
133 
135  FXbool empty(FXival pos) const { return table[pos].key.empty(); }
136 
138  const FXString& key(FXival pos) const { return table[pos].key; }
139 
141  FXString& data(FXival pos){ return table[pos].data; }
142 
144  const FXString& data(FXival pos) const { return table[pos].data; }
145 
147  FXuint mark(FXival pos) const { return table[pos].mark; }
148 
150  FXbool clear();
151 
154  };
155 
156 
157 }
158 
159 #endif
FXuint mark(FXival pos) const
Return mark flag of entry at position pos.
Definition: FXStringDictionary.h:147
FXbool insert(const FXString &ky, const FXchar *str, FXbool mrk=false)
Insert association with given key; return reference to the string.
Definition: FXStringDictionary.h:120
FXString & data(FXival pos)
Return reference to slot at position pos.
Definition: FXStringDictionary.h:141
Definition: FXStringDictionary.h:33
const FXString & at(const FXString &ky) const
Return constant reference to slot assocated with given key.
Definition: FXStringDictionary.h:102
const FXString & data(FXival pos) const
Return constant reference to slot at position pos.
Definition: FXStringDictionary.h:144
FXival used() const
Return number of used slots in the table.
Definition: FXStringDictionary.h:66
FXbool has(const FXString &ky) const
Check if key is mapped.
Definition: FXStringDictionary.h:90
FXival no() const
Return the size of the table, including the empty slots.
Definition: FXStringDictionary.h:63
FXival find(const FXString &ky) const
Find position of given key, returning -1 if not found.
Definition: FXStringDictionary.h:84
FXchar * text()
Get text contents as pointer.
Definition: FXString.h:119
FXbool empty() const
See if string is empty.
Definition: FXString.h:125
FXbool empty(FXival pos) const
Return true if slot is empty.
Definition: FXStringDictionary.h:135
FXbool insert(const FXchar *ky, const FXchar *str, FXbool mrk=false)
Insert association with given key; return reference to the string.
Definition: FXStringDictionary.h:117
const FXString & operator[](const FXString &ky) const
Return constant reference to slot assocated with given key.
Definition: FXStringDictionary.h:114
const FXString & key(FXival pos) const
Return key at position pos.
Definition: FXStringDictionary.h:138
FXbool empty() const
See if map is empty.
Definition: FXStringDictionary.h:72
FXival free() const
Return number of free slots in the table.
Definition: FXStringDictionary.h:69
Definition: FX4Splitter.h:28
FXString & at(const FXString &ky, FXbool mrk=false)
Return reference to slot assocated with given key.
Definition: FXStringDictionary.h:99
FXbool has(const FXchar *ky) const
Check if key is mapped.
Definition: FXStringDictionary.h:87
FXString & operator[](const FXString &ky)
Return reference to slot assocated with given key.
Definition: FXStringDictionary.h:111
const FXString & operator[](const FXchar *ky) const
Return constant reference to slot assocated with given key.
Definition: FXStringDictionary.h:108
FXString & operator[](const FXchar *ky)
Return reference to slot assocated with given key.
Definition: FXStringDictionary.h:105
The dictionary class maintains a fast-access hash table of entities indexed by a character string...
Definition: FXStringDictionary.h:31
FXbool insert(const FXString &ky, const FXString &str, FXbool mrk=false)
Insert association with given key; return reference to the string.
Definition: FXStringDictionary.h:123
FXString provides essential string manipulation capabilities in FOX.
Definition: FXString.h:42

Copyright © 1997-2022 Jeroen van der Zijp