CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
reco::parser::MethodSetter Struct 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 15 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 16 of file MethodSetter.h.

17  :
18  methStack_(methStack), lazyMethStack_(lazyMethStack), typeStack_(typeStack),
19  intStack_(intStack), lazy_(lazy) { }
MethodArgumentStack & intStack_
Definition: MethodSetter.h:39
LazyMethodStack & lazyMethStack_
Definition: MethodSetter.h:37

Member Function Documentation

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

Definition at line 11 of file MethodSetter.cc.

References harvestRelVal::args, begin, edm::hlt::Exception, i, and mergeVDriftHistosByStation::name.

11  {
12  string name(begin, end);
13  string::size_type parenthesis = name.find_first_of('(');
14  if (*begin == '[' || *begin == '(') {
15  name.insert(0, "operator.."); // operator..[arg];
16  parenthesis = 10; // ^--- idx = 10
17  name[8] = *begin; // operator[.[arg];
18  name[9] = name[name.size()-1]; // operator[][arg];
19  name[10] = '('; // operator[](arg];
20  name[name.size()-1] = ')'; // operator[](arg);
21  // we don't actually need the last two, but just for extra care
22  //std::cout << "Transformed {" << string(begin,end) << "} into {"<< name <<"}" << std::endl;
23  }
24  std::vector<AnyMethodArgument> args;
25  if(parenthesis != string::npos) {
26  name.erase(parenthesis, name.size());
27  if(intStack_.size()==0)
28  throw Exception(begin)
29  << "expected method argument, but non given.";
30  for(vector<AnyMethodArgument>::const_iterator i = intStack_.begin(); i != intStack_.end(); ++i)
31  args.push_back(*i);
32  intStack_.clear();
33  }
34  string::size_type endOfExpr = name.find_last_of(' ');
35  if(endOfExpr != string::npos)
36  name.erase(endOfExpr, name.size());
37  //std::cerr << "Pushing [" << name << "] with " << args.size() << " args " << (lazy_ ? "(lazy)" : "(immediate)") << std::endl;
38  if (lazy_) lazyMethStack_.push_back(LazyInvoker(name, args)); // for lazy parsing we just push method name and arguments
39  else push(name, args,begin); // otherwise we really have to resolve the method
40  //std::cerr << "Pushed [" << name << "] with " << args.size() << " args " << (lazy_ ? "(lazy)" : "(immediate)") << std::endl;
41 }
int i
Definition: DBlmapReader.cc:9
bool push(const std::string &, const std::vector< AnyMethodArgument > &, const char *, bool deep=true) const
Definition: MethodSetter.cc:43
uint16_t size_type
Keeps different SingleInvokers for each dynamic type of the objects passed to invoke() ...
Definition: MethodInvoker.h:73
#define end
Definition: vmac.h:38
MethodArgumentStack & intStack_
Definition: MethodSetter.h:39
LazyMethodStack & lazyMethStack_
Definition: MethodSetter.h:37
dictionary args
#define begin
Definition: vmac.h:31
bool MethodSetter::push ( const std::string &  ,
const std::vector< AnyMethodArgument > &  ,
const char *  ,
bool  deep = true 
) const

Resolve the method, push a MethodInvoker on the MethodStack and it's return type to 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 a Ref/Ptr/RefToBase and the method is not found in that 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 a 'get' on the stack
  • return true otherwise

Definition at line 43 of file MethodSetter.cc.

References error, edm::hlt::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 reco::parser::SingleInvoker::SingleInvoker().

43  {
45  vector<AnyMethodArgument> fixups;
46  int error;
47  pair<edm::FunctionWithDict, bool> mem = reco::findMethod(type, name, args, fixups,begin,error);
48  if(mem.first) {
49  edm::TypeWithDict retType = reco::returnType(mem.first);
50  if(!retType) {
51  throw Exception(begin)
52  << "member \"" << mem.first.name() << "\" return type is invalid:\n"
53  << " member type: \"" << mem.first.typeOf().qualifiedName() << "\"\n"
54  << " return type: \"" << mem.first.returnType().qualifiedName() << "\"\n";
55 
56  }
57  typeStack_.push_back(retType);
58  // check for edm::Ref, edm::RefToBase, edm::Ptr
59  if(mem.second) {
60  //std::cout << "Mem.second, so book " << mem.first.name() << " without fixups." << std::endl;
61  methStack_.push_back(MethodInvoker(mem.first));
62  if (deep) push(name, args,begin); // note: we have not found the method, so we have not fixupped the arguments
63  else return false;
64  } else {
65  //std::cout << "Not mem.second, so book " << mem.first.name() << " with #args = " << fixups.size() << std::endl;
66  methStack_.push_back(MethodInvoker(mem.first, fixups));
67  }
68  } else {
69  if(error != reco::parser::kNameDoesNotExist) {
70  switch(error) {
72  throw Exception(begin)
73  << "method named \"" << name << "\" for type \""
74  <<type.name() << "\" is not publically accessible.";
75  break;
77  throw Exception(begin)
78  << "method named \"" << name << "\" for type \""
79  <<type.name() << "\" is static.";
80  break;
82  throw Exception(begin)
83  << "method named \"" << name << "\" for type \""
84  <<type.name() << "\" is not const.";
85  break;
87  throw Exception(begin)
88  << "method named \"" << name << "\" for type \""
89  <<type.name() << "\" was passed the wrong number of arguments.";
90  break;
92  throw Exception(begin)
93  << "method named \"" << name << "\" for type \""
94  <<type.name() << "\" was passed the wrong types of arguments.";
95  break;
96  default:
97  throw Exception(begin)
98  << "method named \"" << name << "\" for type \""
99  <<type.name() << "\" is not usable in this context.";
100  }
101  }
102  //see if it is a member data
103  int error;
104  edm::MemberWithDict member(reco::findDataMember(type,name,error));
105  if(!member) {
106  switch(error) {
108  throw Exception(begin)
109  << "no method or data member named \"" << name << "\" found for type \""
110  <<type.name() << "\"";
111  break;
113  throw Exception(begin)
114  << "data member named \"" << name << "\" for type \""
115  <<type.name() << "\" is not publically accessible.";
116  break;
117  default:
118  throw Exception(begin)
119  << "data member named \"" << name << "\" for type \""
120  <<type.name() << "\" is not usable in this context.";
121  break;
122  }
123  }
124  typeStack_.push_back(member.typeOf());
125  methStack_.push_back(MethodInvoker(member));
126  }
127  return true;
128 }
type
Definition: HCALResponse.h:21
pair< edm::FunctionWithDict, bool > findMethod(const edm::TypeWithDict &t, const string &name, const std::vector< AnyMethodArgument > &args, std::vector< AnyMethodArgument > &fixuppedArgs, const char *iIterator, int &oError)
Definition: findMethod.cc:76
edm::MemberWithDict findDataMember(const edm::TypeWithDict &iType, const std::string &iName, int &oError)
bool push(const std::string &, const std::vector< AnyMethodArgument > &, const char *, bool deep=true) const
Definition: MethodSetter.cc:43
edm::TypeWithDict returnType(const edm::FunctionWithDict &mem)
Definition: returnType.cc:8
std::string name() const
uint16_t mem[nChs][nEvts]
dictionary args
#define begin
Definition: vmac.h:31

Member Data Documentation

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

Definition at line 39 of file MethodSetter.h.

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

Definition at line 40 of file MethodSetter.h.

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

Definition at line 37 of file MethodSetter.h.

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

Definition at line 36 of file MethodSetter.h.

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

Definition at line 38 of file MethodSetter.h.