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 bool CanHaveChilds(const ClassArg &);
59 static bool CanDraw6(const ClassArg &);
60 static bool CanDraw7(const ClassArg &);
61
62 static bool IsFileFormatSupported(const std::string &extension);
63 static std::shared_ptr<RElement> OpenFile(const std::string &extension, const std::string &fullname);
64 static std::shared_ptr<RElement> Browse(std::unique_ptr<RHolder> &obj);
65 static std::shared_ptr<RElement> BrowseNTuple(const std::string &tuplename, const std::string &filename);
66 static bool Draw6(TVirtualPad *subpad, std::unique_ptr<RHolder> &obj, const std::string &opt = "");
67 static bool Draw7(std::shared_ptr<ROOT::Experimental::RPadBase> &subpad, std::unique_ptr<RHolder> &obj, const std::string &opt = "");
68
69protected:
70
71 using FileFunc_t = std::function<std::shared_ptr<RElement>(const std::string &)>;
72 using BrowseFunc_t = std::function<std::shared_ptr<RElement>(std::unique_ptr<RHolder> &)>;
73 using BrowseNTupleFunc_t = std::function<std::shared_ptr<RElement>(const std::string &, const std::string &)>;
74 using Draw6Func_t = std::function<bool(TVirtualPad *, std::unique_ptr<RHolder> &, const std::string &)>;
75 using Draw7Func_t = std::function<bool(std::shared_ptr<ROOT::Experimental::RPadBase> &, std::unique_ptr<RHolder> &, const std::string &)>;
76
77 void RegisterFile(const std::string &extension, FileFunc_t func);
78 void RegisterBrowse(const TClass *cl, BrowseFunc_t func);
79 void RegisterDraw6(const TClass *cl, Draw6Func_t func);
80 void RegisterDraw7(const TClass *cl, Draw7Func_t func);
81 void RegisterClass(const std::string &clname,
82 const std::string &iconname,
83 const std::string &browselib = "",
84 const std::string &draw6lib = "",
85 const std::string &draw7lib = "");
87
88private:
89
94 struct StructClass {
96 bool can_have_childs{false};
98 bool dummy() const { return !provider; }
99 };
100
101 using ClassMap_t = std::multimap<std::string, StructClass>;
102 using FileMap_t = std::multimap<std::string, StructFile>;
103 using BrowseMap_t = std::multimap<const TClass*, StructBrowse>;
104 using Draw6Map_t = std::multimap<const TClass*, StructDraw6>;
105 using Draw7Map_t = std::multimap<const TClass*, StructDraw7>;
106
107 static ClassMap_t &GetClassMap();
108 static FileMap_t &GetFileMap();
109 static BrowseMap_t &GetBrowseMap();
110 static Draw6Map_t &GetDraw6Map();
111 static Draw7Map_t &GetDraw7Map();
113
114 static const StructClass &GetClassEntry(const ClassArg &);
115
116 template<class Map_t>
117 void CleanThis(Map_t &fmap)
118 {
119 auto fiter = fmap.begin();
120 while (fiter != fmap.end()) {
121 if (fiter->second.provider == this)
122 fiter = fmap.erase(fiter);
123 else
124 fiter++;
125 }
126 }
127
128};
129
130
131} // namespace Browsable
132} // namespace Experimental
133} // namespace ROOT
134
135#endif
const char * extension
Definition civetweb.c:7793
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.
std::function< bool(std::shared_ptr< ROOT::Experimental::RPadBase > &, std::unique_ptr< RHolder > &, const std::string &)> Draw7Func_t
Definition RProvider.hxx:75
static bool CanDraw6(const ClassArg &)
Return true if provided class can be drawn on the TCanvas.
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:73
std::function< std::shared_ptr< RElement >(std::unique_ptr< RHolder > &)> BrowseFunc_t
Definition RProvider.hxx:72
std::multimap< const TClass *, StructBrowse > BrowseMap_t
void RegisterBrowse(const TClass *cl, BrowseFunc_t func)
void RegisterNTupleFunc(BrowseNTupleFunc_t func)
void RegisterClass(const std::string &clname, const std::string &iconname, const std::string &browselib="", const std::string &draw6lib="", const std::string &draw7lib="")
std::function< std::shared_ptr< RElement >(const std::string &)> FileFunc_t
Definition RProvider.hxx:71
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:74
static std::shared_ptr< RElement > OpenFile(const std::string &extension, const std::string &fullname)
std::multimap< const TClass *, StructDraw7 > Draw7Map_t
std::multimap< const TClass *, StructDraw6 > Draw6Map_t
static const StructClass & GetClassEntry(const ClassArg &)
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:80
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...