Logo ROOT  
Reference Guide
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
18{
19 static RAttrMap empty;
20 return empty;
21}
22
23///////////////////////////////////////////////////////////////////////////////
24/// Copy attributes from other object
25
26bool 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
45bool 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
56void 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
67bool 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
79void 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
87void 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
96{
97 if (auto access = AccessAttr(name))
98 const_cast<RAttrMap*>(access.attr)->Clear(access.fullname);
99}
100
101void 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
107void 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
113void 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
119void 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 */
127{
128 for (const auto &entry : GetDefaults())
129 ClearValue(entry.first);
130}
char name[80]
Definition: TGX11.cxx:109
Base class for all attributes, used with RDrawable.
Definition: RAttrBase.hxx:27
bool IsValueEqual(const std::string &name, const RAttrMap::Value_t &value, bool use_style=false) const
Copy attributes into target object.
Definition: RAttrBase.cxx:45
void Clear()
Clear all respective values from drawable.
Definition: RAttrBase.cxx:126
bool CopyValue(const std::string &name, const RAttrMap::Value_t &value, bool check_type=true)
Copy attributes from other object.
Definition: RAttrBase.cxx:26
void ClearValue(const std::string &name)
Definition: RAttrBase.cxx:95
void AssignDrawable(RDrawable *drawable, const std::string &prefix)
Return value from attributes container - no style or defaults are used.
Definition: RAttrBase.cxx:79
void SetValue(const std::string &name, bool value)
Definition: RAttrBase.cxx:101
bool IsSame(const RAttrBase &src, bool use_style=true) const
Check if all values which are evaluated in this object are exactly the same as in tgt object.
Definition: RAttrBase.cxx:67
void AssignParent(RAttrBase *parent, const std::string &prefix)
Definition: RAttrBase.cxx:87
virtual const RAttrMap & GetDefaults() const
Return default values for attributes, empty for base class.
Definition: RAttrBase.cxx:17
void CopyTo(RAttrBase &tgt, bool use_style=true) const
Copy attributes into target object.
Definition: RAttrBase.cxx:56
virtual EValuesKind Kind() const =0
virtual std::unique_ptr< Value_t > Copy() const =0
Base class for drawable entities: objects that can be painted on a RPad.
Definition: RDrawable.hxx:99