CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
reco::parser::MethodSetter Class Reference

#include <MethodSetter.h>

Public Member Functions

 MethodSetter (MethodStack &methStack, LazyMethodStack &lazyMethStack, TypeStack &typeStack, MethodArgumentStack &intStack, bool lazy=false)
 
void operator() (const char *, const char *) const
 
bool push (const std::string &, const std::vector< AnyMethodArgument > &, const char *, bool deep=true) const
 

Private Attributes

MethodArgumentStackintStack_
 
bool lazy_
 
LazyMethodStacklazyMethStack_
 
MethodStackmethStack_
 
TypeStacktypeStack_
 

Detailed Description

Definition at line 17 of file MethodSetter.h.

Constructor & Destructor Documentation

◆ MethodSetter()

reco::parser::MethodSetter::MethodSetter ( MethodStack methStack,
LazyMethodStack lazyMethStack,
TypeStack typeStack,
MethodArgumentStack intStack,
bool  lazy = false 
)
inlineexplicit

Definition at line 26 of file MethodSetter.h.

31  : methStack_(methStack),
32  lazyMethStack_(lazyMethStack),
33  typeStack_(typeStack),
34  intStack_(intStack),
35  lazy_(lazy) {}

Member Function Documentation

◆ operator()()

void MethodSetter::operator() ( const char *  begin,
const char *  end 
) const

Definition at line 15 of file MethodSetter.cc.

15  {
16  string name(begin, end);
17  string::size_type parenthesis = name.find_first_of('(');
18  if ((*begin == '[') || (*begin == '(')) {
19  name.insert(0, "operator.."); // operator..[arg];
20  parenthesis = 10; // ^--- idx = 10
21  name[8] = *begin; // operator[.[arg];
22  name[9] = name[name.size() - 1]; // operator[][arg];
23  name[10] = '('; // operator[](arg];
24  name[name.size() - 1] = ')'; // operator[](arg);
25  // we don't actually need the last two, but just for extra care
26  //std::cout << "Transformed {" << string(begin,end) << "} into
27  // {"<< name <<"}" << std::endl;
28  }
29  std::vector<AnyMethodArgument> args;
30  if (parenthesis != string::npos) {
31  name.erase(parenthesis, name.size());
32  if (intStack_.empty()) {
33  throw Exception(begin) << "expected method argument, but non given.";
34  }
35  for (vector<AnyMethodArgument>::const_iterator i = intStack_.begin(); i != intStack_.end(); ++i) {
36  args.push_back(*i);
37  }
38  intStack_.clear();
39  }
40  string::size_type endOfExpr = name.find_last_of(' ');
41  if (endOfExpr != string::npos) {
42  name.erase(endOfExpr, name.size());
43  }
44  //std::cerr << "Pushing [" << name << "] with " << args.size()
45  // << " args " << (lazy_ ? "(lazy)" : "(immediate)") << std::endl;
46  if (lazy_) {
47  // for lazy parsing we just push method name and arguments
48  lazyMethStack_.push_back(LazyInvoker(name, args));
49  } else {
50  // otherwise we really have to resolve the method
51  push(name, args, begin);
52  }
53  //std::cerr << "Pushed [" << name << "] with " << args.size() <<
54  // " args " << (lazy_ ? "(lazy)" : "(immediate)") << std::endl;
55 }

References writedatasetfile::args, begin, end, Exception, mps_fire::i, and Skims_PA_cff::name.

◆ push()

bool MethodSetter::push ( const std::string &  ,
const std::vector< AnyMethodArgument > &  ,
const char *  ,
bool  deep = true 
) const

Resolve the name to either a function member or a data member, push a MethodInvoker on the MethodStack, and its return type to the TypeStack (after stripping "*" and "&").

This method is used also by the LazyInvoker to perform the fetch once the final type is known.

If the object is an edm::Ref/Ptr/RefToBase and the method is not found in the class:

1) it pushes a no-argument 'get()' method

2) if deep = true, it attempts to resolve and push the method on the object to which the edm ref points to. In that case, the MethodStack will contain two more items after this call instead of just one. This behaviour is what you want for non-lazy parsing.

2b) if instead deep = false, it just pushes the 'get' on the stack. this will allow the LazyInvoker to then re-discover the runtime type of the pointee

The method will:

  • throw exception, if the member can't be resolved
  • return 'false' if deep = false and it only pushed

return true otherwise

Definition at line 57 of file MethodSetter.cc.

