Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
RMenuItem.cxx
Go to the documentation of this file.
1 /*************************************************************************
2  * Copyright (C) 1995-2017, 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 #include "ROOT/RMenuItem.hxx"
10 
11 #include "TROOT.h"
12 #include "TString.h"
13 #include "TClass.h"
14 #include "TList.h"
15 #include "TMethod.h"
16 #include "TMethodArg.h"
17 #include "TMethodCall.h"
18 #include "TBufferJSON.h"
19 
20 void ROOT::Experimental::RMenuItems::PopulateObjectMenu(void *obj, TClass *cl)
21 {
22  fItems.clear();
23 
24  TList lst;
25  cl->GetMenuItems(&lst);
26 
27  TIter iter(&lst);
28  TMethod *m = nullptr;
29 
30  while ((m = (TMethod *)iter()) != nullptr) {
31 
32  if (m->IsMenuItem() == kMenuToggle) {
33  TString getter;
34  if (m->Getter() && strlen(m->Getter()) > 0) {
35  getter = m->Getter();
36  } else if (strncmp(m->GetName(), "Set", 3) == 0) {
37  getter = TString(m->GetName())(3, strlen(m->GetName()) - 3);
38  if (cl->GetMethodAllAny(TString("Has") + getter))
39  getter = TString("Has") + getter;
40  else if (cl->GetMethodAllAny(TString("Get") + getter))
41  getter = TString("Get") + getter;
42  else if (cl->GetMethodAllAny(TString("Is") + getter))
43  getter = TString("Is") + getter;
44  else
45  getter = "";
46  }
47 
48  if ((getter.Length() > 0) && cl->GetMethodAllAny(getter)) {
49  // execute getter method to get current state of toggle item
50 
51  auto call = std::make_unique<TMethodCall>(cl, getter, "");
52 
53  if (call->ReturnType() == TMethodCall::kLong) {
54  Long_t l(0);
55  call->Execute(obj, l);
56 
57  AddChkMenuItem(m->GetName(), m->GetTitle(), l != 0, Form("%s(%s)", m->GetName(), (l != 0) ? "0" : "1"));
58 
59  } else {
60  // Error("CheckModifiedFlag", "Cannot get toggle value with getter %s", getter.Data());
61  }
62  }
63  } else {
64  TList *args = m->GetListOfMethodArgs();
65 
66  if (!args || (args->GetSize() == 0)) {
67  AddMenuItem(m->GetName(), m->GetTitle(), Form("%s()", m->GetName()));
68  } else {
69  auto item = std::make_unique<Detail::RArgsMenuItem>(m->GetName(), m->GetTitle());
70  item->SetExec(Form("%s()", m->GetName()));
71 
72  TIter args_iter(args);
73  TMethodArg *arg = nullptr;
74 
75  while ((arg = dynamic_cast<TMethodArg *>(args_iter())) != nullptr) {
76  Detail::RMenuArgument menu_arg(arg->GetName(), arg->GetTitle(), arg->GetFullTypeName());
77  if (arg->GetDefault()) menu_arg.SetDefault(arg->GetDefault());
78  item->AddArg(menu_arg);
79  }
80 
81  Add(std::move(item));
82  }
83  }
84  }
85 }