27 #include <unordered_map> 40 template <
class PRIMITIVE>
41 using ParsedAttrs_t = std::unordered_map<std::string, TDrawingAttrRef<PRIMITIVE>>;
42 using AllParsedAttrs_t = std::tuple<ParsedAttrs_t<TColor>, ParsedAttrs_t<long long>, ParsedAttrs_t<double>>;
44 static AllParsedAttrs_t &GetParsedDefaultAttrs()
46 static AllParsedAttrs_t sAllParsedAttrs;
47 return sAllParsedAttrs;
50 static ParsedAttrs_t<TColor> &GetParsedDefaultAttrsOfAKind(
TColor *)
52 return std::get<0>(GetParsedDefaultAttrs());
55 static ParsedAttrs_t<long long> &GetParsedDefaultAttrsOfAKind(
long long *)
57 return std::get<1>(GetParsedDefaultAttrs());
59 static ParsedAttrs_t<double> &GetParsedDefaultAttrsOfAKind(
double *)
61 return std::get<2>(GetParsedDefaultAttrs());
66 template <
class PRIMITIVE>
68 const PRIMITIVE &deflt,
const std::vector<std::string_view> &optStrings)
70 std::string fullName = opts.
GetName() +
"." + attrName;
71 static constexpr PRIMITIVE *kNullPtr = (PRIMITIVE *)
nullptr;
72 auto &parsedAttrs = GetParsedDefaultAttrsOfAKind(kNullPtr);
76 auto iIdx = parsedAttrs.find(fullName);
77 if (iIdx == parsedAttrs.end()) {
81 parsedAttrs[fullName] = *
this;
83 fIdx = opts.
SameAs(iIdx->second);
87 const auto &defaultTable = defCanv.
GetAttrTable((PRIMITIVE *)
nullptr);
88 PRIMITIVE val = defaultTable.Get(parsedAttrs[fullName]);
94 namespace Experimental {
101 template <
class PRIMITIVE>
105 R__ERROR_HERE(
"Gpad") <<
"Refusing to clear a referenced primitive (use count " << fUseCount <<
")!";
112 template <
class PRIMITIVE>
116 R__ERROR_HERE(
"Gpad") <<
"Refusing to create a primitive over an existing one (use count " << fUseCount <<
")!";
120 new (&fVal) PRIMITIVE(val);
124 template <
class PRIMITIVE>
127 if (fUseCount == 0) {
128 R__ERROR_HERE(
"Gpad") <<
"Refusing to increase use count on a non-existing primitive!";
134 template <
class PRIMITIVE>
137 if (fUseCount == 0) {
138 R__ERROR_HERE(
"Gpad") <<
"Refusing to decrease use count on a non-existing primitive!";
151 template <
class PRIMITIVE>
154 auto isFree = [](
const value_type &el) ->
bool {
return el.IsFree(); };
155 auto iSlot = std::find_if(fTable.begin(), fTable.end(), isFree);
156 if (iSlot != fTable.end()) {
158 std::ptrdiff_t offset = iSlot - fTable.begin();
159 assert(offset >= 0 &&
"This offset cannot possibly be negative!");
162 fTable.emplace_back(val);
166 template <
class PRIMITIVE>
169 if (&fTable.front().Get() > &val || &fTable.back().Get() < &val)
171 std::ptrdiff_t offset = &val - &fTable.front().Get();
172 assert(offset >= 0 &&
"Logic error, how can offset be < 0?");
183 template <
class PRIMITIVE>
187 fRefArray.push_back(canv.
GetAttrTable((PRIMITIVE *)
nullptr).Register(val));
188 return fRefArray.back();
191 template <
class PRIMITIVE>
199 template <
class PRIMITIVE>
203 return canv.
GetAttrTable((PRIMITIVE *)
nullptr).SameAs(val);
206 template <
class PRIMITIVE>
208 const PRIMITIVE &val)
210 canv.
GetAttrTable((PRIMITIVE *)
nullptr).Update(idx, val);
213 template <
class PRIMITIVE>
216 for (
auto idx: fRefArray)
221 template <
class PRIMITIVE>
224 for (
auto idx: fRefArray)
228 template <
class PRIMITIVE>
231 return canv.
GetAttrTable((PRIMITIVE *)
nullptr).Get(idx);
234 template <
class PRIMITIVE>
237 return canv.
GetAttrTable((PRIMITIVE *)
nullptr).Get(idx);
240 template <
class PRIMITIVE>
243 if (!fRefArray.empty())
244 R__ERROR_HERE(
"Gpad") <<
"Drawing attributes table not empty - must call Release() before!";
Internal::TDrawingAttrTable< TColor > & GetAttrTable(TColor *)
Attribute table (non-const access).
Namespace for new ROOT classes and functions.
void IncrUse()
Increase the use count; use count must be >= 1 before (i.e. does not create or "resurrect" values)...
A window's topmost TPad.
void Create(const PRIMITIVE &val)
Create a value, initializing use count to 1.
TColor Parse(std::string_view attr, const TColor &deflt, std::vector< std::string_view >={})
Convenience overloads:
TDrawingAttrRef< PRIMITIVE > SameAs(TDrawingAttrRef< PRIMITIVE > idx)
static TStyle & GetCurrent()
Get the current TStyle.
void RegisterCopy(TCanvas &canv)
Once copied, elements of a OptsAttrRefArr need to increase their use count.
std::unordered_map< std::string, std::string > Attrs_t
const PRIMITIVE & Get(TCanvas &canv, TDrawingAttrRef< PRIMITIVE > idx) const
Access to attribute (const version).
void Update(TCanvas &canv, TDrawingAttrRef< PRIMITIVE > idx, const PRIMITIVE &val)
Update the attribute at index idx to the value val.
TCanvas & GetCanvas()
The TCanvas holding the TDrawable (or its TPad) (non-const version).
static bool IsDefaultCanvas(const TPadBase &canv)
Whether the canvas is one of the canvases used to store attribute defaults.
void Release(TCanvas &canv)
Clear all attribute references, removing their uses in TCanvas.
void DecrUse()
Decrease the use count; use count must be >= 1 before the call. Calls Clear() if use count drops to 0...
const std::string & GetName() const
Get the (style config) name of this option set.
TDrawingAttrRef()=default
Construct an invalid reference.
void Clear()
Clear the value; use count must be 0.
TDrawingAttrRef< PRIMITIVE > Register(const PRIMITIVE &val)
Register an attribute with the table.
TDrawingAttrRef< PRIMITIVE > Register(const PRIMITIVE &val)
The TCanvas keep track of TColors, integer and floating point attributes used by the drawing options...
static TPadBase & GetDefaultCanvas(const TStyle &style)
Default attributes need to register their values in a pad - they will take this pad for default attri...
static Attrs_t ReadDefaults()
Reads the attribute config values from .rootstylerc.
TDrawingAttrRef< PRIMITIVE > Register(TCanvas &canv, const PRIMITIVE &val)
Register an attribute.
A color: Red|Green|Blue|Alpha, or a position in a TPalette.
TDrawingAttrRef< PRIMITIVE > SameAs(const PRIMITIVE &val)
Find the index belonging to the attribute at the given address and add a use.
TDrawingAttrRef< PRIMITIVE > SameAs(TCanvas &canv, TDrawingAttrRef< PRIMITIVE > idx)
Re-use an existing attribute.
#define R__ERROR_HERE(GROUP)