Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
RAttrBase.cxx
Go to the documentation of this file.
1 /*************************************************************************
2  * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
3  * All rights reserved. *
4  * *
5  * For the licensing terms see $ROOTSYS/LICENSE. *
6  * For the list of contributors see $ROOTSYS/README/CREDITS. *
7  *************************************************************************/
8 
9 #include <ROOT/RAttrBase.hxx>
10 
11 #include <ROOT/RLogger.hxx>
12 
13 
14 ///////////////////////////////////////////////////////////////////////////////
15 /// Return default values for attributes, empty for base class
16 
17 const ROOT::Experimental::RAttrMap &ROOT::Experimental::RAttrBase::GetDefaults() const
18 {
19  static RAttrMap empty;
20  return empty;
21 }
22 
23 ///////////////////////////////////////////////////////////////////////////////
24 /// Copy attributes from other object
25 
26 bool ROOT::Experimental::RAttrBase::CopyValue(const std::string &name, const RAttrMap::Value_t &value, bool check_type)
27 {
28  if (check_type) {
29  const auto *dvalue = GetDefaults().Find(name);
30  if (!dvalue || !dvalue->Compatible(value.Kind()))
31  return false;
32  }
33 
34  if (auto access = EnsureAttr(name)) {
35  access.attr->Add(access.fullname, value.Copy());
36  return true;
37  }
38 
39  return false;
40 }
41 
42 ///////////////////////////////////////////////////////////////////////////////
43 /// Copy attributes into target object
44 
45 bool ROOT::Experimental::RAttrBase::IsValueEqual(const std::string &name, const RAttrMap::Value_t &value, bool use_style) const
46 {
47  if (auto v = AccessValue(name, use_style))
48  return v.value->IsEqual(value);
49 
50  return false;
51 }
52 
53 ///////////////////////////////////////////////////////////////////////////////
54 /// Copy attributes into target object
55 
56 void ROOT::Experimental::RAttrBase::CopyTo(RAttrBase &tgt, bool use_style) const
57 {
58  for (const auto &entry : GetDefaults()) {
59  if (auto v = AccessValue(entry.first, use_style))
60  tgt.CopyValue(entry.first, *v.value);
61  }
62 }
63 
64 ///////////////////////////////////////////////////////////////////////////////
65 /// Check if all values which are evaluated in this object are exactly the same as in tgt object
66 
67 bool ROOT::Experimental::RAttrBase::IsSame(const RAttrBase &tgt, bool use_style) const
68 {
69  for (const auto &entry : GetDefaults()) {
70  if (auto v = AccessValue(entry.first, use_style))
71  if (!tgt.IsValueEqual(entry.first, *v.value, use_style)) return false;
72  }
73  return true;
74 }
75 
76 ///////////////////////////////////////////////////////////////////////////////
77 /// Return value from attributes container - no style or defaults are used
78 
79 void ROOT::Experimental::RAttrBase::AssignDrawable(RDrawable *drawable, const std::string &prefix)
80 {
81  fDrawable = drawable;
82  fOwnAttr.reset();
83  fPrefix = prefix;
84  fParent = nullptr;
85 }
86 
87 void ROOT::Experimental::RAttrBase::AssignParent(RAttrBase *parent, const std::string &prefix)
88 {
89  fDrawable = nullptr;
90  fOwnAttr.reset();
91  fPrefix = prefix;
92  fParent = parent;
93 }
94 
95 void ROOT::Experimental::RAttrBase::ClearValue(const std::string &name)
96 {
97  if (auto access = AccessAttr(name))
98  const_cast<RAttrMap*>(access.attr)->Clear(access.fullname);
99 }
100 
101 void ROOT::Experimental::RAttrBase::SetValue(const std::string &name, bool value)
102 {
103  if (auto access = EnsureAttr(name))
104  access.attr->AddBool(access.fullname, value);
105 }
106 
107 void ROOT::Experimental::RAttrBase::SetValue(const std::string &name, int value)
108 {
109  if (auto access = EnsureAttr(name))
110  access.attr->AddInt(access.fullname, value);
111 }
112 
113 void ROOT::Experimental::RAttrBase::SetValue(const std::string &name, double value)
114 {
115  if (auto access = EnsureAttr(name))
116  access.attr->AddDouble(access.fullname, value);
117 }
118 
119 void ROOT::Experimental::RAttrBase::SetValue(const std::string &name, const std::string &value)
120 {
121  if (auto access = EnsureAttr(name))
122  access.attr->AddString(access.fullname, value);
123 }
124 
125 /** Clear all respective values from drawable. Only defaults can be used */
126 void ROOT::Experimental::RAttrBase::Clear()
127 {
128  for (const auto &entry : GetDefaults())
129  ClearValue(entry.first);
130 }