Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 {
17
18class RLogChannel;
19
20namespace Experimental {
21
22/// Log channel for GPad diagnostics.
24
25/** \class RAttrBase
26\ingroup GpadROOT7
27\author Sergey Linev <s.linev@gsi.de>
28\date 2019-09-17
29\brief Base class for all attributes, used with RDrawable
30\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
31*/
32
33class RAttrBase {
34
35 friend class RAttrMap;
36
37 enum {kDrawable, kParent, kOwnAttr} fKind{kDrawable}; ///<! kind of data
38
39 union {
40 RDrawable *drawable; // either drawable to which attributes belongs to
41 RAttrBase *parent; // or aggregation of attributes
42 RAttrMap *ownattr; // or just own container with values
43 } fD{nullptr}; ///<! data
44
45 const char *fPrefix{nullptr}; ///<! name prefix for all attributes values
46
47 void ClearData();
49
50protected:
51
52 RDrawable *GetDrawable() const { return fKind == kDrawable ? fD.drawable : nullptr; }
53 RAttrBase *GetParent() const { return fKind == kParent ? fD.parent : nullptr; }
54 RAttrMap *GetOwnAttr() const { return fKind == kOwnAttr ? fD.ownattr : nullptr; }
55
56 virtual RAttrMap CollectDefaults() const = 0;
57
58 virtual bool IsAggregation() const { return false; }
59
60 ///////////////////////////////////////////////////////////////////////////////
61
62 struct Rec_t {
63 RAttrMap *attr{nullptr};
64 std::string fullname;
66 operator bool() const { return !!attr; }
67 };
68
69 /// Find attributes container and full-qualified name for value
70 const Rec_t AccessAttr(const std::string &name) const
71 {
72 const RAttrBase *prnt = this;
73 std::string fullname = name;
74 while (prnt) {
75 if (prnt->IsAggregation() && prnt->fPrefix) {
76 fullname.insert(0, "_"); // fullname = prnt->fPrefix + _ + fullname
77 fullname.insert(0, prnt->fPrefix);
78 }
79 if (auto dr = prnt->GetDrawable())
80 return { &dr->fAttr, fullname, dr };
81 if (auto attr = prnt->GetOwnAttr())
82 return { attr, fullname, nullptr };
83 prnt = prnt->GetParent();
84 }
85 return {nullptr, fullname, nullptr};
86 }
87
88 struct Val_t {
89 const RAttrMap::Value_t *value{nullptr};
90 std::shared_ptr<RStyle> style;
91 operator bool() const { return !!value; }
92 };
93
94 /** Search value with given name in attributes */
95 const Val_t AccessValue(const std::string &name, bool use_style = true) const
96 {
97 if (auto access = AccessAttr(name)) {
98 if (auto rec = access.attr->Find(access.fullname))
99 return {rec, nullptr};
100 if (access.drawable && use_style)
101 if (auto observe = access.drawable->fStyle.lock()) {
102 if (auto rec = observe->Eval(access.fullname, *access.drawable))
103 return {rec, observe};
104 }
105 }
106
107 return {nullptr, nullptr};
108 }
109
110 /// Ensure attribute with give name exists - creates container for attributes if required
111
112 Rec_t EnsureAttr(const std::string &name)
113 {
114 auto prnt = this;
115 std::string fullname = name;
116 while (prnt) {
117 if (prnt->IsAggregation() && prnt->fPrefix) {
118 fullname.insert(0, "_"); // fullname = prnt->fPrefix + _ + fullname
119 fullname.insert(0, prnt->fPrefix);
120 }
121 if (auto dr = prnt->GetDrawable())
122 return { &dr->fAttr, fullname, dr };
123 if (prnt->fKind != kParent)
124 return { prnt->CreateOwnAttr(), fullname, nullptr };
125 prnt = prnt->GetParent();
126 }
127 return {nullptr, fullname, nullptr};
128 }
129
130 RAttrBase(const char *prefix)
131 {
132 fKind = kOwnAttr;
133 fD.ownattr = nullptr;
134 fPrefix = prefix;
135 }
136
137 RAttrBase(RDrawable *drawable, const char *prefix = nullptr)
138 {
139 fKind = kDrawable;
140 fD.drawable = drawable;
141 fPrefix = prefix;
142 }
143
144 RAttrBase(RAttrBase *parent, const char *prefix = nullptr)
145 {
146 fKind = kParent;
147 fD.parent = parent;
148 fPrefix = prefix;
149 }
150
151 void SetNoValue(const std::string &name);
152
153 const char *GetPrefix() const { return fPrefix; }
154
155 void ClearValue(const std::string &name);
156
157 void MoveTo(RAttrBase &tgt);
158
159public:
160 RAttrBase() = default;
161
162 virtual ~RAttrBase() { ClearData(); }
163
164 virtual void Clear() = 0;
165
166};
167
168} // namespace Experimental
169} // namespace ROOT
170
171#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:33
RAttrBase(RAttrBase *parent, const char *prefix=nullptr)
RAttrMap * GetOwnAttr() const
Definition RAttrBase.hxx:54
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:70
RDrawable * GetDrawable() const
Definition RAttrBase.hxx:52
const Val_t AccessValue(const std::string &name, bool use_style=true) const
Search value with given name in attributes.
Definition RAttrBase.hxx:95
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:45
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:58
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:53
Base class for drawable entities: objects that can be painted on a RPad.
A log configuration for a channel, e.g.
Definition RLogger.hxx:98
ROOT::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:89
std::shared_ptr< RStyle > style
Definition RAttrBase.hxx:90