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,2017 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  void insert(const FXchar* ky,const FXchar* str,FXbool mrk=false){ at(ky,mrk)=str; }
118 
120  void insert(const FXString& ky,const FXchar* str,FXbool mrk=false){ at(ky,mrk)=str; }
121 
123  void insert(const FXString& ky,const FXString& str,FXbool mrk=false){ at(ky,mrk)=str; }
124 
126  void remove(const FXchar* ky);
127 
129  void remove(const FXString& ky){ remove(ky.text()); }
130 
132  void 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  void clear();
151 
154  };
155 
156 
157 }
158 
159 #endif

Copyright © 1997-2016 Jeroen van der Zijp