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 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.

29  : methStack_(methStack)
30  , lazyMethStack_(lazyMethStack)
31  , typeStack_(typeStack)
32  , intStack_(intStack)
33  , lazy_(lazy)
34  {
35  }
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 17 of file MethodSetter.cc.

References mps_alisetup::args, begin, Exception, i, and mergeVDriftHistosByStation::name.

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

67 {
69  vector<AnyMethodArgument> fixups;
70  int error = 0;
71  pair<edm::FunctionWithDict, bool> mem =
72  reco::findMethod(type, name, args, fixups, begin, error);
73  if (bool(mem.first)) {
74  // We found the method.
75  edm::TypeWithDict retType = reco::returnType(mem.first);
76  if (!bool(retType)) {
77  // Invalid return type, fatal error, throw.
78  throw Exception(begin)
79  << "member \"" << mem.first.name()
80  << "\" return type is invalid:\n"
81  << " return type: \""
82  << mem.first.typeName() << "\"\n";
83  }
84  typeStack_.push_back(retType);
85  // check for edm::Ref, edm::RefToBase, edm::Ptr
86  if (mem.second) {
87  // Without fixups.
88  //std::cout << "Mem.second, so book " << mem.first.name() <<
89  // " without fixups." << std::endl;
90  methStack_.push_back(MethodInvoker(mem.first));
91  if (!deep) {
92  return false;
93  }
94  // note: we have not found the method, so we have not
95  // fixupped the arguments
96  push(name, args, begin);
97  }
98  else {
99  // With fixups.
100  //std::cout << "Not mem.second, so book " << mem.first.name()
101  // << " with #args = " << fixups.size() << std::endl;
102  methStack_.push_back(MethodInvoker(mem.first, fixups));
103  }
104  return true;
105  }
106  if (error != reco::parser::kNameDoesNotExist) {
107  // Fatal error, throw.
108  switch (error) {
110  throw Exception(begin)
111  << "method named \"" << name << "\" for type \""
112  << type.name() << "\" is not publically accessible.";
113  break;
115  throw Exception(begin)
116  << "method named \"" << name << "\" for type \""
117  << type.name() << "\" is static.";
118  break;
120  throw Exception(begin)
121  << "method named \"" << name << "\" for type \""
122  << type.name() << "\" is not const.";
123  break;
125  throw Exception(begin)
126  << "method named \"" << name << "\" for type \""
127  << type.name() << "\" was passed the wrong number of arguments.";
128  break;
130  throw Exception(begin)
131  << "method named \"" << name << "\" for type \""
132  << type.name() << "\" was passed the wrong types of arguments.";
133  break;
134  default:
135  throw Exception(begin)
136  << "method named \"" << name << "\" for type \""
137  << type.name() << "\" is not usable in this context.";
138  }
139  }
140  // Not a method, check for a data member.
141  error = 0;
142  edm::MemberWithDict member(reco::findDataMember(type, name, error));
143  if (!bool(member)) {
144  // Not a data member either, fatal error, throw.
145  switch (error) {
147  throw Exception(begin)
148  << "no method or data member named \"" << name
149  << "\" found for type \""
150  << type.name() << "\"";
151  break;
153  throw Exception(begin)
154  << "data member named \"" << name << "\" for type \""
155  << type.name() << "\" is not publically accessible.";
156  break;
157  default:
158  throw Exception(begin)
159  << "data member named \"" << name << "\" for type \""
160  << type.name() << "\" is not usable in this context.";
161  break;
162  }
163  }
164  // Ok, it was a data member.
165  typeStack_.push_back(member.typeOf());
166  methStack_.push_back(MethodInvoker(member));
167  return true;
168 }
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:145
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:65
uint16_t mem[nChs][nEvts]
#define begin
Definition: vmac.h:30

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.