Logo ROOT   6.12/07
Reference Guide
TDrawingOptsReader.hxx
Go to the documentation of this file.
1 /// \file ROOT/TDrawingOptsReader.hxx
2 /// \ingroup Gpad ROOT7
3 /// \author Axel Naumann <axel@cern.ch>
4 /// \date 2017-09-29
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 #ifndef ROOT7_TDrawingOptsReader
17 #define ROOT7_TDrawingOptsReader
18 
19 #include <ROOT/TColor.hxx>
20 
21 #include <RStringView.h>
22 
23 #include <unordered_map>
24 #include <vector>
25 
26 namespace ROOT {
27 namespace Experimental {
28 namespace Internal {
29 /** \class ROOT::Experimental::TFrame
30  Reads the attribute config values from `.rootstylerc`. If the style entry is not found there, tries `~/.rootstylerc`
31  and finally `$ROOTSYS/system.rootstylerc`.
32  */
34 public:
35  using Attrs_t = std::unordered_map<std::string, std::string>;
36 
37 private:
38  /// Attributes to operate on.
40 
41 public:
42  TDrawingOptsReader(Attrs_t &attrs): fAttrs(attrs) {}
43 
44  /// Reads the attribute config values from `.rootstylerc`. If the style entry is not found there, tries
45  /// `~/.rootstylerc` and finally `$ROOTSYS/system.rootstylerc`.
46 
47  static Attrs_t ReadDefaults();
48 
49  /// Parse a TColor from attr's value.
50  /// Colors can be specified as RGBA (red green blue alpha) or RRGGBBAA:
51  /// #fa7f #ffa07bff
52  /// For all predefined colors in TColor, colors can be specified as name without leading 'k', e.g. `red` for
53  /// `TColor::kRed`.
54  /// Prints an error and returns `TColor::kBlack` if the attribute string cannot be parsed or if the attribute has no
55  /// entry in `fAttrs`.
56  TColor ParseColor(std::string_view attr, const TColor& deflt);
57 
58  /// Parse an integer attribute, or if `opts` is given, return the index of the string from the options file in
59  /// `opts`. Returns `0` (and prints an error) if the string cannot be found in opts, or if the integer cannot be
60  /// parsed or if the attribute has no entry in `fAttrs`.
61  long long ParseInt(std::string_view attr, long long deflt, std::vector<std::string_view> opts = {});
62 
63  /// Parse a floating point attribute.
64  /// Returns `0.` and prints an error if the attribute string cannot be parsed as a floating point number.
65  /// Prints an error if the attribute has no entry in `fAttrs`.
66  double ParseFP(std::string_view attr, double deflt);
67 
68  /// Convenience overloads:
69  TColor Parse(std::string_view attr, const TColor &deflt, std::vector<std::string_view> = {}) { return ParseColor(attr, deflt); }
70  long long Parse(std::string_view attr, long long deflt, std::vector<std::string_view> opts = {})
71  {
72  return ParseInt(attr, deflt, opts);
73  }
74  double Parse(std::string_view attr, double deflt, std::vector<std::string_view> = {}) { return ParseFP(attr, deflt); }
75 
76  /// Adds attributes specified in `filename` to those already existing in `fAttrs`.
77  /// Overwrites values for attributes that already exist in `attrs`!
78  /// \returns `true` on success, `false` if the file cannot be found or the syntax is wrong.
79  /// Prints an error if the syntax is wrong (but not if the file does not exist).
80  bool AddFromStyleFile(std::string_view filename);
81 };
82 } // namespace Internal
83 } // namespace Experimental
84 } // namespace ROOT
85 
86 #endif
long long ParseInt(std::string_view attr, long long deflt, std::vector< std::string_view > opts={})
Parse an integer attribute, or if opts is given, return the index of the string from the options file...
basic_string_view< char > string_view
Definition: RStringView.h:35
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
Attrs_t & fAttrs
Attributes to operate on.
TColor Parse(std::string_view attr, const TColor &deflt, std::vector< std::string_view >={})
Convenience overloads:
double Parse(std::string_view attr, double deflt, std::vector< std::string_view >={})
bool AddFromStyleFile(std::string_view filename)
Adds attributes specified in filename to those already existing in fAttrs.
TColor ParseColor(std::string_view attr, const TColor &deflt)
Parse a TColor from attr&#39;s value.
std::unordered_map< std::string, std::string > Attrs_t
static Attrs_t ReadDefaults()
Reads the attribute config values from .rootstylerc.
double ParseFP(std::string_view attr, double deflt)
Parse a floating point attribute.
A color: Red|Green|Blue|Alpha, or a position in a TPalette.
Definition: TColor.hxx:27
long long Parse(std::string_view attr, long long deflt, std::vector< std::string_view > opts={})