Logo ROOT  
Reference Guide
TDictAttributeMap.cxx
Go to the documentation of this file.
1 // @(#)root/meta:$Id:$
2 // Author: Bianca-Cristina Cristescu 03/07/13
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2013, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 /** \class TDictAttributeMap
13 The ROOT object has a list of properties which are stored and
14 retrieved using TDictAttributeMap.
15 TDictAttributeMap maps the property keys of the object to their
16 values.
17 */
18 
19 #include "TDictAttributeMap.h"
20 #include "THashTable.h"
21 #include "TNamed.h"
22 #include "TParameter.h"
23 
24 
26 
27 ////////////////////////////////////////////////////////////////////////////////
28 ///Default constructor.
29 
31 {
33 }
34 
35 ////////////////////////////////////////////////////////////////////////////////
36 ///Default destructor.
37 
39 {
40 }
41 
42 ////////////////////////////////////////////////////////////////////////////////
43 ///Add a property with a String value to the TDictAttributeMap.
44 ///Parameters: key and char* value of the property.
45 
46 void TDictAttributeMap::AddProperty(const char* key, const char* value)
47 {
48  //Add the property pair name - Int value to the hash table.
49  fStringProperty.Add(new TNamed(key, value));
50 }
51 
52 ////////////////////////////////////////////////////////////////////////////////
53 
54 Bool_t TDictAttributeMap::HasKey(const char* key) const
55 {
56  //Check whether the class has a property using the key.
57 
58  if (fStringProperty.FindObject(key))
59  return true;
60  return false;
61 }
62 
63 ////////////////////////////////////////////////////////////////////////////////
64 ///Access the value of a String property using the key.
65 
66 const char* TDictAttributeMap::GetPropertyAsString(const char* key) const
67 {
68  //Copy object into found to avoid calling the function two times.
69  TObject* found = fStringProperty.FindObject(key);
70  if(found)
71  return found->GetTitle();
72  else
73  //Show an error message if the key is not found.
74  Error("GetPropertyAsString"
75  , "Could not find property with String value for this key: %s", key);
76  return 0;
77 }
78 
79 ////////////////////////////////////////////////////////////////////////////////
80 ///Remove a String property from the attribute map specified by the key.
81 ///Returns the TString property removed or NULL if the property does not exist.
82 
84 {
85  TObject *property = fStringProperty.FindObject(key);
86  if (property) {
87  fStringProperty.Remove(property);
88  return property->GetTitle();
89  }
90  return TString(0);
91 }
92 
94 {
95  //Remove a property from the attribute map specified by the key.
96  //Returns true if property exists and was removed, false if property
97  //does not exist.
98 
99  if (TObject *property = fStringProperty.FindObject(key)) {
100  fStringProperty.Remove(property);
101  return true;
102  }
103  return false;
104 }
105 
106 ////////////////////////////////////////////////////////////////////////////////
107 ///Deletes all the properties of the class.
108 
109 void TDictAttributeMap::Clear(Option_t* /*option = ""*/)
110 {
112 }
TDictAttributeMap::~TDictAttributeMap
virtual ~TDictAttributeMap()
Default destructor.
Definition: TDictAttributeMap.cxx:38
TDictAttributeMap::Clear
void Clear(Option_t *option="")
Deletes all the properties of the class.
Definition: TDictAttributeMap.cxx:109
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
THashTable::Add
void Add(TObject *obj)
Add object to the hash table.
Definition: THashTable.cxx:92
TDictAttributeMap::RemovePropertyString
TString RemovePropertyString(const char *key)
Remove a String property from the attribute map specified by the key.
Definition: TDictAttributeMap.cxx:83
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TNamed.h
TObject::Error
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:890
TCollection::SetOwner
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
Definition: TCollection.cxx:746
TObject::GetTitle
virtual const char * GetTitle() const
Returns title of object.
Definition: TObject.cxx:403
TString
Definition: TString.h:136
THashTable::Delete
void Delete(Option_t *option="")
Remove all objects from the table AND delete all heap based objects.
Definition: THashTable.cxx:220
bool
TDictAttributeMap.h
TParameter.h
TDictAttributeMap
Definition: TDictAttributeMap.h:29
TDictAttributeMap::GetPropertyAsString
const char * GetPropertyAsString(const char *key) const
Access the value of a String property using the key.
Definition: TDictAttributeMap.cxx:66
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
TNamed
Definition: TNamed.h:29
THashTable::FindObject
TObject * FindObject(const char *name) const
Find object using its name.
Definition: THashTable.cxx:238
TDictAttributeMap::fStringProperty
THashTable fStringProperty
Definition: TDictAttributeMap.h:52
TDictAttributeMap::TDictAttributeMap
TDictAttributeMap()
Default constructor.
Definition: TDictAttributeMap.cxx:30
THashTable::Remove
TObject * Remove(TObject *obj)
Remove object from the hashtable.
Definition: THashTable.cxx:417
TDictAttributeMap::HasKey
Bool_t HasKey(const char *key) const
Definition: TDictAttributeMap.cxx:54
TDictAttributeMap::AddProperty
void AddProperty(const char *key, const char *value)
Add a property with a String value to the TDictAttributeMap.
Definition: TDictAttributeMap.cxx:46
TObject
Definition: TObject.h:37
TDictAttributeMap::RemoveProperty
Bool_t RemoveProperty(const char *key)
Definition: TDictAttributeMap.cxx:93
THashTable.h