10#define ROOT7_RAttrBase
17namespace Experimental {
54 operator bool()
const {
return !!
attr; }
61 std::string fullname =
name;
63 fullname.insert(0, prnt->
fPrefix);
67 return {prnt->
fOwnAttr.get(), fullname,
nullptr};
70 return {
nullptr, fullname,
nullptr};
76 operator bool()
const {
return !!
value; }
82 if (
auto rec = access.attr->Find(access.fullname))
83 return {rec,
nullptr};
84 if (access.drawable && use_style)
85 if (
auto observe = access.drawable->fStyle.lock()) {
86 if (
auto rec = observe->Eval(access.fullname, *access.drawable))
87 return {rec, observe};
91 return {
nullptr,
nullptr};
99 std::string fullname =
name;
101 fullname.insert(0, prnt->fPrefix);
103 return {&(prnt->fDrawable->fAttr), fullname, prnt->fDrawable};
104 if (!prnt->fParent && !prnt->fOwnAttr)
105 prnt->fOwnAttr = std::make_unique<RAttrMap>();
107 return {prnt->fOwnAttr.get(), fullname,
nullptr};
108 prnt = prnt->fParent;
110 return {
nullptr, fullname,
nullptr};
115 template <
typename RET_TYPE,
typename MATCH_TYPE =
void>
116 auto Eval(
const std::string &
name,
bool use_dflts =
true)
const
119 return RAttrMap::Value_t::GetValue<RET_TYPE,MATCH_TYPE>(
v.value);
126 return RAttrMap::Value_t::GetValue<RET_TYPE,MATCH_TYPE>(rec);
149 void SetValue(
const std::string &
name,
const std::string &value);
157 template <
typename T =
void>
158 bool HasValue(
const std::string &
name,
bool check_defaults =
false)
const
160 return Eval<const RAttrMap::Value_t *, T>(
name, check_defaults) !=
nullptr;
163 template <
typename T>
166 return Eval<T>(
name);
182#define R__ATTR_CLASS(ClassName,dflt_prefix,dflt_values) \
184const RAttrMap &GetDefaults() const override \
186 static auto dflts = RAttrMap().dflt_values; \
190 ClassName() = default; \
191 ClassName(RDrawable *drawable, const std::string &prefix = dflt_prefix) { AssignDrawable(drawable, prefix); } \
192 ClassName(RAttrBase *parent, const std::string &prefix = dflt_prefix) { AssignParent(parent, prefix); } \
193 ClassName(const ClassName &src) : ClassName() { src.CopyTo(*this); } \
194 ClassName(ClassName &&src) = default; \
195 ClassName &operator=(ClassName &&src) = default; \
196 ClassName &operator=(const ClassName &src) \
Base class for all attributes, used with RDrawable.
bool IsValueEqual(const std::string &name, const RAttrMap::Value_t &value, bool use_style=false) const
Copy attributes into target object.
const Rec_t AccessAttr(const std::string &name) const
Find attributes container and full-qualified name for value.
std::unique_ptr< RAttrMap > fOwnAttr
! own instance when deep copy is created
const Val_t AccessValue(const std::string &name, bool use_style=true) const
friend bool operator!=(const RAttrBase &lhs, const RAttrBase &rhs)
void Clear()
Clear all respective values from drawable.
bool HasValue(const std::string &name, bool check_defaults=false) const
Rec_t EnsureAttr(const std::string &name)
Ensure attribute with give name exists - creates container for attributes if required.
RAttrBase & operator=(const RAttrBase &src)
bool CopyValue(const std::string &name, const RAttrMap::Value_t &value, bool check_type=true)
Copy attributes from other object.
RDrawable * fDrawable
! drawable used to store attributes
void ClearValue(const std::string &name)
void AssignDrawable(RDrawable *drawable, const std::string &prefix)
Return value from attributes container - no style or defaults are used.
friend bool operator==(const RAttrBase &lhs, const RAttrBase &rhs)
RAttrBase * fParent
! parent attributes, prefix applied to it
RAttrBase(RAttrBase *parent, const std::string &prefix)
virtual ~RAttrBase()=default
void SetValue(const std::string &name, bool value)
const std::string & GetPrefix() const
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.
RAttrBase(RDrawable *drawable, const std::string &prefix)
void AssignParent(RAttrBase *parent, const std::string &prefix)
std::string fPrefix
! name prefix for all attributes values
T GetValue(const std::string &name) const
virtual const RAttrMap & GetDefaults() const
Return default values for attributes, empty for base class.
RAttrBase(const RAttrBase &src)
void CopyTo(RAttrBase &tgt, bool use_style=true) const
Copy attributes into target object.
auto Eval(const std::string &name, bool use_dflts=true) const
Evaluate attribute value.
const Value_t * Find(const std::string &name) const
Base class for drawable entities: objects that can be painted on a RPad.
RAttrMap fAttr
attributes values
const RAttrMap::Value_t * value
std::shared_ptr< RStyle > style