Logo ROOT   6.18/05
Reference Guide
RMenuItem.cxx
Go to the documentation of this file.
1/// \file RMenuItem.cxx
2/// \ingroup Base ROOT7
3/// \author Sergey Linev
4/// \date 2017-07-18
5/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6/// is welcome!
7
8/*************************************************************************
9 * Copyright (C) 1995-2017, Rene Brun and Fons Rademakers. *
10 * All rights reserved. *
11 * *
12 * For the licensing terms see $ROOTSYS/LICENSE. *
13 * For the list of contributors see $ROOTSYS/README/CREDITS. *
14 *************************************************************************/
15
16#include "ROOT/RMenuItem.hxx"
17
18#include "TROOT.h"
19#include "TString.h"
20#include "TClass.h"
21#include "TList.h"
22#include "TMethod.h"
23#include "TMethodArg.h"
24#include "TMethodCall.h"
25#include "TBufferJSON.h"
26
28{
29 for (unsigned n = 0; n < fItems.size(); ++n) delete fItems[n];
30
31 fItems.clear();
32}
33
35{
36 Cleanup();
37
38 TList *lst = new TList;
39 cl->GetMenuItems(lst);
40
41 TIter iter(lst);
42 TMethod *m = 0;
43
44 while ((m = (TMethod *)iter()) != 0) {
45
46 if (m->IsMenuItem() == kMenuToggle) {
47 TString getter;
48 if (m->Getter() && strlen(m->Getter()) > 0) {
49 getter = m->Getter();
50 } else if (strncmp(m->GetName(), "Set", 3) == 0) {
51 getter = TString(m->GetName())(3, strlen(m->GetName()) - 3);
52 if (cl->GetMethodAllAny(TString("Has") + getter))
53 getter = TString("Has") + getter;
54 else if (cl->GetMethodAllAny(TString("Get") + getter))
55 getter = TString("Get") + getter;
56 else if (cl->GetMethodAllAny(TString("Is") + getter))
57 getter = TString("Is") + getter;
58 else
59 getter = "";
60 }
61
62 if ((getter.Length() > 0) && cl->GetMethodAllAny(getter)) {
63 // execute getter method to get current state of toggle item
64
65 TMethodCall *call = new TMethodCall(cl, getter, "");
66
67 if (call->ReturnType() == TMethodCall::kLong) {
68 Long_t l(0);
69 call->Execute(obj, l);
70
71 AddChkMenuItem(m->GetName(), m->GetTitle(), l != 0, Form("%s(%s)", m->GetName(), (l != 0) ? "0" : "1"));
72
73 } else {
74 // Error("CheckModifiedFlag", "Cannot get toggle value with getter %s", getter.Data());
75 }
76
77 delete call;
78 }
79 } else {
80 TList *args = m->GetListOfMethodArgs();
81
82 if (!args || (args->GetSize() == 0)) {
83 AddMenuItem(m->GetName(), m->GetTitle(), Form("%s()", m->GetName()));
84 } else {
85 Detail::RArgsMenuItem *item = new Detail::RArgsMenuItem(m->GetName(), m->GetTitle());
86 item->SetExec(Form("%s()", m->GetName()));
87
88 TIter args_iter(args);
89 TMethodArg *arg = 0;
90
91 while ((arg = dynamic_cast<TMethodArg *>(args_iter())) != 0) {
92 Detail::RMenuArgument menu_arg(arg->GetName(), arg->GetTitle(), arg->GetFullTypeName());
93 if (arg->GetDefault()) menu_arg.SetDefault(arg->GetDefault());
94 item->AddArg(menu_arg);
95 }
96
97 Add(item);
98 }
99 }
100 }
101
102 delete lst;
103}
104
106{
107 TClass *cl = gROOT->GetClass("std::vector<ROOT::Experimental::Detail::RMenuItem*>");
108
109 // FIXME: got problem with std::list<RMenuItem>, can be generic TBufferJSON
110 TString res = TBufferJSON::ConvertToJSON(&fItems, cl);
111
112 // printf("Got JSON %s\n", res.Data());
113
114 return res.Data();
115}
long Long_t
Definition: RtypesCore.h:50
@ kMenuToggle
Definition: TMethod.h:34
#define gROOT
Definition: TROOT.h:414
char * Form(const char *fmt,...)
void AddArg(const RMenuArgument &arg)
Definition: RMenuItem.hxx:114
void SetDefault(const std::string &dflt)
Definition: RMenuItem.hxx:98
void SetExec(const std::string &exec)
Set execution string with all required arguments, which will be executed when menu item is selected
Definition: RMenuItem.hxx:51
std::vector< Detail::RMenuItem * > fItems
list of items in the menu
Definition: RMenuItem.hxx:123
void PopulateObjectMenu(void *obj, TClass *cl)
Definition: RMenuItem.cxx:34
static TString ConvertToJSON(const TObject *obj, Int_t compact=0, const char *member_name=nullptr)
Converts object, inherited from TObject class, to JSON string Lower digit of compact parameter define...
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:75
void GetMenuItems(TList *listitems)
Returns list of methods accessible by context menu.
Definition: TClass.cxx:3746
TMethod * GetMethodAllAny(const char *method)
Return pointer to method without looking at parameters.
Definition: TClass.cxx:4254
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Definition: TCollection.h:182
A doubly linked list.
Definition: TList.h:44
Each ROOT method (see TMethod) has a linked list of its arguments.
Definition: TMethodArg.h:31
const char * GetFullTypeName() const
Get full type description of method argument, e.g.: "class TDirectory*".
Definition: TMethodArg.cxx:75
const char * GetDefault() const
Get default value of method argument.
Definition: TMethodArg.cxx:58
Method or function calling interface.
Definition: TMethodCall.h:37
EReturnType ReturnType()
Returns the return type of the method.
static const EReturnType kLong
Definition: TMethodCall.h:43
void Execute(const char *, const char *, int *=0)
Execute method on this object with the given parameter string, e.g.
Definition: TMethodCall.h:64
Each ROOT class (see TClass) has a linked list of methods.
Definition: TMethod.h:38
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Basic string class.
Definition: TString.h:131
Ssiz_t Length() const
Definition: TString.h:405
const char * Data() const
Definition: TString.h:364
const Int_t n
Definition: legend1.C:16
void Add(RHist< DIMENSIONS, PRECISION_TO, STAT_TO... > &to, const RHist< DIMENSIONS, PRECISION_FROM, STAT_FROM... > &from)
Add two histograms.
Definition: RHist.hxx:309
auto * m
Definition: textangle.C:8
auto * l
Definition: textangle.C:4