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