test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MethodSetter.cc
Go to the documentation of this file.
7 #include <string>
8 using namespace reco::parser;
9 using namespace std;
10 
11 void MethodSetter::operator()(const char * begin, const char * end) const {
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 }
42 
43 bool MethodSetter::push(const string & name, const vector<AnyMethodArgument> & args, const char* begin,bool deep) const {
44  edm::TypeWithDict type = typeStack_.back();
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 }
129 
type
Definition: HCALResponse.h:21
int i
Definition: DBlmapReader.cc:9
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:78
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:10
uint16_t size_type
Keeps different SingleInvokers for each dynamic type of the objects passed to invoke() ...
Definition: MethodInvoker.h:73
std::string name() const
TypeWithDict typeOf() const
uint16_t mem[nChs][nEvts]
#define end
Definition: vmac.h:37
void operator()(const char *, const char *) const
Definition: MethodSetter.cc:11
#define begin
Definition: vmac.h:30