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

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

Definition at line 26 of file MethodSetter.h.

References operator()(), push(), and AlCaHLTBitMon_QueryRunRegistry::string.

31  : methStack_(methStack),
32  lazyMethStack_(lazyMethStack),
33  typeStack_(typeStack),
34  intStack_(intStack),
35  lazy_(lazy) {}
MethodArgumentStack & intStack_
Definition: MethodSetter.h:22
LazyMethodStack & lazyMethStack_
Definition: MethodSetter.h:20

Member Function Documentation

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

Definition at line 15 of file MethodSetter.cc.

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

Referenced by MethodSetter().

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 }
MethodArgumentStack & intStack_
Definition: MethodSetter.h:22
uint16_t size_type
Keeps different SingleInvokers for each dynamic type of the objects passed to invoke() ...
Definition: MethodInvoker.h:98
bool push(const std::string &, const std::vector< AnyMethodArgument > &, const char *, bool deep=true) const
Definition: MethodSetter.cc:57
#define end
Definition: vmac.h:39
LazyMethodStack & lazyMethStack_
Definition: MethodSetter.h:20
#define begin
Definition: vmac.h:32
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.

References 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, edm::TypeWithDict::name(), reco::returnType(), and edm::MemberWithDict::typeOf().

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

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  }
91  if (error != reco::parser::kNameDoesNotExist) {
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;
119  edm::MemberWithDict member(reco::findDataMember(type, name, error));
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 }
type
Definition: HCALResponse.h:21
edm::MemberWithDict findDataMember(const edm::TypeWithDict &iType, const std::string &iName, int &oError)
std::string name() const
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
edm::TypeWithDict returnType(const edm::FunctionWithDict &func)
Definition: returnType.cc:16
bool push(const std::string &, const std::vector< AnyMethodArgument > &, const char *, bool deep=true) const
Definition: MethodSetter.cc:57
uint16_t mem[nChs][nEvts]
#define begin
Definition: vmac.h:32

Member Data Documentation

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

Definition at line 22 of file MethodSetter.h.

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

Definition at line 23 of file MethodSetter.h.

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

Definition at line 20 of file MethodSetter.h.

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

Definition at line 19 of file MethodSetter.h.

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

Definition at line 21 of file MethodSetter.h.