Convert PDict into template

This commit is contained in:
Tim Wojtulewicz 2019-07-02 18:44:34 -07:00 committed by Jon Siwek
parent 237c7e4e15
commit e2feec52be

View file

@ -183,46 +183,41 @@ private:
PList<IterCookie> cookies; PList<IterCookie> cookies;
}; };
template<typename T>
#define PDict(type) type ## PDict class PDict : public Dictionary {
#define PDictdeclare(type) \ public:
class PDict(type) : public Dictionary { \ explicit PDict(dict_order ordering = UNORDERED, int initial_size = 0) :
public: \ Dictionary(ordering, initial_size) {}
explicit PDict(type)(dict_order ordering = UNORDERED, \ T* Lookup(const char* key) const
int initial_size = 0) : \ {
Dictionary(ordering, initial_size) {} \ HashKey h(key);
type* Lookup(const char* key) const \ return (T*) Dictionary::Lookup(&h);
{ \ }
HashKey h(key); \ T* Lookup(const HashKey* key) const
return (type*) Dictionary::Lookup(&h); \ { return (T*) Dictionary::Lookup(key); }
} \ T* Insert(const char* key, T* val)
type* Lookup(const HashKey* key) const \ {
{ return (type*) Dictionary::Lookup(key); } \ HashKey h(key);
type* Insert(const char* key, type* val) \ return (T*) Dictionary::Insert(&h, (void*) val);
{ \ }
HashKey h(key); \ T* Insert(HashKey* key, T* val)
return (type*) Dictionary::Insert(&h, (void*) val); \ { return (T*) Dictionary::Insert(key, (void*) val); }
} \ T* NthEntry(int n) const
type* Insert(HashKey* key, type* val) \ { return (T*) Dictionary::NthEntry(n); }
{ return (type*) Dictionary::Insert(key, (void*) val); }\ T* NthEntry(int n, const char*& key) const
type* NthEntry(int n) const \ {
{ return (type*) Dictionary::NthEntry(n); } \ int key_len;
type* NthEntry(int n, const char*& key) const \ return (T*) Dictionary::NthEntry(n, (const void*&) key, key_len);
{ \ }
int key_len; \ T* NextEntry(IterCookie*& cookie) const
return (type*) Dictionary::NthEntry(n, (const void*&) key,\ {
key_len); \ HashKey* h;
} \ return (T*) Dictionary::NextEntry(h, cookie, 0);
type* NextEntry(IterCookie*& cookie) const \ }
{ \ T* NextEntry(HashKey*& h, IterCookie*& cookie) const
HashKey* h; \ { return (T*) Dictionary::NextEntry(h, cookie, 1); }
return (type*) Dictionary::NextEntry(h, cookie, 0); \ T* RemoveEntry(const HashKey* key)
} \ { return (T*) Remove(key->Key(), key->Size(), key->Hash()); }
type* NextEntry(HashKey*& h, IterCookie*& cookie) const \ };
{ return (type*) Dictionary::NextEntry(h, cookie, 1); } \
type* RemoveEntry(const HashKey* key) \
{ return (type*) Remove(key->Key(), key->Size(), \
key->Hash()); } \
}
#endif #endif