Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RElement.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_RElement
10#define ROOT7_Browsable_RElement
11
13
14#include <string>
15#include <vector>
16
17namespace ROOT {
18namespace Experimental {
19namespace Browsable {
20
21using RElementPath_t = std::vector<std::string>;
22
23class RLevelIter;
24
25/** \class RElement
26\ingroup rbrowser
27\brief Basic element of browsable hierarchy. Provides access to data, creates iterator if any
28\author Sergey Linev <S.Linev@gsi.de>
29\date 2019-10-14
30\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
31*/
32
33class RElement {
34public:
35
37 kNone, ///< not recognized
38 kText, ///< "text" - plain text for code editor
39 kImage, ///< "image64" - base64 for supported image formats (png/gif/gpeg)
40 kPng, ///< "png" - plain png binary code, returned inside std::string
41 kJpeg, ///< "jpg" or "jpeg" - plain jpg binary code, returned inside std::string
42 kJson, ///< "json" representation of object, can be used in code editor
43 kFileName ///< "filename" - file name if applicable
44 };
45
46 static EContentKind GetContentKind(const std::string &kind);
47
48 /** Possible actions on double-click */
50 kActNone, ///< do nothing
51 kActBrowse, ///< just browse (expand) item
52 kActEdit, ///< can provide data for text editor
53 kActImage, ///< can be shown in image viewer, can provide image
54 kActDraw6, ///< can be drawn inside ROOT6 canvas
55 kActDraw7, ///< can be drawn inside ROOT7 canvas
56 kActCanvas, ///< indicate that it is canvas and should be drawn directly
57 kActGeom ///< can be shown in geometry viewer
58 };
59
60 virtual ~RElement() = default;
61
62 /** Name of browsable, must be provided in derived classes */
63 virtual std::string GetName() const = 0;
64
65 /** Checks if element name match to provided value */
66 virtual bool MatchName(const std::string &name) const { return name == GetName(); }
67
68 /** Title of browsable (optional) */
69 virtual std::string GetTitle() const { return ""; }
70
71 /** Create iterator for childs elements if any */
72 virtual std::unique_ptr<RLevelIter> GetChildsIter();
73
74 virtual int GetNumChilds();
75
76 /** Returns element content, depends from kind. Can be "text" or "image64" or "json" */
77 virtual std::string GetContent(const std::string & = "text");
78
79 /** Access object */
80 virtual std::unique_ptr<RHolder> GetObject() { return nullptr; }
81
82 /** Get default action */
83 virtual EActionKind GetDefaultAction() const { return kActNone; }
84
85 /** Check if want to perform action */
86 virtual bool IsCapable(EActionKind action) const { return action == GetDefaultAction(); }
87
88 /** Should item representing element be expand by default */
89 virtual bool IsExpandByDefault() const { return false; }
90
91 /** Select element as active */
92 virtual bool cd() { return false; }
93
94 static std::shared_ptr<RElement> GetSubElement(std::shared_ptr<RElement> &elem, const RElementPath_t &path);
95
96 static RElementPath_t ParsePath(const std::string &str);
97
98 static int ComparePaths(const RElementPath_t &path1, const RElementPath_t &path2);
99
100 static std::string GetPathAsString(const RElementPath_t &path);
101
102 static int ExtractItemIndex(std::string &name);
103};
104
105} // namespace Browsable
106} // namespace Experimental
107} // namespace ROOT
108
109#endif
char name[80]
Definition TGX11.cxx:110
Basic element of browsable hierarchy.
Definition RElement.hxx:33
virtual bool MatchName(const std::string &name) const
Checks if element name match to provided value.
Definition RElement.hxx:66
@ kFileName
"filename" - file name if applicable
Definition RElement.hxx:43
@ kJson
"json" representation of object, can be used in code editor
Definition RElement.hxx:42
@ kImage
"image64" - base64 for supported image formats (png/gif/gpeg)
Definition RElement.hxx:39
@ kJpeg
"jpg" or "jpeg" - plain jpg binary code, returned inside std::string
Definition RElement.hxx:41
@ kPng
"png" - plain png binary code, returned inside std::string
Definition RElement.hxx:40
@ kText
"text" - plain text for code editor
Definition RElement.hxx:38
static EContentKind GetContentKind(const std::string &kind)
Find item with specified name Default implementation, should work for all.
Definition RElement.cxx:49
virtual std::string GetName() const =0
Name of browsable, must be provided in derived classes.
virtual bool IsCapable(EActionKind action) const
Check if want to perform action.
Definition RElement.hxx:86
virtual bool IsExpandByDefault() const
Should item representing element be expand by default.
Definition RElement.hxx:89
virtual std::string GetContent(const std::string &="text")
Returns element content, depends from kind.
Definition RElement.cxx:87
virtual std::unique_ptr< RLevelIter > GetChildsIter()
Create iterator for childs elements if any.
Definition RElement.cxx:27
virtual int GetNumChilds()
Returns number of childs By default creates iterator and iterates over all items.
Definition RElement.cxx:36
static int ExtractItemIndex(std::string &name)
Extract index from name Index coded by client with ###<indx>$$$ suffix Such coding used by browser to...
Definition RElement.cxx:164
static int ComparePaths(const RElementPath_t &path1, const RElementPath_t &path2)
Compare two paths, Returns number of elements matches in both paths.
Definition RElement.cxx:131
static std::string GetPathAsString(const RElementPath_t &path)
Converts element path back to string.
Definition RElement.cxx:146
virtual bool cd()
Select element as active.
Definition RElement.hxx:92
static std::shared_ptr< RElement > GetSubElement(std::shared_ptr< RElement > &elem, const RElementPath_t &path)
Returns sub element.
Definition RElement.cxx:66
EActionKind
Possible actions on double-click.
Definition RElement.hxx:49
@ kActEdit
can provide data for text editor
Definition RElement.hxx:52
@ kActCanvas
indicate that it is canvas and should be drawn directly
Definition RElement.hxx:56
@ kActBrowse
just browse (expand) item
Definition RElement.hxx:51
@ kActGeom
can be shown in geometry viewer
Definition RElement.hxx:57
@ kActDraw7
can be drawn inside ROOT7 canvas
Definition RElement.hxx:55
@ kActImage
can be shown in image viewer, can provide image
Definition RElement.hxx:53
@ kActDraw6
can be drawn inside ROOT6 canvas
Definition RElement.hxx:54
virtual std::unique_ptr< RHolder > GetObject()
Access object.
Definition RElement.hxx:80
virtual EActionKind GetDefaultAction() const
Get default action.
Definition RElement.hxx:83
static RElementPath_t ParsePath(const std::string &str)
Parse string path to produce RElementPath_t One should avoid to use string pathes as much as possible...
Definition RElement.cxx:102
virtual std::string GetTitle() const
Title of browsable (optional)
Definition RElement.hxx:69
Iterator over single level hierarchy like any array, keys list, ...
std::vector< std::string > RElementPath_t
Definition RElement.hxx:21
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...