CMS 3D CMS Logo

FunctionWithDict.cc
Go to the documentation of this file.
2 
6 
7 #include "TMethod.h"
8 #include "TMethodArg.h"
9 #include "TMethodCall.h"
10 
11 #include "oneapi/tbb/concurrent_unordered_map.h"
12 
13 namespace edm {
14  namespace {
15  typedef oneapi::tbb::concurrent_unordered_map<TMethod const*, TypeWithDict> Map;
16  Map returnTypeMap;
17  } // namespace
18 
19  FunctionWithDict::FunctionWithDict() : function_(nullptr) {}
20 
21  FunctionWithDict::FunctionWithDict(TMethod* meth) : function_(meth) {
22  if (meth and isPublic() and not isDestructor() and not isConstructor()) {
23  TMethodCall caller(meth);
24  auto callFunc = caller.GetCallFunc();
25  funcptr_ = gInterpreter->CallFunc_IFacePtr(callFunc);
26  }
27  }
28 
30  if (function_ == nullptr) {
31  return false;
32  }
33  return function_->IsValid();
34  }
35 
36  std::string FunctionWithDict::name() const { return function_->GetName(); }
37 
38  std::string FunctionWithDict::typeName() const { return function_->GetReturnTypeNormalizedName(); }
39 
41  auto const& item = returnTypeMap.find(function_);
42  if (item != returnTypeMap.end()) {
43  return item->second;
44  }
45  TypeWithDict theType = TypeWithDict::byName(function_->GetReturnTypeNormalizedName());
46  returnTypeMap.insert(std::make_pair(function_, theType));
47  return theType;
48  }
49 
51 
52  bool FunctionWithDict::isConst() const { return function_->Property() & kIsConstMethod; }
53 
54  bool FunctionWithDict::isConstructor() const { return function_->ExtraProperty() & kIsConstructor; }
55 
56  bool FunctionWithDict::isDestructor() const { return function_->ExtraProperty() & kIsDestructor; }
57 
58  bool FunctionWithDict::isOperator() const { return function_->ExtraProperty() & kIsOperator; }
59 
60  bool FunctionWithDict::isPublic() const { return function_->Property() & kIsPublic; }
61 
62  bool FunctionWithDict::isStatic() const { return function_->Property() & kIsStatic; }
63 
64  size_t FunctionWithDict::functionParameterSize(bool required /*= false*/) const {
65  if (required) {
66  return function_->GetNargs() - function_->GetNargsOpt();
67  }
68  return function_->GetNargs();
69  }
70 
71  size_t FunctionWithDict::size() const { return function_->GetNargs(); }
72 
75  ObjectWithDict* ret /*=nullptr*/,
76  std::vector<void*> const& values /*=std::vector<void*>()*/) const {
77  void** data = const_cast<void**>(values.data());
78  assert(funcptr_.fGeneric);
79  if (ret == nullptr) {
80  (*funcptr_.fGeneric)(obj.address(), values.size(), data, nullptr);
81  return;
82  }
83  (*funcptr_.fGeneric)(obj.address(), values.size(), data, ret->address());
84  }
85 
88  std::vector<void*> const& values /*=std::vector<void*>()*/) const {
89  void** data = const_cast<void**>(values.data());
90  assert(funcptr_.fGeneric);
91  if (ret == nullptr) {
92  (*funcptr_.fGeneric)(nullptr, values.size(), data, nullptr);
93  return;
94  }
95  (*funcptr_.fGeneric)(nullptr, values.size(), data, ret->address());
96  }
97 
99  if (function_ == nullptr) {
100  return IterWithDict<TMethodArg>();
101  }
102  return IterWithDict<TMethodArg>(function_->GetListOfMethodArgs());
103  }
104 
106 
107 } // namespace edm
TypeWithDict finalReturnType() const
ret
prodAgent to be discontinued
IterWithDict< TMethodArg > end() const
IterWithDict< TMethodArg > begin() const
TypeWithDict declaringType() const
assert(be >=bs)
static TypeWithDict byName(std::string const &name)
Definition: TypeWithDict.cc:74
std::string typeName() const
void invoke(ObjectWithDict const &obj, ObjectWithDict *ret=nullptr, std::vector< void *> const &values=std::vector< void *>()) const
Call a member function.
std::string name() const
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
TInterpreter::CallFuncIFacePtr_t funcptr_
size_t functionParameterSize(bool required=false) const