Warning, file /include/root/ROOT/RAttrValue.hxx was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef ROOT7_RAttrValue
0010 #define ROOT7_RAttrValue
0011
0012 #include <ROOT/RAttrBase.hxx>
0013
0014 namespace ROOT {
0015 namespace Experimental {
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 template<typename T>
0026 class RAttrValue : public RAttrBase {
0027
0028 template <typename Q, bool = std::is_enum<Q>::value>
0029 struct ValueExtractor {
0030 Q Get(const RAttrMap::Value_t *value)
0031 {
0032 return (Q) RAttrMap::Value_t::GetValue<int>(value);
0033 }
0034 };
0035
0036 template <typename Q>
0037 struct ValueExtractor<Q, false> {
0038 Q Get(const RAttrMap::Value_t *value) {
0039 return RAttrMap::Value_t::GetValue<Q>(value);
0040 }
0041 };
0042
0043 protected:
0044
0045 T fDefault{};
0046
0047 RAttrMap CollectDefaults() const override
0048 {
0049 return RAttrMap().AddValue(GetName(), fDefault);
0050 }
0051
0052 public:
0053
0054 RAttrValue() : RAttrBase("") {}
0055
0056 RAttrValue(const T& dflt) : RAttrBase(""), fDefault(dflt) {}
0057
0058 RAttrValue(RDrawable *drawable, const char *name, const T &dflt = T()) : RAttrBase(drawable, name ? name : ""), fDefault(dflt) { }
0059
0060 RAttrValue(RAttrBase *parent, const char *name, const T &dflt = T()) : RAttrBase(parent, name ? name : ""), fDefault(dflt) { }
0061
0062 RAttrValue(const RAttrValue& src) : RAttrBase("")
0063 {
0064 Set(src.Get());
0065 fDefault = src.GetDefault();
0066 }
0067
0068 T GetDefault() const { return fDefault; }
0069
0070 void Set(const T &v)
0071 {
0072 if (auto access = EnsureAttr(GetName()))
0073 access.attr->AddValue(access.fullname, v);
0074 }
0075
0076 T Get() const
0077 {
0078 if (auto v = AccessValue(GetName(), true))
0079 return ValueExtractor<T>().Get(v.value);
0080 return fDefault;
0081 }
0082
0083 const char *GetName() const { return GetPrefix(); }
0084
0085 void Clear() override { ClearValue(GetName()); }
0086
0087 bool Has() const
0088 {
0089 if (auto v = AccessValue(GetName(), true)) {
0090 auto res = RAttrMap::Value_t::GetValue<const RAttrMap::Value_t *,T>(v.value);
0091 return res ? (res->Kind() != RAttrMap::kNoValue) : false;
0092 }
0093
0094 return false;
0095 }
0096
0097 RAttrValue &operator=(const T &v) { Set(v); return *this; }
0098
0099 RAttrValue &operator=(const RAttrValue &v) { Set(v.Get()); return *this; }
0100
0101 operator T() const { return Get(); }
0102
0103 friend bool operator==(const RAttrValue& lhs, const RAttrValue& rhs) { return lhs.Get() == rhs.Get(); }
0104 friend bool operator!=(const RAttrValue& lhs, const RAttrValue& rhs) { return lhs.Get() != rhs.Get(); }
0105
0106 friend bool operator==(const RAttrValue& lhs, const T& rhs) { return lhs.Get() == rhs; }
0107 friend bool operator!=(const RAttrValue& lhs, const T& rhs) { return lhs.Get() != rhs; }
0108
0109 };
0110
0111 }
0112 }
0113
0114 #endif