Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
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
13The ROOT object has a list of properties which are stored and
14retrieved using TDictAttributeMap.
15TDictAttributeMap maps the property keys of the object to their
16values.
17*/
18
19#include "TDictAttributeMap.h"
20#include "THashTable.h"
21#include "TNamed.h"
22#include "TParameter.h"
23
24
25
26////////////////////////////////////////////////////////////////////////////////
27///Default constructor.
28
33
34////////////////////////////////////////////////////////////////////////////////
35///Default destructor.
36
40
41////////////////////////////////////////////////////////////////////////////////
42///Add a property with a String value to the TDictAttributeMap.
43///Parameters: key and char* value of the property.
44
45void TDictAttributeMap::AddProperty(const char* key, const char* value)
46{
47 //Add the property pair name - Int value to the hash table.
48 fStringProperty.Add(new TNamed(key, value));
49}
50
51////////////////////////////////////////////////////////////////////////////////
52
53Bool_t TDictAttributeMap::HasKey(const char* key) const
54{
55 //Check whether the class has a property using the key.
56
57 if (fStringProperty.FindObject(key))
58 return true;
59 return false;
60}
61
62////////////////////////////////////////////////////////////////////////////////
63///Access the value of a String property using the key.
64
65const char* TDictAttributeMap::GetPropertyAsString(const char* key) const
66{
67 //Copy object into found to avoid calling the function two times.
68 TObject* found = fStringProperty.FindObject(key);
69 if(found)
70 return found->GetTitle();
71 else
72 //Show an error message if the key is not found.
73 Error("GetPropertyAsString"
74 , "Could not find property with String value for this key: %s", key);
75 return nullptr;
76}
77
78////////////////////////////////////////////////////////////////////////////////
79///Remove a String property from the attribute map specified by the key.
80///Returns the TString property removed or NULL if the property does not exist.
81
83{
84 TObject *property = fStringProperty.FindObject(key);
85 if (property) {
86 fStringProperty.Remove(property);
87 return property->GetTitle();
88 }
89 return TString(0);
90}
91
93{
94 //Remove a property from the attribute map specified by the key.
95 //Returns true if property exists and was removed, false if property
96 //does not exist.
97
98 if (TObject *property = fStringProperty.FindObject(key)) {
99 fStringProperty.Remove(property);
100 return true;
101 }
102 return false;
103}
104
105////////////////////////////////////////////////////////////////////////////////
106///Deletes all the properties of the class.
107
108void TDictAttributeMap::Clear(Option_t* /*option = ""*/)
109{
110 fStringProperty.Delete();
111}
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char).
Definition RtypesCore.h:80
TString RemovePropertyString(const char *key)
Remove a String property from the attribute map specified by the key.
void Clear(Option_t *option="") override
Deletes all the properties of the class.
const char * GetPropertyAsString(const char *key) const
Access the value of a String property using the key.
TDictAttributeMap()
Default constructor.
Bool_t HasKey(const char *key) const
virtual ~TDictAttributeMap()
Default destructor.
void AddProperty(const char *key, const char *value)
Add a property with a String value to the TDictAttributeMap.
Bool_t RemoveProperty(const char *key)
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1098
virtual const char * GetTitle() const
Returns title of object.
Definition TObject.cxx:507
TObject()
TObject constructor.
Definition TObject.h:259
Basic string class.
Definition TString.h:138