Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RBrowserWidget.cxx
Go to the documentation of this file.
1// Author: Sergey Linev <S.Linev@gsi.de>
2// Date: 2021-01-22
3// Warning: This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
4
5/*************************************************************************
6 * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers. *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 *************************************************************************/
12
13#include "RBrowserWidget.hxx"
14
15#include <algorithm>
16
17#include "TSystem.h"
18
19
20using namespace std::string_literals;
21using namespace ROOT::Experimental;
22
24{
25 GetMap().emplace(kind, this);
26}
27
29{
30 auto &map = GetMap();
31 auto iter = std::find_if(map.begin(), map.end(),
32 [this](const ProvidersMap_t::value_type &pair) { return this == pair.second; });
33
34 if (iter != map.end())
35 map.erase(iter);
36}
37
39{
41 return mMap;
42}
43
44///////////////////////////////////////////////////////////////
45/// Create specified widget
46
47std::shared_ptr<RBrowserWidget> RBrowserWidgetProvider::CreateWidget(const std::string &kind, const std::string &name)
48{
49 auto &map = GetMap();
50 auto iter = map.find(kind);
51 if (iter == map.end()) {
52 // try to load necessary libraries
53 if (kind == "geom")
54 gSystem->Load("libROOTBrowserGeomWidget");
55 else if (kind == "tcanvas")
56 gSystem->Load("libROOTBrowserTCanvasWidget");
57 else if (kind == "rcanvas")
58 gSystem->Load("libROOTBrowserRCanvasWidget");
59 iter = map.find(kind);
60 if (iter == map.end())
61 return nullptr;
62 }
63 return iter->second->Create(name);
64}
65
66///////////////////////////////////////////////////////////////
67/// Create specified widget for existing object
68
69
70std::shared_ptr<RBrowserWidget> RBrowserWidgetProvider::CreateWidgetFor(const std::string &kind, const std::string &name, std::shared_ptr<Browsable::RElement> &element)
71{
72 auto &map = GetMap();
73 auto iter = map.find(kind);
74 if (iter == map.end()) {
75 // try to load necessary libraries
76 if (kind == "geom")
77 gSystem->Load("libROOTBrowserGeomWidget");
78 else if (kind == "tcanvas")
79 gSystem->Load("libROOTBrowserTCanvasWidget");
80 else if (kind == "rcanvas")
81 gSystem->Load("libROOTBrowserRCanvasWidget");
82 iter = map.find(kind);
83 if (iter == map.end())
84 return nullptr;
85 }
86 return iter->second->CreateFor(name, element);
87}
char name[80]
Definition TGX11.cxx:110
R__EXTERN TSystem * gSystem
Definition TSystem.h:559
std::map< std::string, RBrowserWidgetProvider * > ProvidersMap_t
static std::shared_ptr< RBrowserWidget > CreateWidgetFor(const std::string &kind, const std::string &name, std::shared_ptr< Browsable::RElement > &element)
Create specified widget for existing object.
static std::shared_ptr< RBrowserWidget > CreateWidget(const std::string &kind, const std::string &name)
Create specified widget.
RBrowserWidgetProvider(const std::string &kind)
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition TSystem.cxx:1855