Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RProvider.hxx
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (C) 1995-2020, 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_Browsable_RProvider
10#define ROOT7_Browsable_RProvider
11
13
14#include <functional>
15#include <map>
16#include <memory>
17
18class TVirtualPad;
19
20namespace ROOT {
21
22namespace Experimental {
23class RPadBase;
24} // namespace Experimental
25
26namespace Browsable {
27
28/** \class RProvider
29\ingroup rbrowser
30\brief Provider of different browsing methods for supported classes
31\author Sergey Linev <S.Linev@gsi.de>
32\date 2019-10-14
33*/
34
35
36class RProvider {
37
38public:
39
40 virtual ~RProvider();
41
42 using ProgressFunc_t = std::function<void(float progress, void *handle)>;
43
44 class ClassArg {
45 friend class RProvider;
46 const TClass *cl{nullptr};
47 std::string name;
48 ClassArg() = delete;
49 public:
50 ClassArg(const TClass *_cl) : cl(_cl) {}
51 ClassArg(const std::string &_name) : name(_name) {}
52 ClassArg(const char *_name) : name(_name) {}
53
54 bool empty() const { return !cl && name.empty(); }
55 const TClass *GetClass() const { return cl; }
56 const std::string &GetName() const { return name; }
57 };
58
60 friend class RProvider;
61 void *fHandle{nullptr};
62
63 ProgressHandle(const ProgressHandle &) = delete;
65 public:
66 explicit ProgressHandle(void *handle, ProgressFunc_t func);
68 void Extend(void *handle2);
69 };
70
71 friend class ProgressHandle;
72
73 static std::string GetClassIcon(const ClassArg &, bool = false);
74 static std::string GetClassDrawOption(const ClassArg &);
75 static bool SetClassDrawOption(const ClassArg &, const std::string &);
76
77 static bool CanHaveChilds(const ClassArg &);
78 static bool NotShowChilds(const ClassArg &);
79 static bool CanDraw6(const ClassArg &);
80 static bool CanDraw7(const ClassArg &);
81
82 static bool IsFileFormatSupported(const std::string &extension);
83 static std::shared_ptr<RElement> OpenFile(const std::string &extension, const std::string &fullname);
84 static std::shared_ptr<RElement> Browse(std::unique_ptr<RHolder> &obj);
85 static std::shared_ptr<RElement> BrowseNTuple(const std::string &tuplename, const std::string &filename);
86 static bool Draw6(TVirtualPad *subpad, std::unique_ptr<RHolder> &obj, const std::string &opt = "");
87 static bool Draw7(std::shared_ptr<ROOT::Experimental::RPadBase> &subpad, std::unique_ptr<RHolder> &obj, const std::string &opt = "");
88
89 static void ExtendProgressHandle(void *handle, void *handle2);
90 static bool ReportProgress(void *handle, float progress);
91
92protected:
93
94 using FileFunc_t = std::function<std::shared_ptr<RElement>(const std::string &)>;
95 using BrowseFunc_t = std::function<std::shared_ptr<RElement>(std::unique_ptr<RHolder> &)>;
96 using BrowseNTupleFunc_t = std::function<std::shared_ptr<RElement>(const std::string &, const std::string &)>;
97 using Draw6Func_t = std::function<bool(TVirtualPad *, std::unique_ptr<RHolder> &, const std::string &)>;
98 using Draw7Func_t = std::function<bool(std::shared_ptr<ROOT::Experimental::RPadBase> &, std::unique_ptr<RHolder> &, const std::string &)>;
99
100 void RegisterFile(const std::string &extension, FileFunc_t func);
101 void RegisterBrowse(const TClass *cl, BrowseFunc_t func);
102 void RegisterDraw6(const TClass *cl, Draw6Func_t func);
103 void RegisterDraw7(const TClass *cl, Draw7Func_t func);
104 void RegisterClass(const std::string &clname,
105 const std::string &iconname,
106 const std::string &browselib = "",
107 const std::string &draw6lib = "",
108 const std::string &draw7lib = "",
109 const std::string &drawopt = "");
111
112private:
113
118 struct StructProgress { void *handle{nullptr}, *handle2{nullptr}; ProgressFunc_t func; };
119
120 struct StructClass {
122 bool can_have_childs{false};
124 bool dummy() const { return !provider; }
125 };
126
127 using ClassMap_t = std::multimap<std::string, StructClass>;
128 using FileMap_t = std::multimap<std::string, StructFile>;
129 using BrowseMap_t = std::multimap<const TClass*, StructBrowse>;
130 using Draw6Map_t = std::multimap<const TClass*, StructDraw6>;
131 using Draw7Map_t = std::multimap<const TClass*, StructDraw7>;
132 using ProgressVect_t = std::vector<StructProgress>;
133
134 static ClassMap_t &GetClassMap();
135 static FileMap_t &GetFileMap();
136 static BrowseMap_t &GetBrowseMap();
137 static Draw6Map_t &GetDraw6Map();
138 static Draw7Map_t &GetDraw7Map();
141
142 static StructClass &GetClassEntry(const ClassArg &);
143
144 template<class Map_t>
145 void CleanThis(Map_t &fmap)
146 {
147 if (fmap.empty())
148 return;
149 auto fiter = fmap.begin();
150 while (fiter != fmap.end()) {
151 if (fiter->second.provider == this)
152 fiter = fmap.erase(fiter);
153 else
154 fiter++;
155 }
156 }
157
158};
159
160
161} // namespace Browsable
162} // namespace ROOT
163
164#endif
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
const char * extension
Definition civetweb.c:8515
const std::string & GetName() const
Definition RProvider.hxx:56
ClassArg(const std::string &_name)
Definition RProvider.hxx:51
const TClass * GetClass() const
Definition RProvider.hxx:55
ProgressHandle & operator=(const ProgressHandle &)=delete
void Extend(void *handle2)
Extend progress handle.
ProgressHandle(const ProgressHandle &)=delete
~ProgressHandle()
Destroy progress handle.
ProgressHandle(void *handle, ProgressFunc_t func)
Provider of different browsing methods for supported classes.
Definition RProvider.hxx:36
void RegisterDraw7(const TClass *cl, Draw7Func_t func)
static bool ReportProgress(void *handle, float progress)
Report running progress Returns true if handling function was invoked Method can be used to detect if...
static ProgressVect_t & GetProgressVect()
Definition RProvider.cxx:71
static std::shared_ptr< RElement > BrowseNTuple(const std::string &tuplename, const std::string &filename)
Start browsing of RNTuple.
void RegisterClass(const std::string &clname, const std::string &iconname, const std::string &browselib="", const std::string &draw6lib="", const std::string &draw7lib="", const std::string &drawopt="")
static bool CanDraw6(const ClassArg &)
Return true if provided class can be drawn on the TCanvas.
static ClassMap_t & GetClassMap()
Definition RProvider.cxx:62
static bool SetClassDrawOption(const ClassArg &, const std::string &)
Set draw option for the class Return true if entry for the class exists.
static FileMap_t & GetFileMap()
Definition RProvider.cxx:35
void RegisterDraw6(const TClass *cl, Draw6Func_t func)
static std::shared_ptr< RElement > Browse(std::unique_ptr< RHolder > &obj)
Create browsable element for the object Created element may take ownership over the object.
static bool CanDraw7(const ClassArg &)
Return true if provided class can be drawn on the RCanvas.
static BrowseNTupleFunc_t gNTupleFunc
static bool Draw6(TVirtualPad *subpad, std::unique_ptr< RHolder > &obj, const std::string &opt="")
Invoke drawing of object on TCanvas sub-pad All existing providers are checked, first checked are cla...
std::multimap< const TClass *, StructDraw6 > Draw6Map_t
virtual ~RProvider()
Automatically unregister provider from all maps.
Definition RProvider.cxx:82
std::function< std::shared_ptr< RElement >(const std::string &)> FileFunc_t
Definition RProvider.hxx:94
static std::string GetClassIcon(const ClassArg &, bool=false)
Return icon name for the given class - either class name or TClass *.
static bool Draw7(std::shared_ptr< ROOT::Experimental::RPadBase > &subpad, std::unique_ptr< RHolder > &obj, const std::string &opt="")
Invoke drawing of object on RCanvas sub-pad All existing providers are checked, first checked are cla...
std::function< void(float progress, void *handle)> ProgressFunc_t
Definition RProvider.hxx:42
std::multimap< const TClass *, StructBrowse > BrowseMap_t
void RegisterFile(const std::string &extension, FileFunc_t func)
Definition RProvider.cxx:95
static bool IsFileFormatSupported(const std::string &extension)
static Draw7Map_t & GetDraw7Map()
Definition RProvider.cxx:53
std::function< bool(TVirtualPad *, std::unique_ptr< RHolder > &, const std::string &)> Draw6Func_t
Definition RProvider.hxx:97
void RegisterBrowse(const TClass *cl, BrowseFunc_t func)
std::function< std::shared_ptr< RElement >(std::unique_ptr< RHolder > &)> BrowseFunc_t
Definition RProvider.hxx:95
void RegisterNTupleFunc(BrowseNTupleFunc_t func)
static bool CanHaveChilds(const ClassArg &)
Return true if provided class can have childs.
static BrowseMap_t & GetBrowseMap()
Definition RProvider.cxx:26
static StructClass & GetClassEntry(const ClassArg &)
std::function< bool(std::shared_ptr< ROOT::Experimental::RPadBase > &, std::unique_ptr< RHolder > &, const std::string &)> Draw7Func_t
Definition RProvider.hxx:98
static std::shared_ptr< RElement > OpenFile(const std::string &extension, const std::string &fullname)
std::vector< StructProgress > ProgressVect_t
void CleanThis(Map_t &fmap)
std::multimap< std::string, StructFile > FileMap_t
static Draw6Map_t & GetDraw6Map()
Definition RProvider.cxx:44
std::function< std::shared_ptr< RElement >(const std::string &, const std::string &)> BrowseNTupleFunc_t
Definition RProvider.hxx:96
static bool NotShowChilds(const ClassArg &)
Check if showing of sub-elements was disabled.
static std::string GetClassDrawOption(const ClassArg &)
Return configured draw option for the class.
std::multimap< std::string, StructClass > ClassMap_t
static void ExtendProgressHandle(void *handle, void *handle2)
Extend progress handle - to be able react on sub item.
std::multimap< const TClass *, StructDraw7 > Draw7Map_t
const_iterator begin() const
const_iterator end() const
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51