File indexing completed on 2025-01-18 10:10:31
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef ROOT7_Browsable_RProvider
0010 #define ROOT7_Browsable_RProvider
0011
0012 #include <ROOT/Browsable/RElement.hxx>
0013
0014 #include <functional>
0015 #include <map>
0016 #include <memory>
0017
0018 class TVirtualPad;
0019
0020 namespace ROOT {
0021
0022 namespace Experimental {
0023 class RPadBase;
0024 }
0025
0026 namespace Browsable {
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 class RProvider {
0038
0039 public:
0040
0041 virtual ~RProvider();
0042
0043 using ProgressFunc_t = std::function<void(float progress, void *handle)>;
0044
0045 class ClassArg {
0046 friend class RProvider;
0047 const TClass *cl{nullptr};
0048 std::string name;
0049 ClassArg() = delete;
0050 public:
0051 ClassArg(const TClass *_cl) : cl(_cl) {}
0052 ClassArg(const std::string &_name) : name(_name) {}
0053 ClassArg(const char *_name) : name(_name) {}
0054
0055 bool empty() const { return !cl && name.empty(); }
0056 const TClass *GetClass() const { return cl; }
0057 const std::string &GetName() const { return name; }
0058 };
0059
0060 class ProgressHandle {
0061 friend class RProvider;
0062 void *fHandle{nullptr};
0063
0064 ProgressHandle(const ProgressHandle &) = delete;
0065 ProgressHandle& operator=(const ProgressHandle &) = delete;
0066 public:
0067 explicit ProgressHandle(void *handle, ProgressFunc_t func);
0068 ~ProgressHandle();
0069 void Extend(void *handle2);
0070 };
0071
0072 friend class ProgressHandle;
0073
0074 static std::string GetClassIcon(const ClassArg &, bool = false);
0075 static std::string GetClassDrawOption(const ClassArg &);
0076 static bool SetClassDrawOption(const ClassArg &, const std::string &);
0077
0078 static bool CanHaveChilds(const ClassArg &);
0079 static bool NotShowChilds(const ClassArg &);
0080 static bool CanDraw6(const ClassArg &);
0081 static bool CanDraw7(const ClassArg &);
0082
0083 static bool IsFileFormatSupported(const std::string &extension);
0084 static std::shared_ptr<RElement> OpenFile(const std::string &extension, const std::string &fullname);
0085 static std::shared_ptr<RElement> Browse(std::unique_ptr<RHolder> &obj);
0086 static std::shared_ptr<RElement> BrowseNTuple(const std::string &tuplename, const std::string &filename);
0087 static bool Draw6(TVirtualPad *subpad, std::unique_ptr<RHolder> &obj, const std::string &opt = "");
0088 static bool Draw7(std::shared_ptr<ROOT::Experimental::RPadBase> &subpad, std::unique_ptr<RHolder> &obj, const std::string &opt = "");
0089
0090 static void ExtendProgressHandle(void *handle, void *handle2);
0091 static bool ReportProgress(void *handle, float progress);
0092
0093 protected:
0094
0095 using FileFunc_t = std::function<std::shared_ptr<RElement>(const std::string &)>;
0096 using BrowseFunc_t = std::function<std::shared_ptr<RElement>(std::unique_ptr<RHolder> &)>;
0097 using BrowseNTupleFunc_t = std::function<std::shared_ptr<RElement>(const std::string &, const std::string &)>;
0098 using Draw6Func_t = std::function<bool(TVirtualPad *, std::unique_ptr<RHolder> &, const std::string &)>;
0099 using Draw7Func_t = std::function<bool(std::shared_ptr<ROOT::Experimental::RPadBase> &, std::unique_ptr<RHolder> &, const std::string &)>;
0100
0101 void RegisterFile(const std::string &extension, FileFunc_t func);
0102 void RegisterBrowse(const TClass *cl, BrowseFunc_t func);
0103 void RegisterDraw6(const TClass *cl, Draw6Func_t func);
0104 void RegisterDraw7(const TClass *cl, Draw7Func_t func);
0105 void RegisterClass(const std::string &clname,
0106 const std::string &iconname,
0107 const std::string &browselib = "",
0108 const std::string &draw6lib = "",
0109 const std::string &draw7lib = "",
0110 const std::string &drawopt = "");
0111 void RegisterNTupleFunc(BrowseNTupleFunc_t func);
0112
0113 private:
0114
0115 struct StructBrowse { RProvider *provider{nullptr}; BrowseFunc_t func; };
0116 struct StructFile { RProvider *provider{nullptr}; FileFunc_t func; };
0117 struct StructDraw6 { RProvider *provider{nullptr}; Draw6Func_t func; };
0118 struct StructDraw7 { RProvider *provider{nullptr}; Draw7Func_t func; };
0119 struct StructProgress { void *handle{nullptr}, *handle2{nullptr}; ProgressFunc_t func; };
0120
0121 struct StructClass {
0122 RProvider *provider{nullptr};
0123 bool can_have_childs{false};
0124 std::string iconname, browselib, draw6lib, draw7lib, drawopt;
0125 bool dummy() const { return !provider; }
0126 };
0127
0128 using ClassMap_t = std::multimap<std::string, StructClass>;
0129 using FileMap_t = std::multimap<std::string, StructFile>;
0130 using BrowseMap_t = std::multimap<const TClass*, StructBrowse>;
0131 using Draw6Map_t = std::multimap<const TClass*, StructDraw6>;
0132 using Draw7Map_t = std::multimap<const TClass*, StructDraw7>;
0133 using ProgressVect_t = std::vector<StructProgress>;
0134
0135 static ClassMap_t &GetClassMap();
0136 static FileMap_t &GetFileMap();
0137 static BrowseMap_t &GetBrowseMap();
0138 static Draw6Map_t &GetDraw6Map();
0139 static Draw7Map_t &GetDraw7Map();
0140 static ProgressVect_t &GetProgressVect();
0141 static BrowseNTupleFunc_t gNTupleFunc;
0142
0143 static StructClass &GetClassEntry(const ClassArg &);
0144
0145 template<class Map_t>
0146 void CleanThis(Map_t &fmap)
0147 {
0148 if (fmap.empty())
0149 return;
0150 auto fiter = fmap.begin();
0151 while (fiter != fmap.end()) {
0152 if (fiter->second.provider == this)
0153 fiter = fmap.erase(fiter);
0154 else
0155 fiter++;
0156 }
0157 }
0158
0159 };
0160
0161
0162 }
0163 }
0164
0165 #endif