00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef ROOT_TMap
00013 #define ROOT_TMap
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef ROOT_TCollection
00029 #include "TCollection.h"
00030 #endif
00031 #ifndef ROOT_THashTable
00032 #include "THashTable.h"
00033 #endif
00034
00035 #include <iterator>
00036
00037
00038 class THashTableIter;
00039 class TMapIter;
00040 class TPair;
00041 class TBrowser;
00042
00043
00044 class TMap : public TCollection {
00045
00046 friend class TMapIter;
00047
00048 private:
00049 THashTable *fTable;
00050
00051 TMap(const TMap& map);
00052 TMap& operator=(const TMap& map);
00053
00054 protected:
00055 enum { kIsOwnerValue = BIT(15) };
00056
00057 virtual void PrintCollectionEntry(TObject* entry, Option_t* option, Int_t recurse) const;
00058
00059 public:
00060 typedef TMapIter Iterator_t;
00061
00062 TMap(Int_t capacity = TCollection::kInitHashTableCapacity, Int_t rehash = 0);
00063 virtual ~TMap();
00064 void Add(TObject *obj);
00065 void Add(TObject *key, TObject *value);
00066 Float_t AverageCollisions() const;
00067 Int_t Capacity() const;
00068 void Clear(Option_t *option="");
00069 Int_t Collisions(const char *keyname) const;
00070 Int_t Collisions(TObject *key) const;
00071 void Delete(Option_t *option="");
00072 void DeleteKeys() { Delete(); }
00073 void DeleteValues();
00074 void DeleteAll();
00075 Bool_t DeleteEntry(TObject *key);
00076 TObject *FindObject(const char *keyname) const;
00077 TObject *FindObject(const TObject *key) const;
00078 TObject **GetObjectRef(const TObject *obj) const { return fTable->GetObjectRef(obj); }
00079 const THashTable *GetTable() const { return fTable; }
00080 TObject *GetValue(const char *keyname) const;
00081 TObject *GetValue(const TObject *key) const;
00082 Bool_t IsOwnerValue() const { return TestBit(kIsOwnerValue); }
00083 TObject *operator()(const char *keyname) const { return GetValue(keyname); }
00084 TObject *operator()(const TObject *key) const { return GetValue(key); }
00085 TIterator *MakeIterator(Bool_t dir = kIterForward) const;
00086 void Rehash(Int_t newCapacity, Bool_t checkObjValidity = kTRUE);
00087 TObject *Remove(TObject *key);
00088 TPair *RemoveEntry(TObject *key);
00089 virtual void SetOwnerValue(Bool_t enable = kTRUE);
00090 virtual void SetOwnerKeyValue(Bool_t ownkeys = kTRUE, Bool_t ownvals = kTRUE);
00091
00092 ClassDef(TMap,3)
00093 };
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 class TPair : public TObject {
00105
00106 private:
00107 TObject *fKey;
00108 TObject *fValue;
00109
00110 TPair& operator=(const TPair&);
00111
00112 public:
00113 TPair(TObject *key, TObject *value) : fKey(key), fValue(value) { }
00114 TPair(const TPair &a) : TObject(), fKey(a.fKey), fValue(a.fValue) { }
00115 virtual ~TPair() { }
00116 Bool_t IsFolder() const { return kTRUE;}
00117 virtual void Browse(TBrowser *b);
00118 const char *GetName() const { return fKey->GetName(); }
00119 const char *GetTitle() const { return fKey->GetTitle(); }
00120 ULong_t Hash() const { return fKey->Hash(); }
00121 Bool_t IsEqual(const TObject *obj) const { return fKey->IsEqual(obj); }
00122 TObject *Key() const { return fKey; }
00123 TObject *Value() const { return fValue; }
00124 void SetValue(TObject *val) { fValue = val; }
00125
00126 ClassDef(TPair,0);
00127 };
00128
00129 typedef TPair TAssoc;
00130
00131
00132
00133 #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= 40600
00134 #pragma GCC diagnostic push
00135 #pragma GCC diagnostic ignored "-Weffc++"
00136 #endif
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 class TMapIter : public TIterator,
00147 public std::iterator<std::bidirectional_iterator_tag,
00148 TObject*, std::ptrdiff_t,
00149 const TObject**, const TObject*&> {
00150
00151 private:
00152 const TMap *fMap;
00153 THashTableIter *fCursor;
00154 Bool_t fDirection;
00155
00156 TMapIter() : fMap(0), fCursor(0), fDirection(kIterForward) { }
00157
00158 public:
00159 TMapIter(const TMap *map, Bool_t dir = kIterForward);
00160 TMapIter(const TMapIter &iter);
00161 ~TMapIter();
00162 TIterator &operator=(const TIterator &rhs);
00163 TMapIter &operator=(const TMapIter &rhs);
00164
00165 const TCollection *GetCollection() const { return fMap; }
00166 TObject *Next();
00167 void Reset();
00168 bool operator!=(const TIterator &aIter) const;
00169 bool operator!=(const TMapIter &aIter) const;
00170 TObject *operator*() const;
00171
00172 ClassDef(TMapIter,0)
00173 };
00174
00175 #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= 40600
00176 #pragma GCC diagnostic pop
00177 #endif
00178
00179 #endif