Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RAttrBase.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_RAttrBase
10#define ROOT7_RAttrBase
11
12#include <ROOT/RAttrMap.hxx>
13#include <ROOT/RStyle.hxx>
14#include <ROOT/RDrawable.hxx>
15
16namespace ROOT {
17namespace Experimental {
18
19class RLogChannel;
20/// Log channel for GPad diagnostics.
21RLogChannel &GPadLog();
22
23/** \class RAttrBase
24\ingroup GpadROOT7
25\author Sergey Linev <s.linev@gsi.de>
26\date 2019-09-17
27\brief Base class for all attributes, used with RDrawable
28\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
29*/
30
31class RAttrBase {
32
33 friend class RAttrMap;
34
35 enum {kDrawable, kParent, kOwnAttr} fKind{kDrawable}; ///<! kind of data
36
37 union {
38 RDrawable *drawable; // either drawable to which attributes belongs to
39 RAttrBase *parent; // or aggregation of attributes
40 RAttrMap *ownattr; // or just own container with values
41 } fD{nullptr}; ///<! data
42
43 const char *fPrefix{nullptr}; ///<! name prefix for all attributes values
44
45 void ClearData();
47
48protected:
49
50 RDrawable *GetDrawable() const { return fKind == kDrawable ? fD.drawable : nullptr; }
51 RAttrBase *GetParent() const { return fKind == kParent ? fD.parent : nullptr; }
52 RAttrMap *GetOwnAttr() const { return fKind == kOwnAttr ? fD.ownattr : nullptr; }
53
54 virtual RAttrMap CollectDefaults() const = 0;
55
56 virtual bool IsAggregation() const { return false; }
57
58 ///////////////////////////////////////////////////////////////////////////////
59
60 struct Rec_t {
61 RAttrMap *attr{nullptr};
62 std::string fullname;
64 operator bool() const { return !!attr; }
65 };
66
67 /// Find attributes container and full-qualified name for value
68 const Rec_t AccessAttr(const std::string &name) const
69 {
70 const RAttrBase *prnt = this;
71 std::string fullname = name;
72 while (prnt) {
73 if (prnt->IsAggregation() && prnt->fPrefix) {
74 fullname.insert(0, "_"); // fullname = prnt->fPrefix + _ + fullname
75 fullname.insert(0, prnt->fPrefix);
76 }
77 if (auto dr = prnt->GetDrawable())
78 return { &dr->fAttr, fullname, dr };
79 if (auto attr = prnt->GetOwnAttr())
80 return { attr, fullname, nullptr };
81 prnt = prnt->GetParent();
82 }
83 return {nullptr, fullname, nullptr};
84 }
85
86 struct Val_t {
87 const RAttrMap::Value_t *value{nullptr};
88 std::shared_ptr<RStyle> style;
89 operator bool() const { return !!value; }
90 };
91
92 /** Search value with given name in attributes */
93 const Val_t AccessValue(const std::string &name, bool use_style = true) const
94 {
95 if (auto access = AccessAttr(name)) {
96 if (auto rec = access.attr->Find(access.fullname))
97 return {rec, nullptr};
98 if (access.drawable && use_style)
99 if (auto observe = access.drawable->fStyle.lock()) {
100 if (auto rec = observe->Eval(access.fullname, *access.drawable))
101 return {rec, observe};
102 }
103 }
104
105 return {nullptr, nullptr};
106 }
107
108 /// Ensure attribute with give name exists - creates container for attributes if required
109
110 Rec_t EnsureAttr(const std::string &name)
111 {
112 auto prnt = this;
113 std::string fullname = name;
114 while (prnt) {
115 if (prnt->IsAggregation() && prnt->fPrefix) {
116 fullname.insert(0, "_"); // fullname = prnt->fPrefix + _ + fullname
117 fullname.insert(0, prnt->fPrefix);
118 }
119 if (auto dr = prnt->GetDrawable())
120 return { &dr->fAttr, fullname, dr };
121 if (prnt->fKind != kParent)
122 return { prnt->CreateOwnAttr(), fullname, nullptr };
123 prnt = prnt->GetParent();
124 }
125 return {nullptr, fullname, nullptr};
126 }
127
128 RAttrBase(const char *prefix)
129 {
130 fKind = kOwnAttr;
131 fD.ownattr = nullptr;
132 fPrefix = prefix;
133 }
134
135 RAttrBase(RDrawable *drawable, const char *prefix = nullptr)
136 {
137 fKind = kDrawable;
138 fD.drawable = drawable;
139 fPrefix = prefix;
140 }
141
142 RAttrBase(RAttrBase *parent, const char *prefix = nullptr)
143 {
144 fKind = kParent;
145 fD.parent = parent;
146 fPrefix = prefix;
147 }
148
149 void SetNoValue(const std::string &name);
150
151 const char *GetPrefix() const { return fPrefix; }
152
153 void ClearValue(const std::string &name);
154
155 void MoveTo(RAttrBase &tgt);
156
157public:
158 RAttrBase() = default;
159
160 virtual ~RAttrBase() { ClearData(); }
161
162 virtual void Clear() = 0;
163
164};
165
166} // namespace Experimental
167} // namespace ROOT
168
169#endif
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t attr
char name[80]
Definition TGX11.cxx:110
Base class for all attributes, used with RDrawable.
Definition RAttrBase.hxx:31
RAttrBase(RAttrBase *parent, const char *prefix=nullptr)
RAttrMap * GetOwnAttr() const
Definition RAttrBase.hxx:52
void ClearValue(const std::string &name)
Clear value if any with specified name.
Definition RAttrBase.cxx:54
const Rec_t AccessAttr(const std::string &name) const
Find attributes container and full-qualified name for value.
Definition RAttrBase.hxx:68
RDrawable * GetDrawable() const
Definition RAttrBase.hxx:50
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
void MoveTo(RAttrBase &tgt)
Move all fields into target object.
Definition RAttrBase.cxx:73
const char * fPrefix
! name prefix for all attributes values
Definition RAttrBase.hxx:43
Rec_t EnsureAttr(const std::string &name)
Ensure attribute with give name exists - creates container for attributes if required.
virtual bool IsAggregation() const
Definition RAttrBase.hxx:56
RAttrMap * CreateOwnAttr()
Creates own attribute - only if no drawable and no parent are assigned.
Definition RAttrBase.cxx:37
void ClearData()
Clear internal data.
Definition RAttrBase.cxx:26
RAttrBase(const char *prefix)
enum ROOT::Experimental::RAttrBase::@40 kDrawable
! kind of data
RAttrBase(RDrawable *drawable, const char *prefix=nullptr)
virtual RAttrMap CollectDefaults() const =0
void SetNoValue(const std::string &name)
Set <NoValue> for attribute.
Definition RAttrBase.cxx:64
RAttrBase * GetParent() const
Definition RAttrBase.hxx:51
Base class for drawable entities: objects that can be painted on a RPad.
RLogChannel & GPadLog()
Log channel for GPad diagnostics.
Definition RAttrBase.cxx:17
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
const RAttrMap::Value_t * value
Definition RAttrBase.hxx:87
std::shared_ptr< RStyle > style
Definition RAttrBase.hxx:88