StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TAttr.cxx
1 /***************************************************************************
2  *
3  * $Id: TAttr.cxx,v 1.10 2017/08/08 19:37:37 perev Exp $
4  *
5  ***************************************************************************
6  *
7  * Description:
8  *
9  ***************************************************************************
10  **************************************************************************/
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <ctype.h>
15 #include <assert.h>
16 #include "TAttr.h"
17 #include "TClass.h"
18 Int_t TAttr::_debug = 0;
19 ClassImp(TAttr)
20 //______________________________________________________________________________
21 TAttr::TAttr(const char *name)
22 {
23  if (!name) name = "";
24  SetName(name);
25 }
26 //______________________________________________________________________________
27 TAttr::~TAttr()
28 {
29  Delete();
30 }
31 //_____________________________________________________________________________
39 void TAttr::SetAttr(const char *key, const char *val)
40 {
41 
42  TString tk(key);tk.ToLower();tk.ReplaceAll(" ","");tk.ReplaceAll("\t","");
43  if (!val) val ="";
44  TString tv(val);tv = tv.Strip(TString::kBoth) ;tv.ReplaceAll("\t","");
45  if (tv == ".remove") {
46  TObject *t = FindObject(tk.Data());
47  if (t) {Remove(t); delete t;}
48  } else {
49  TNamed *t = new TNamed(tk.Data(),tv.Data());
50  t->SetUniqueID(0);
51  AddFirst(t);
52  }
53  if (_debug)
54  Info("SetAttr","(\"%s\",\"%s\",\")",tk.Data(),tv.Data());
55 
56 }
57 //_____________________________________________________________________________
58 int TAttr::SetAttr(const TAttr *att)
59 {
60  TListIter iter(att,kIterBackward);
61  int add=0; const TNamed *tn=0;
62  while ((tn = (const TNamed*)iter())) {AddFirst(new TNamed(*tn));add++;}
63  return add;
64 }
65 //_____________________________________________________________________________
66 void TAttr::SetAttr(const char *key, Long_t val)
67 {
68  TString ts; ts+=val; SetAttr(key, ts.Data());
69 }
70 //_____________________________________________________________________________
71 void TAttr::SetAttr(const char *key, ULong_t val)
72 {
73  TString ts; ts+=val; return SetAttr(key, ts.Data());
74 }
75 //_____________________________________________________________________________
76 void TAttr::SetAttr(const char *key, double val)
77 {
78  TString ts; ts+=val; return SetAttr(key, ts.Data());
79 }
80 
81 //_____________________________________________________________________________
82 const char *TAttr::SAttr(const char *key) const
83 {
84  TString tey(key);
85  tey.ToLower(); tey.ReplaceAll(" ",""); tey.ReplaceAll("\t","");
86  TObject *att = FindObject(tey.Data());
87  if (att) { // we found the attribut
88  int n = att->GetUniqueID();
89  att->SetUniqueID(n+1);
90  if (n<13) Info("Found","%s = %s\n",att->GetName(),att->GetTitle());
91  }
92  return (att)? att->GetTitle():"";
93 }
94 //_____________________________________________________________________________
95 Long_t TAttr::IAttr(const char *key) const
96 {
97  const char *val = SAttr(key);
98  if (!val || !val[0]) return 0;
99  if (isdigit(*val))return strtol(val,0,10);
100  return strtoul(val,0,10);
101 }
102 //_____________________________________________________________________________
103 ULong_t TAttr::UAttr(const char *key) const
104 {
105  return (UInt_t)IAttr(key);
106 }
107 //_____________________________________________________________________________
108 double TAttr::DAttr(const char *key) const
109 {
110  const char *val = SAttr(key);
111  if (!val) return 0;
112  if (!val[0]) return 0;
113  return strtod(val,0);
114 }
115 //_____________________________________________________________________________
116 void TAttr::PrintAttr() const
117 {
118  if (!First()) return;
119  TIter next(this);
120  printf("PrintAttr() for %s::%s\n",ClassName(),GetName());
121  TObject *object;
122  int n=0;
123  while ((object = next())) {
124  n++;
125  printf(" %2d - %s = %s\n",n,object->GetName(),object->GetTitle());
126  }
127  printf("PrintAttr() ==============================================\n");
128 }
129 
Definition: TAttr.h:17
void SetAttr(const char *key, const char *val)
Definition: TAttr.cxx:39