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 {
21namespace Experimental {
22
23class RPadBase;
24
25namespace Browsable {
26
27/** \class RProvider
28\ingroup rbrowser
29\brief Provider of different browsing methods for supported classes
30\author Sergey Linev <S.Linev@gsi.de>
31\date 2019-10-14
32\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
33*/
34
35
36class RProvider {
37
38public:
39
40 virtual ~RProvider();
41
42 class ClassArg {
43 friend class RProvider;
44 const TClass *cl{nullptr};
45 std::string name;
46 ClassArg() = delete;
47 public:
48 ClassArg(const TClass *_cl) : cl(_cl) {}
49 ClassArg(const std::string &_name) : name(_name) {}
50 ClassArg(const char *_name) : name(_name) {}
51
52 bool empty() const { return !cl && name.empty(); }
53 const TClass *GetClass() const { return cl; }
54 const std::string &GetName() const { return name; }
55 };
56
57 static std::string GetClassIcon(const ClassArg &, bool = false);
58 static std::string GetClassDrawOption(const ClassArg &);
59 static bool SetClassDrawOption(const ClassArg &, const std::string &);
60
61 static bool CanHaveChilds(const ClassArg &);
62 static bool NotShowChilds(const ClassArg &);
63 static bool CanDraw6(const ClassArg &);
64 static bool CanDraw7(const ClassArg &);
65
66 static bool IsFileFormatSupported(const std::string &extension);
67 static std::shared_ptr<RElement> OpenFile(const std::string &extension, const std::string &fullname);
68 static std::shared_ptr<RElement> Browse(std::unique_ptr<RHolder> &obj);
69 static std::shared_ptr<RElement> BrowseNTuple(const std::string &tuplename, const std::string &filename);
70 static bool Draw6(TVirtualPad *subpad, std::unique_ptr<RHolder> &obj, const std::string &opt = "");
71 static bool Draw7(std::shared_ptr<ROOT::Experimental::RPadBase> &subpad, std::unique_ptr<RHolder> &obj, const std::string &opt = "");
72
73protected:
74
75 using FileFunc_t = std::function<std::shared_ptr<RElement>(const std::string &)>;
76 using BrowseFunc_t = std::function<std::shared_ptr<RElement>(std::unique_ptr<RHolder> &)>;
77 using BrowseNTupleFunc_t = std::function<std::shared_ptr<RElement>(const std::string &, const std::string &)>;
78 using Draw6Func_t = std::function<bool(TVirtualPad *, std::unique_ptr<RHolder> &, const std::string &)>;
79 using Draw7Func_t = std::function<bool(std::shared_ptr<ROOT::Experimental::RPadBase> &, std::unique_ptr<RHolder> &, const std::string &)>;
80
81 void RegisterFile(const std::string &extension, FileFunc_t func);
82 void RegisterBrowse(const TClass *cl, BrowseFunc_t func);
83 void RegisterDraw6(const TClass *cl, Draw6Func_t func);
84 void RegisterDraw7(const TClass *cl, Draw7Func_t func);
85 void RegisterClass(const std::string &clname,
86 const std::string &iconname,
87 const std::string &browselib = "",
88 const std::string &draw6lib = "",
89 const std::string &draw7lib = "",
90 const std::string &drawopt = "");
92
93private:
94
99 struct StructClass {
101 bool can_have_childs{false};
103 bool dummy() const { return !provider; }
104 };
105
106 using ClassMap_t = std::multimap<std::string, StructClass>;
107 using FileMap_t = std::multimap<std::string, StructFile>;
108 using BrowseMap_t = std::multimap<const TClass*, StructBrowse>;
109 using Draw6Map_t = std::multimap<const TClass*, StructDraw6>;
110 using Draw7Map_t = std::multimap<const TClass*, StructDraw7>;
111
112 static ClassMap_t &GetClassMap();
113 static FileMap_t &GetFileMap();
114 static BrowseMap_t &GetBrowseMap();
115 static Draw6Map_t &GetDraw6Map();
116 static Draw7Map_t &GetDraw7Map();
118
119 static StructClass &GetClassEntry(const ClassArg &);
120
121 template<class Map_t>
122 void CleanThis(Map_t &fmap)
123 {
124 if (fmap.empty())
125 return;
126 auto fiter = fmap.begin();
127 while (fiter != fmap.end()) {
128 if (fiter->second.provider == this)
129 fiter = fmap.erase(fiter);
130 else
131 fiter++;
132 }
133 }
134
135};
136
137
138} // namespace Browsable
139} // namespace Experimental
140} // namespace ROOT
141
142#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:8024
Provider of different browsing methods for supported classes.
Definition RProvider.hxx:36
void RegisterDraw7(const TClass *cl, Draw7Func_t func)
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="")
std::function< bool(std::shared_ptr< ROOT::Experimental::RPadBase > &, std::unique_ptr< RHolder > &, const std::string &)> Draw7Func_t
Definition RProvider.hxx:79
static bool CanDraw6(const ClassArg &)
Return true if provided class can be drawn on the TCanvas.
static bool SetClassDrawOption(const ClassArg &, const std::string &)
Set draw option for the class Return true if entry for the class exists.
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...
virtual ~RProvider()
Automatically unregister provider from all maps.
Definition RProvider.cxx:75
std::multimap< std::string, StructClass > ClassMap_t
static std::string GetClassIcon(const ClassArg &, bool=false)
Return icon name for the given class - either class name or TClass *.
std::multimap< std::string, StructFile > FileMap_t
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...
void RegisterFile(const std::string &extension, FileFunc_t func)
Definition RProvider.cxx:88
static bool IsFileFormatSupported(const std::string &extension)
std::function< std::shared_ptr< RElement >(const std::string &, const std::string &)> BrowseNTupleFunc_t
Definition RProvider.hxx:77
std::function< std::shared_ptr< RElement >(std::unique_ptr< RHolder > &)> BrowseFunc_t
Definition RProvider.hxx:76
std::multimap< const TClass *, StructBrowse > BrowseMap_t
void RegisterBrowse(const TClass *cl, BrowseFunc_t func)
void RegisterNTupleFunc(BrowseNTupleFunc_t func)
std::function< std::shared_ptr< RElement >(const std::string &)> FileFunc_t
Definition RProvider.hxx:75
static bool CanHaveChilds(const ClassArg &)
Return true if provided class can have childs.
std::function< bool(TVirtualPad *, std::unique_ptr< RHolder > &, const std::string &)> Draw6Func_t
Definition RProvider.hxx:78
static StructClass & GetClassEntry(const ClassArg &)
static std::shared_ptr< RElement > OpenFile(const std::string &extension, const std::string &fullname)
std::multimap< const TClass *, StructDraw7 > Draw7Map_t
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< const TClass *, StructDraw6 > Draw6Map_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
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.