Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RGroup.cxx
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
10
13
14#include <ROOT/RLogger.hxx>
15
16using namespace ROOT::Experimental::Browsable;
17
18class RGroupIter : public RLevelIter {
19 int fIndx{-1};
21
22public:
23
24 explicit RGroupIter(RGroup &comp) : fComp(comp) {}
25 virtual ~RGroupIter() = default;
26
27 /** Shift to next element */
28 bool Next() override { return ++fIndx < (int) fComp.GetChilds().size(); }
29
30 /** Returns current element name */
31 std::string GetItemName() const override { return fComp.GetChilds()[fIndx]->GetName(); }
32
33 /** Returns true if item can have childs */
34 bool CanItemHaveChilds() const override { return true; }
35
36 /** Returns full information for current element */
37 std::shared_ptr<RElement> GetElement() override { return fComp.GetChilds()[fIndx]; }
38
39 /** Find item with specified name, use item MatchName() functionality */
40 bool Find(const std::string &name, int indx = -1) override
41 {
42 if ((indx >= 0) && (indx <= (int) fComp.GetChilds().size()))
43 if (fComp.GetChilds()[indx]->MatchName(name)) {
44 fIndx = indx;
45 return true;
46 }
47
48 while (Next()) {
49 if (fComp.GetChilds()[fIndx]->MatchName(name))
50 return true;
51 }
52
53 return false;
54 }
55
56 /////////////////////////////////////////////////////////////////////
57 /// Create generic description item for RBrowser
58
59 std::unique_ptr<RItem> CreateItem() override
60 {
61 auto elem = fComp.GetChilds()[fIndx];
62
63 std::string item_name = elem->GetName();
64
65 auto item = std::make_unique<RItem>(GetItemName(), -1, "sap-icon://folder-blank");
66
67 if (elem->IsExpandByDefault())
68 item->SetExpanded(true);
69
70 return item;
71 }
72
73};
74
75/////////////////////////////////////////////////////////////////////
76/// Create iterator for childs of composite
77
78std::unique_ptr<RLevelIter> RGroup::GetChildsIter()
79{
80 return std::make_unique<RGroupIter>(*this);
81}
82
char name[80]
Definition TGX11.cxx:110
std::unique_ptr< RItem > CreateItem() override
Create generic description item for RBrowser.
Definition RGroup.cxx:59
RGroup & fComp
Definition RGroup.cxx:20
int fIndx
Definition RGroup.cxx:19
bool Find(const std::string &name, int indx=-1) override
Find item with specified name, use item MatchName() functionality.
Definition RGroup.cxx:40
std::string GetItemName() const override
Returns current element name
Definition RGroup.cxx:31
bool Next() override
Shift to next element.
Definition RGroup.cxx:28
RGroupIter(RGroup &comp)
Definition RGroup.cxx:24
virtual ~RGroupIter()=default
std::shared_ptr< RElement > GetElement() override
Returns full information for current element.
Definition RGroup.cxx:37
bool CanItemHaveChilds() const override
Returns true if item can have childs.
Definition RGroup.cxx:34
Group of browsable elements - combines several different elements together.
Definition RGroup.hxx:26
std::unique_ptr< RLevelIter > GetChildsIter() override
Create iterator for childs elements if any.
Definition RGroup.cxx:78
Iterator over single level hierarchy like any array, keys list, ...