57  {
59  vector<AnyMethodArgument> fixups;
60  int error = 0;
61  pair<edm::FunctionWithDict, bool> mem = reco::findMethod(type, name, args, fixups, begin, error);
62  if (bool(mem.first)) {
63  // We found the method.
64  edm::TypeWithDict retType = reco::returnType(mem.first);
65  if (!bool(retType)) {
66  // Invalid return type, fatal error, throw.
67  throw Exception(begin) << "member \"" << mem.first.name() << "\" return type is invalid:\n"
68  << " return type: \"" << mem.first.typeName() << "\"\n";
69  }
70  typeStack_.push_back(retType);
71  // check for edm::Ref, edm::RefToBase, edm::Ptr
72  if (mem.second) {
73  // Without fixups.
74  //std::cout << "Mem.second, so book " << mem.first.name() <<
75  // " without fixups." << std::endl;
76  methStack_.push_back(MethodInvoker(mem.first));
77  if (!deep) {
78  return false;
79  }
80  // note: we have not found the method, so we have not
81  // fixupped the arguments
82  push(name, args, begin);
83  } else {
84  // With fixups.
85  //std::cout << "Not mem.second, so book " << mem.first.name()
86  // << " with #args = " << fixups.size() << std::endl;
87  methStack_.push_back(MethodInvoker(mem.first, fixups));
88  }
89  return true;
90  }
92  // Fatal error, throw.
93  switch (error) {
95  throw Exception(begin) << "method named \"" << name << "\" for type \"" << type.name()
96  << "\" is not publically accessible.";
97  break;
99  throw Exception(begin) << "method named \"" << name << "\" for type \"" << type.name() << "\" is static.";
100  break;
102  throw Exception(begin) << "method named \"" << name << "\" for type \"" << type.name() << "\" is not const.";
103  break;
105  throw Exception(begin) << "method named \"" << name << "\" for type \"" << type.name()
106  << "\" was passed the wrong number of arguments.";
107  break;
109  throw Exception(begin) << "method named \"" << name << "\" for type \"" << type.name()
110  << "\" was passed the wrong types of arguments.";
111  break;
112  default:
113  throw Exception(begin) << "method named \"" << name << "\" for type \"" << type.name()
114  << "\" is not usable in this context.";
115  }
116  }
117  // Not a method, check for a data member.
118  error = 0;
120  if (!bool(member)) {
121  // Not a data member either, fatal error, throw.
122  switch (error) {
124  throw Exception(begin) << "no method or data member named \"" << name << "\" found for type \"" << type.name()
125  << "\"";
126  break;
128  throw Exception(begin) << "data member named \"" << name << "\" for type \"" << type.name()
129  << "\" is not publically accessible.";
130  break;
131  default:
132  throw Exception(begin) << "data member named \"" << name << "\" for type \"" << type.name()
133  << "\" is not usable in this context.";
134  break;
135  }
136  }
137  // Ok, it was a data member.
138  typeStack_.push_back(member.typeOf());
139  methStack_.push_back(MethodInvoker(member));
140  return true;
141 }

References writedatasetfile::args, begin, relativeConstraints::error, Exception, reco::findDataMember(), reco::findMethod(), reco::parser::kIsNotConst, reco::parser::kIsNotPublic, reco::parser::kIsStatic, reco::parser::kNameDoesNotExist, reco::parser::kWrongArgumentType, reco::parser::kWrongNumberOfArguments, mem, Skims_PA_cff::name, reco::returnType(), and edm::MemberWithDict::typeOf().

Referenced by reco::parser::SingleInvoker::SingleInvoker(), esMonitoring.LineHistoryEnd::write(), and esMonitoring.LineHistoryStart::write().

Member Data Documentation

◆ intStack_

MethodArgumentStack& reco::parser::MethodSetter::intStack_
private

Definition at line 22 of file MethodSetter.h.

◆ lazy_

bool reco::parser::MethodSetter::lazy_
private

Definition at line 23 of file MethodSetter.h.

◆ lazyMethStack_

LazyMethodStack& reco::parser::MethodSetter::lazyMethStack_
private

Definition at line 20 of file MethodSetter.h.

◆ methStack_

MethodStack& reco::parser::MethodSetter::methStack_
private

Definition at line 19 of file MethodSetter.h.

◆ typeStack_

TypeStack& reco::parser::MethodSetter::typeStack_
private

Definition at line 21 of file MethodSetter.h.

writedatasetfile.args
args
Definition: writedatasetfile.py:18
mps_fire.i
i
Definition: mps_fire.py:355
reco::findDataMember
edm::MemberWithDict findDataMember(const edm::TypeWithDict &iType, const std::string &iName, int &oError)
Definition: findDataMember.cc:30
reco::parser::kIsNotPublic
Definition: ErrorCodes.h:33
reco::parser::kNameDoesNotExist
Definition: ErrorCodes.h:32
reco::parser::MethodSetter::lazyMethStack_
LazyMethodStack & lazyMethStack_
Definition: MethodSetter.h:20
reco::parser::MethodSetter::methStack_
MethodStack & methStack_
Definition: MethodSetter.h:19
reco::parser::MethodInvoker
Definition: MethodInvoker.h:27
mem
uint16_t mem[nChs][nEvts]
Definition: recycleTccEmu.cc:13
relativeConstraints.error
error
Definition: relativeConstraints.py:53
reco::parser::MethodSetter::intStack_
MethodArgumentStack & intStack_
Definition: MethodSetter.h:22
end
#define end
Definition: vmac.h:39
reco::parser::MethodSetter::lazy_
bool lazy_
Definition: MethodSetter.h:23
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
reco::parser::kIsNotConst
Definition: ErrorCodes.h:35
reco::findMethod
std::pair< edm::FunctionWithDict, bool > findMethod(const edm::TypeWithDict &t, const std::string &name, const std::vector< AnyMethodArgument > &args, std::vector< AnyMethodArgument > &fixuppedArgs, const char *iIterator, int &oError)
Definition: findMethod.cc:130
reco::returnType
edm::TypeWithDict returnType(const edm::FunctionWithDict &func)
Definition: returnType.cc:16
edm::TypeWithDict
Definition: TypeWithDict.h:38
reco::parser::LazyInvoker
Keeps different SingleInvokers for each dynamic type of the objects passed to invoke()
Definition: MethodInvoker.h:95
edm::MemberWithDict
Definition: MemberWithDict.h:19
reco::parser::kIsStatic
Definition: ErrorCodes.h:34
type
type
Definition: HCALResponse.h:21
Exception
Definition: hltDiff.cc:246
reco::parser::MethodSetter::push
bool push(const std::string &, const std::vector< AnyMethodArgument > &, const char *, bool deep=true) const
Definition: MethodSetter.cc:57
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
reco::parser::MethodSetter::typeStack_
TypeStack & typeStack_
Definition: MethodSetter.h:21
reco::parser::kWrongNumberOfArguments
Definition: ErrorCodes.h:40
begin
#define begin
Definition: vmac.h:32
reco::parser::kWrongArgumentType
Definition: ErrorCodes.h:41