Dictionary.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef ROCKETCOREDICTIONARY_H
00029 #define ROCKETCOREDICTIONARY_H
00030
00031 #include <Rocket/Core/Header.h>
00032 #include <Rocket/Core/Variant.h>
00033
00034 namespace Rocket {
00035 namespace Core {
00036
00044 class ROCKETCORE_API Dictionary
00045 {
00046 public:
00047 Dictionary();
00048 Dictionary(const Dictionary &dict);
00049 ~Dictionary();
00050
00052 void Set(const String& key, const Variant &value);
00053
00055 template <typename T>
00056 inline void Set(const String& key, const T& value);
00057
00059 Variant* Get(const String& key) const;
00060 Variant* operator[](const String& key) const;
00061
00064 template <typename T>
00065 inline T Get(const String& key, const T& default_val) const;
00066
00069 template <typename T>
00070 inline bool GetInto(const String& key, T& value) const;
00071
00073 bool Remove(const String& key);
00074
00076 bool Iterate(int &pos, String& key, Variant* &value) const;
00077 template <typename T>
00078 bool Iterate(int &pos, String& key, T& value) const;
00079
00081 bool Reserve(int size);
00082
00084 void Clear();
00085
00087 bool IsEmpty() const;
00088
00090 int Size() const;
00091
00093 void Merge(const Dictionary& dict);
00094
00095
00096 void operator=(const Dictionary &dict);
00097
00098 private:
00099 unsigned int num_full;
00100 unsigned int num_used;
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 static const int DICTIONARY_MINSIZE = 8;
00111
00112
00113 struct DictionaryEntry
00114 {
00115 DictionaryEntry() : hash(0) {}
00116 Hash hash;
00117 String key;
00118 Variant value;
00119 };
00120
00121
00122
00123
00124
00125 unsigned int mask;
00126
00127
00128 DictionaryEntry small_table[DICTIONARY_MINSIZE];
00129
00131 DictionaryEntry* table;
00132
00134 void Insert(const String& key, Hash hash, const Variant& value);
00135
00137 DictionaryEntry* Retrieve(const String& key, Hash hash) const;
00138
00140 void ResetToMinimumSize();
00141
00142
00143 void Copy(const Dictionary &dict);
00144 };
00145
00146 #include <Rocket/Core/Dictionary.inl>
00147
00148 }
00149 }
00150
00151 #endif