Logo ROOT  
Reference Guide
RDrawable.hxx
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (C) 1995-2015, Rene Brun and Fons Rademakers. *
3 * All rights reserved. *
4 * *
5 * For the licensing terms see $ROOTSYS/LICENSE. *
6 * For the list of contributors see $ROOTSYS/README/CREDITS. *
7 *************************************************************************/
8
9#ifndef ROOT7_RDrawable
10#define ROOT7_RDrawable
11
12#include <memory>
13#include <string>
14#include <vector>
15
16#include <ROOT/RAttrMap.hxx>
17#include <ROOT/RStyle.hxx>
18
19
20namespace ROOT {
21namespace Experimental {
22
23class RMenuItems;
24class RPadBase;
25class RAttrBase;
26class RDisplayItem;
27class RLegend;
28
29
30namespace Internal {
31
32/** \class RIOSharedBase
33\ingroup GpadROOT7
34\author Sergey Linev <s.linev@gsi.de>
35\date 2019-09-24
36\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
37*/
38
40public:
41 virtual const void *GetIOPtr() const = 0;
42 virtual bool HasShared() const = 0;
43 virtual void *MakeShared() = 0;
44 virtual void SetShared(void *shared) = 0;
45 virtual ~RIOSharedBase() = default;
46};
47
48using RIOSharedVector_t = std::vector<RIOSharedBase *>;
49
50template<class T>
51class RIOShared final : public RIOSharedBase {
52 std::shared_ptr<T> fShared; ///<! holder of object
53 T* fIO{nullptr}; ///< plain pointer for IO
54public:
55 const void *GetIOPtr() const final { return fIO; }
56 virtual bool HasShared() const final { return fShared.get() != nullptr; }
57 virtual void *MakeShared() final { fShared.reset(fIO); return &fShared; }
58 virtual void SetShared(void *shared) final { fShared = *((std::shared_ptr<T> *) shared); }
59
60 RIOShared() = default;
61
62 RIOShared(const std::shared_ptr<T> &ptr) : RIOSharedBase()
63 {
64 fShared = ptr;
65 fIO = ptr.get();
66 }
67
68 RIOShared &operator=(const std::shared_ptr<T> &ptr)
69 {
70 fShared = ptr;
71 fIO = ptr.get();
72 return *this;
73 }
74
75 operator bool() const { return !!fShared || !!fIO; }
76
77 const T *get() const { return fShared ? fShared.get() : fIO; }
78 T *get() { return fShared ? fShared.get() : fIO; }
79
80 const T *operator->() const { return get(); }
81 T *operator->() { return get(); }
82
83 std::shared_ptr<T> get_shared() const { return fShared; }
84
85 void reset() { fShared.reset(); fIO = nullptr; }
86};
87
88}
89
90/** \class RDrawable
91\ingroup GpadROOT7
92\brief Base class for drawable entities: objects that can be painted on a `RPad`.
93\author Axel Naumann <axel@cern.ch>
94\author Sergey Linev <s.linev@gsi.de>
95\date 2015-08-07
96\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
97*/
98
99class RDrawable {
100
101friend class RPadBase; // to access Display method
102friend class RAttrBase;
103friend class RStyle;
104friend class RLegend; // to access CollectShared method
105
106private:
107 RAttrMap fAttr; ///< attributes values
108 std::weak_ptr<RStyle> fStyle; ///<! style applied for RDrawable
109 std::string fCssType; ///<! drawable type, not stored in the root file, must be initialized in constructor
110 std::string fCssClass; ///< user defined drawable class, can later go inside map
111 std::string fId; ///< optional object identifier, may be used in CSS as well
112
113protected:
114
116
117 RAttrMap &GetAttrMap() { return fAttr; }
118 const RAttrMap &GetAttrMap() const { return fAttr; }
119
120 bool MatchSelector(const std::string &selector) const;
121
122 virtual std::unique_ptr<RDisplayItem> Display() const;
123
124public:
125
126 explicit RDrawable(const std::string &type) : fCssType(type) {}
127
128 virtual ~RDrawable();
129
130 // copy constructor and assign operator !!!
131
132 /** Method can be used to provide menu items for the drawn object */
133 virtual void PopulateMenu(RMenuItems &){};
134
135 virtual void Execute(const std::string &);
136
137 virtual void UseStyle(const std::shared_ptr<RStyle> &style) { fStyle = style; }
138 void ClearStyle() { UseStyle(nullptr); }
139
140 void SetCssClass(const std::string &cl) { fCssClass = cl; }
141 const std::string &GetCssClass() const { return fCssClass; }
142
143 const std::string &GetCssType() const { return fCssType; }
144
145 const std::string &GetId() const { return fId; }
146 void SetId(const std::string &id) { fId = id; }
147
148};
149
150/// Central method to insert drawable in list of pad primitives
151/// By default drawable placed as is.
152template <class DRAWABLE, std::enable_if_t<std::is_base_of<RDrawable, DRAWABLE>{}>* = nullptr>
153inline auto GetDrawable(const std::shared_ptr<DRAWABLE> &drawable)
154{
155 return drawable;
156}
157
158} // namespace Experimental
159} // namespace ROOT
160
161#endif
XFontStruct * id
Definition: TGX11.cxx:108
int type
Definition: TGX11.cxx:120
virtual void SetShared(void *shared)=0
virtual const void * GetIOPtr() const =0
std::shared_ptr< T > fShared
! holder of object
Definition: RDrawable.hxx:52
virtual void SetShared(void *shared) final
Definition: RDrawable.hxx:58
RIOShared(const std::shared_ptr< T > &ptr)
Definition: RDrawable.hxx:62
const void * GetIOPtr() const final
Definition: RDrawable.hxx:55
virtual void * MakeShared() final
Definition: RDrawable.hxx:57
virtual bool HasShared() const final
Definition: RDrawable.hxx:56
RIOShared & operator=(const std::shared_ptr< T > &ptr)
Definition: RDrawable.hxx:68
std::shared_ptr< T > get_shared() const
Definition: RDrawable.hxx:83
Base class for all attributes, used with RDrawable.
Definition: RAttrBase.hxx:27
Base class for drawable entities: objects that can be painted on a RPad.
Definition: RDrawable.hxx:99
const RAttrMap & GetAttrMap() const
Definition: RDrawable.hxx:118
virtual void PopulateMenu(RMenuItems &)
Method can be used to provide menu items for the drawn object.
Definition: RDrawable.hxx:133
std::weak_ptr< RStyle > fStyle
! style applied for RDrawable
Definition: RDrawable.hxx:108
const std::string & GetId() const
Definition: RDrawable.hxx:145
virtual void Execute(const std::string &)
Definition: RDrawable.cxx:20
void SetCssClass(const std::string &cl)
Definition: RDrawable.hxx:140
RAttrMap fAttr
attributes values
Definition: RDrawable.hxx:107
std::string fCssClass
user defined drawable class, can later go inside map
Definition: RDrawable.hxx:110
std::string fId
optional object identifier, may be used in CSS as well
Definition: RDrawable.hxx:111
const std::string & GetCssType() const
Definition: RDrawable.hxx:143
virtual std::unique_ptr< RDisplayItem > Display() const
Creates display item for drawable By default item contains drawble data itself.
Definition: RDrawable.cxx:42
virtual void UseStyle(const std::shared_ptr< RStyle > &style)
Definition: RDrawable.hxx:137
const std::string & GetCssClass() const
Definition: RDrawable.hxx:141
void SetId(const std::string &id)
Definition: RDrawable.hxx:146
virtual void CollectShared(Internal::RIOSharedVector_t &)
Definition: RDrawable.hxx:115
RDrawable(const std::string &type)
Definition: RDrawable.hxx:126
bool MatchSelector(const std::string &selector) const
Preliminary method which checks if drawable matches with given selector Following selector are allowe...
Definition: RDrawable.cxx:33
std::string fCssType
! drawable type, not stored in the root file, must be initialized in constructor
Definition: RDrawable.hxx:109
List of items for object context menu.
Definition: RMenuItem.hxx:151
Base class for graphic containers for RDrawable-s.
Definition: RPadBase.hxx:37
A set of defaults for graphics attributes, e.g.
Definition: RStyle.hxx:30
std::vector< RIOSharedBase * > RIOSharedVector_t
Definition: RDrawable.hxx:48
auto GetDrawable(const std::shared_ptr< DRAWABLE > &drawable)
Central method to insert drawable in list of pad primitives By default drawable placed as is.
Definition: RDrawable.hxx:153
double T(double x)
Definition: ChebyshevPol.h:34
VSD Structures.
Definition: StringConv.hxx:21
TCanvas * style()
Definition: style.C:1