source: trunk/Mars/mbase/MObjLookup.h@ 12776

Last change on this file since 12776 was 8892, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 1.4 KB
Line 
1#ifndef MARS_MObjLookup
2#define MARS_MObjLookup
3
4#ifndef ROOT_TExMap
5#include <TExMap.h>
6#endif
7
8class MObjLookup : public TObject
9{
10private:
11 TExMap fMap;
12 TObject *fDefault;
13
14 enum {
15 kIsOwner = BIT(14),
16 };
17
18public:
19 MObjLookup() : fDefault(0) { }
20 ~MObjLookup();
21
22 // Add a new object
23 void Add(Long_t key, TObject *obj) { fMap.Add(key, Long_t(obj)); }
24 void Add(Long_t key, const char *txt);
25 void Add(Long_t key, const char *name, const char *title);
26
27 // Get an object
28 TObject *GetObj(Long_t key) const;
29
30 TObject *operator[](Long_t key) const { return GetObj(key); }
31
32 const char *GetObjName(Long_t key) const { const TObject *o=GetObj(key); return o?o->GetName():NULL; }
33 const char *GetObjTitle(Long_t key) const { const TObject *o=GetObj(key); return o?o->GetTitle():NULL; }
34
35 // Number of entrues
36 Int_t GetSize() const { return fMap.GetSize(); }
37
38 // Owenership
39 void SetOnwer(Bool_t b=kTRUE) { b ? SetBit(kIsOwner) : ResetBit(kIsOwner); }
40
41 // Default returned if no obj found (deletion is user responsibility)
42 void SetDefault(TObject *o) { fDefault = o; }
43 TObject *GetDefault() { return fDefault; }
44
45 // Direct access to the TExMap
46 const TExMap &GetMap() const { return fMap; }
47 TExMap &GetMap() { return fMap; }
48
49 ClassDef(MObjLookup, 1) // A class providing a fast lookup table key(int)->TObject
50};
51
52#endif
Note: See TracBrowser for help on using the repository browser.