Logo ROOT   6.18/05
Reference Guide
RStyle.cxx
Go to the documentation of this file.
1/// \file RStyle.cxx
2/// \ingroup Gpad ROOT7
3/// \author Axel Naumann <axel@cern.ch>
4/// \date 2017-10-11
5/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6/// is welcome!
7
8/*************************************************************************
9 * Copyright (C) 1995-2017, Rene Brun and Fons Rademakers. *
10 * All rights reserved. *
11 * *
12 * For the licensing terms see $ROOTSYS/LICENSE. *
13 * For the list of contributors see $ROOTSYS/README/CREDITS. *
14 *************************************************************************/
15
16#include "ROOT/RStyle.hxx"
17
18#include "ROOT/RLogger.hxx"
19#include "ROOT/RPadExtent.hxx"
20#include "ROOT/RPadPos.hxx"
21
22#include "RStyleReader.hxx" // in src/
23
24#include <ROOT/RStringView.hxx>
25
26#include <cassert>
27#include <limits>
28#include <string>
29#include <sstream>
30
31using namespace ROOT::Experimental;
32
33namespace {
34static Internal::RStyleReader::AllStyles_t ReadGlobalDefaultStyles()
35{
37 Internal::RStyleReader reader(target);
38 reader.ReadDefaults();
39 return target;
40}
41
42static Internal::RStyleReader::AllStyles_t &GetGlobalStyles()
43{
44 static Internal::RStyleReader::AllStyles_t sStyles = ReadGlobalDefaultStyles();
45 return sStyles;
46}
47} // unnamed namespace
48
49RStyle &RStyle::Register(RStyle&& style)
50{
51 RStyle& ret = GetGlobalStyles()[style.GetName()];
52 ret = style;
53 return ret;
54}
55
57{
58 auto iStyle = GetGlobalStyles().find(std::string(name));
59 if (iStyle != GetGlobalStyles().end())
60 return &iStyle->second;
61 return nullptr;
62}
63
64
65namespace {
66static RStyle GetInitialCurrent()
67{
68 static constexpr const char* kDefaultStyleName = "plain";
69 auto iDefStyle = GetGlobalStyles().find(std::string(kDefaultStyleName));
70 if (iDefStyle == GetGlobalStyles().end()) {
71 R__INFO_HERE("Gpad") << "Cannot find initial default style named \"" << kDefaultStyleName
72 << "\", using an empty one.";
73 RStyle defStyle(kDefaultStyleName);
74 return RStyle::Register(std::move(defStyle));
75 } else {
76 return iDefStyle->second;
77 }
78}
79}
80
82{
83 static RStyle sCurrentStyle = GetInitialCurrent();
84 return sCurrentStyle;
85}
86
87std::string RStyle::GetAttribute(const std::string &attrName, const std::string &/*className*/) const {
88 std::string trailingPart(attrName);
89 while (!trailingPart.empty()) {
90 auto iter = fAttrs.find(trailingPart);
91 if (iter != fAttrs.end())
92 return iter->second;
93 auto posDot = trailingPart.find('.');
94 if (posDot != std::string::npos) {
95 trailingPart.erase(0, posDot + 1);
96 } else {
97 return {};
98 }
99 }
100 return {};
101}
#define R__INFO_HERE(GROUP)
Definition: RLogger.hxx:185
char name[80]
Definition: TGX11.cxx:109
std::unordered_map< std::string, RStyle > AllStyles_t
Key is the style name.
A set of defaults for graphics attributes, e.g.
Definition: RStyle.hxx:34
static RStyle & Register(RStyle &&style)
Move-register style in the global style collection, possibly replacing a global style with the same n...
Definition: RStyle.cxx:49
static RStyle & GetCurrent()
Get the current RStyle.
Definition: RStyle.cxx:81
static RStyle * Get(std::string_view name)
Get the RStyle named name from the global style collection, or nullptr if that doesn't exist.
Definition: RStyle.cxx:56
std::string GetAttribute(const std::string &attrName, const std::string &className={}) const
Get the style value as a string, given an attribute name.
Definition: RStyle.cxx:87
const char * GetName() const
Returns name of object.
Definition: TPad.h:255
basic_string_view< char > string_view
TCanvas * style()
Definition: style.C:1