source: trunk/MagicSoft/Mars/mbase/MObjLookup.cc@ 9422

Last change on this file since 9422 was 8930, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 2.5 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Thomas Bretz 5/2008 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: CheObs Software Development, 2008
21!
22!
23\* ======================================================================== */
24
25
26//////////////////////////////////////////////////////////////////////////////
27//
28//
29//////////////////////////////////////////////////////////////////////////////
30#include "MObjLookup.h"
31
32#include <TNamed.h>
33#include <TObjString.h>
34
35ClassImp(MObjLookup);
36
37// --------------------------------------------------------------------------
38//
39// Delete all elements with kCenDelete set or all elements in case of
40// kIsOwener is set
41//
42MObjLookup::~MObjLookup()
43{
44 TExMapIter iter(&fMap);
45
46 Long_t key;
47 Long_t value;
48
49 while (iter.Next(key, value))
50 {
51 TObject *o = reinterpret_cast<TObject*>(value);
52 if (o->TestBit(kCanDelete) || TestBit(kIsOwner))
53 delete o;
54 }
55}
56
57// --------------------------------------------------------------------------
58//
59// Add a TObjString to the table
60//
61void MObjLookup::Add(Long_t key, const char *txt)
62{
63 TObject *o=new TObjString(txt);
64
65 o->SetBit(kCanDelete);
66
67 Add(key,o);
68}
69
70// --------------------------------------------------------------------------
71//
72// Add a TNames to the table
73//
74void MObjLookup::Add(Long_t key, const char *name, const char *title)
75{
76 TObject *o=new TNamed(name, title);
77
78 o->SetBit(kCanDelete);
79
80 Add(key,o);
81}
82
83// --------------------------------------------------------------------------
84//
85// Search for the object corresponding to key. If no object is found,
86// fDefault is returned instead.
87//
88TObject *MObjLookup::GetObj(Long_t key) const
89{
90 TObject *o = reinterpret_cast<TObject*>(const_cast<TExMap&>(fMap).GetValue(key));
91 return o ? o : fDefault;
92}
Note: See TracBrowser for help on using the repository browser.