#ifndef Dictionary_First #define Dictionary_First #ifdef __GNUG__ #pragma interface #endif #include "Container.h" class DictHashTab; class DictionaryIterator; //---- Dictionary -------------------------------------------------------------- class Dictionary : public Container { friend DictionaryIterator; static Object *ignore; public: MetaDef(Dictionary); Dictionary(int initCapacity= cContainerInitCap); ~Dictionary(); Object *Clone(); void InitNew(); void FreeAll(); int Capacity(); virtual void Empty(int newCapacity= cContainerInitCap); void FreeValues(); // delete all values and empty receiver void FreeAllValues(); // FreeAll values and empty receiver //---- manipulation virtual Object *PutAtKeyIfAbsent(Object *value, Object *key); virtual Object *PutAtKey(Object *value, Object *key); virtual Object *RemoveKey(Object *key, Object *&value= ignore); //---- access Iterator *MakeIterator(bool dir= cIterForward, void *placement= 0); // Iterator yields keys Object *AtKey(Object *key); // return the value at key //---- object i/o OStream& PrintOn(OStream&); IStream& ReadFrom(IStream&); protected: Dictionary(Dictionary*); void Init(int initCapacity); bool CheckKey(char *name, Object *op); protected: DictHashTab *ht; }; //---- DictionaryIterator ------------------------------------------------------ class DictionaryIterator : public Iterator { public: DictionaryIterator(Dictionary *aDict); ~DictionaryIterator(); void Reset(); Object *operator()(); // return key Object *GetValue(); Object *NextValue(); Object *NextKey(); protected: Container *GetContainer(); Object *NextIndex(); protected: int pix; DictHashTab *ht; Dictionary *dt; }; #endif