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

FXVariantMap.h
1 /********************************************************************************
2 * *
3 * V a r i a n t - M a p *
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 FXVARIANTMAP_H
22 #define FXVARIANTMAP_H
23 
24 namespace FX {
25 
26 
31 class FXAPI FXVariantMap {
32 protected:
33  struct Entry {
34  FXString key; // Lookup key
35  FXVariant data; // Variant data
36  FXuint hash; // Hash of key
37  };
38 protected:
39  Entry *table; // Hash table
40 protected:
41 
42  // Change size of the table
43  FXbool no(FXival n);
44 
45  // Change number of used entries
46  void used(FXival u){ ((FXival*)table)[-2]=u; }
47 
48  // Change number of free entries
49  void free(FXival f){ ((FXival*)table)[-3]=f; }
50 
51  // Resize the table to the given size, keeping contents
52  FXbool resize(FXival n);
53 public:
54 
56  FXVariantMap();
57 
59  FXVariantMap(const FXVariantMap& other);
60 
62  FXival no() const { return ((FXival*)table)[-1]; }
63 
65  FXival used() const { return ((FXival*)table)[-2]; }
66 
68  FXival free() const { return ((FXival*)table)[-3]; }
69 
71  FXbool empty() const { return ((FXival*)table)[-1]<=1; }
72 
74  FXVariantMap& operator=(const FXVariantMap& other);
75 
77  FXVariantMap& adopt(FXVariantMap& other);
78 
80  FXival find(const FXchar* ky) const;
81 
83  FXival find(const FXString& ky) const { return find(ky.text()); }
84 
86  FXbool has(const FXchar* ky) const { return 0<=find(ky); }
87 
89  FXbool has(const FXString& ky) const { return has(ky.text()); }
90 
92  FXVariant& at(const FXchar* ky);
93 
95  const FXVariant& at(const FXchar* ky) const;
96 
98  FXVariant& at(const FXString& ky){ return at(ky.text()); }
99 
101  const FXVariant& at(const FXString& ky) const { return at(ky.text()); }
102 
104  FXVariant& operator[](const FXchar* ky){ return at(ky); }
105 
107  const FXVariant& operator[](const FXchar* ky) const { return at(ky); }
108 
110  FXVariant& operator[](const FXString& ky){ return at(ky); }
111 
113  const FXVariant& operator[](const FXString& ky) const { return at(ky); }
114 
116  void remove(const FXchar* ky);
117 
119  void remove(const FXString& ky){ remove(ky.text()); }
120 
122  void erase(FXival pos);
123 
125  FXbool empty(FXival pos) const { return table[pos].key.empty(); }
126 
128  const FXString& key(FXival pos) const { return table[pos].key; }
129 
132  FXVariant& data(FXival pos){ return table[pos].data; }
133 
135  const FXVariant& data(FXival pos) const { return table[pos].data; }
136 
138  void clear();
139 
141  ~FXVariantMap();
142  };
143 
144 
145 }
146 
147 #endif

Copyright © 1997-2016 Jeroen van der Zijp