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 12 of file MethodSetter.cc.

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

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

Referenced by reco::parser::SingleInvoker::SingleInvoker().

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

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.