Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RAttrValue.hxx
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (C) 1995-2021, 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#ifndef ROOT7_RAttrValue
10#define ROOT7_RAttrValue
11
12#include <ROOT/RAttrBase.hxx>
13
14namespace ROOT {
15namespace Experimental {
16
17/** \class RAttrValue
18\ingroup GpadROOT7
19\author Sergey Linev <s.linev@gsi.de>
20\date 2020-06-24
21\brief Template class to access single value from drawable or other attributes
22\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
23*/
24
25template<typename T>
26class RAttrValue : public RAttrBase {
27
28 template <typename Q, bool = std::is_enum<Q>::value>
31 {
32 return (Q) RAttrMap::Value_t::GetValue<int>(value);
33 }
34 };
35
36 template <typename Q>
37 struct ValueExtractor<Q, false> {
39 return RAttrMap::Value_t::GetValue<Q>(value);
40 }
41 };
42
43protected:
44
45 T fDefault{}; ///<! default value
46
47 RAttrMap CollectDefaults() const override
48 {
49 return RAttrMap().AddValue(GetName(), fDefault);
50 }
51
52public:
53
55
56 RAttrValue(const T& dflt) : RAttrBase(""), fDefault(dflt) {}
57
58 RAttrValue(RDrawable *drawable, const char *name, const T &dflt = T()) : RAttrBase(drawable, name ? name : ""), fDefault(dflt) { }
59
60 RAttrValue(RAttrBase *parent, const char *name, const T &dflt = T()) : RAttrBase(parent, name ? name : ""), fDefault(dflt) { }
61
63 {
64 Set(src.Get());
65 fDefault = src.GetDefault();
66 }
67
68 T GetDefault() const { return fDefault; }
69
70 void Set(const T &v)
71 {
72 if (auto access = EnsureAttr(GetName()))
73 access.attr->AddValue(access.fullname, v);
74 }
75
76 T Get() const
77 {
78 if (auto v = AccessValue(GetName(), true))
79 return ValueExtractor<T>().Get(v.value);
80 return fDefault;
81 }
82
83 const char *GetName() const { return GetPrefix(); }
84
85 void Clear() override { ClearValue(GetName()); }
86
87 bool Has() const
88 {
89 if (auto v = AccessValue(GetName(), true)) {
90 auto res = RAttrMap::Value_t::GetValue<const RAttrMap::Value_t *,T>(v.value);
91 return res ? (res->Kind() != RAttrMap::kNoValue) : false;
92 }
93
94 return false;
95 }
96
97 RAttrValue &operator=(const T &v) { Set(v); return *this; }
98
99 RAttrValue &operator=(const RAttrValue &v) { Set(v.Get()); return *this; }
100
101 operator T() const { return Get(); }
102
103 friend bool operator==(const RAttrValue& lhs, const RAttrValue& rhs) { return lhs.Get() == rhs.Get(); }
104 friend bool operator!=(const RAttrValue& lhs, const RAttrValue& rhs) { return lhs.Get() != rhs.Get(); }
105
106 friend bool operator==(const RAttrValue& lhs, const T& rhs) { return lhs.Get() == rhs; }
107 friend bool operator!=(const RAttrValue& lhs, const T& rhs) { return lhs.Get() != rhs; }
108
109};
110
111} // namespace Experimental
112} // namespace ROOT
113
114#endif // ROOT7_RAttrValue
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t src
char name[80]
Definition TGX11.cxx:110
Base class for all attributes, used with RDrawable.
Definition RAttrBase.hxx:31
void ClearValue(const std::string &name)
Clear value if any with specified name.
Definition RAttrBase.cxx:54
const Val_t AccessValue(const std::string &name, bool use_style=true) const
Search value with given name in attributes.
Definition RAttrBase.hxx:93
const char * GetPrefix() const
Rec_t EnsureAttr(const std::string &name)
Ensure attribute with give name exists - creates container for attributes if required.
RAttrMap & AddValue(const std::string &name, bool value)
Definition RAttrMap.hxx:165
Template class to access single value from drawable or other attributes.
friend bool operator!=(const RAttrValue &lhs, const RAttrValue &rhs)
friend bool operator==(const RAttrValue &lhs, const RAttrValue &rhs)
RAttrValue(RAttrBase *parent, const char *name, const T &dflt=T())
friend bool operator!=(const RAttrValue &lhs, const T &rhs)
RAttrValue(RDrawable *drawable, const char *name, const T &dflt=T())
friend bool operator==(const RAttrValue &lhs, const T &rhs)
RAttrMap CollectDefaults() const override
const char * GetName() const
RAttrValue & operator=(const RAttrValue &v)
RAttrValue & operator=(const T &v)
RAttrValue(const RAttrValue &src)
Base class for drawable entities: objects that can be painted on a RPad.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Q Get(const RAttrMap::Value_t *value)