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\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
34*/
35
36
37class RProvider {
38
39public:
40
41 virtual ~RProvider();
42
43 using ProgressFunc_t = std::function<void(float progress, void *handle)>;
44
45 class ClassArg {
46 friend class RProvider;
47 const TClass *cl{nullptr};
48 std::string name;
49 ClassArg() = delete;
50 public:
51 ClassArg(const TClass *_cl) : cl(_cl) {}
52 ClassArg(const std::string &_name) : name(_name) {}
53 ClassArg(const char *_name) : name(_name) {}
54
55 bool empty() const { return !cl && name.empty(); }
56 const TClass *GetClass() const { return cl; }
57 const std::string &GetName() const { return name; }
58 };
59
61 friend class RProvider;
62 void *fHandle{nullptr};
63
64 ProgressHandle(const ProgressHandle &) = delete;
66 public:
67 explicit ProgressHandle(void *handle, ProgressFunc_t func);
69 void Extend(void *handle2);
70 };
71
72 friend class ProgressHandle;
73
74 static std::string GetClassIcon(const ClassArg &, bool = false);
75 static std::string GetClassDrawOption(const ClassArg &);
76 static bool SetClassDrawOption(const ClassArg &, const std::string &);
77
78 static bool CanHaveChilds(const ClassArg &);
79 static bool NotShowChilds(const ClassArg &);
80 static bool CanDraw6(const ClassArg &);
81 static bool CanDraw7(const ClassArg &);
82
83 static bool IsFileFormatSupported(const std::string &extension);
84 static std::shared_ptr<RElement> OpenFile(const std::string &extension, const std::string &fullname);
85 static std::shared_ptr<RElement> Browse(std::unique_ptr<RHolder> &obj);
86 static std::shared_ptr<RElement> BrowseNTuple(const std::string &tuplename, const std::string &filename);
87 static bool Draw6(TVirtualPad *subpad, std::unique_ptr<RHolder> &obj, const std::string &opt = "");
88 static bool Draw7(std::shared_ptr<ROOT::Experimental::RPadBase> &subpad, std::unique_ptr<RHolder> &obj, const std::string &opt = "");
89
90 static void ExtendProgressHandle(void *handle, void *handle2);
91 static bool ReportProgress(void *handle, float progress);
92
93protected:
94
95 using FileFunc_t = std::function<std::shared_ptr<RElement>(const std::string &)>;
96 using BrowseFunc_t = std::function<std::shared_ptr<RElement>(std::unique_ptr<RHolder> &)>;
97 using BrowseNTupleFunc_t = std::function<std::shared_ptr<RElement>(const std::string &, const std::string &)>;
98 using Draw6Func_t = std::function<bool(TVirtualPad *, std::unique_ptr<RHolder> &, const std::string &)>;
99 using Draw7Func_t = std::function<bool(std::shared_ptr<ROOT::Experimental::RPadBase> &, std::unique_ptr<RHolder> &, const std::string &)>;
100
101 void RegisterFile(const std::string &extension, FileFunc_t func);
102 void RegisterBrowse(const TClass *cl, BrowseFunc_t func);
103 void RegisterDraw6(const TClass *cl, Draw6Func_t func);
104 void RegisterDraw7(const TClass *cl, Draw7Func_t func);
105 void RegisterClass(const std::string &clname,
106 const std::string &iconname,
107 const std::string &browselib = "",
108 const std::string &draw6lib = "",
109 const std::string &draw7lib = "",
110 const std::string &drawopt = "");
112
113private:
114
119 struct StructProgress { void *handle{nullptr}, *handle2{nullptr}; ProgressFunc_t func; };
120
121 struct StructClass {
123 bool can_have_childs{false};
125 bool dummy() const { return !provider; }
126 };
127
128 using ClassMap_t = std::multimap<std::string, StructClass>;
129 using FileMap_t = std::multimap<std::string, StructFile>;
130 using BrowseMap_t = std::multimap<const TClass*, StructBrowse>;
131 using Draw6Map_t = std::multimap<const TClass*, StructDraw6>;
132 using Draw7Map_t = std::multimap<const TClass*, StructDraw7>;
133 using ProgressVect_t = std::vector<StructProgress>;
134
135 static ClassMap_t &GetClassMap();
136 static FileMap_t &GetFileMap();
137 static BrowseMap_t &GetBrowseMap();
138 static Draw6Map_t &GetDraw6Map();
139 static Draw7Map_t &GetDraw7Map();
142
143 static StructClass &GetClassEntry(const ClassArg &);
144
145 template<class Map_t>
146 void CleanThis(Map_t &fmap)
147 {
148 if (fmap.empty())
149 return;
150 auto fiter = fmap.begin();
151 while (fiter != fmap.end()) {
152 if (fiter->second.provider == this)
153 fiter = fmap.erase(fiter);
154 else
155 fiter++;
156 }
157 }
158
159};
160
161
162} // namespace Browsable
163} // namespace ROOT
164
165#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:8026
const std::string & GetName() const
Definition RProvider.hxx:57
ClassArg(const std::string &_name)
Definition RProvider.hxx:52
const TClass * GetClass() const
Definition RProvider.hxx:56
ProgressHandle & operator=(const ProgressHandle &)=delete
void Extend(void *handle2)
Extend progress handle.
ProgressHandle(const ProgressHandle &)=delete
~ProgressHandle()
Destroy progress handle.
Provider of different browsing methods for supported classes.
Definition RProvider.hxx:37
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:95
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:43
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:98
void RegisterBrowse(const TClass *cl, BrowseFunc_t func)
std::function< std::shared_ptr< RElement >(std::unique_ptr< RHolder > &)> BrowseFunc_t
Definition RProvider.hxx:96
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:99
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:97
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
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...