Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-24 02:18:55

0001 #include "FWCore/Reflection/interface/FunctionWithDict.h"
0002 
0003 #include "FWCore/Reflection/interface/IterWithDict.h"
0004 #include "FWCore/Reflection/interface/ObjectWithDict.h"
0005 #include "FWCore/Reflection/interface/TypeWithDict.h"
0006 
0007 #include "TMethod.h"
0008 #include "TMethodArg.h"
0009 #include "TMethodCall.h"
0010 
0011 #include "oneapi/tbb/concurrent_unordered_map.h"
0012 
0013 namespace edm {
0014   namespace {
0015     typedef oneapi::tbb::concurrent_unordered_map<TMethod const*, TypeWithDict> Map;
0016     Map returnTypeMap;
0017   }  // namespace
0018 
0019   FunctionWithDict::FunctionWithDict() : function_(nullptr) {}
0020 
0021   FunctionWithDict::FunctionWithDict(TMethod* meth) : function_(meth) {
0022     if (meth and isPublic() and not isDestructor() and not isConstructor()) {
0023       TMethodCall caller(meth);
0024       auto callFunc = caller.GetCallFunc();
0025       funcptr_ = gInterpreter->CallFunc_IFacePtr(callFunc);
0026     }
0027   }
0028 
0029   FunctionWithDict::operator bool() const {
0030     if (function_ == nullptr) {
0031       return false;
0032     }
0033     return function_->IsValid();
0034   }
0035 
0036   std::string FunctionWithDict::name() const { return function_->GetName(); }
0037 
0038   std::string FunctionWithDict::typeName() const { return function_->GetReturnTypeNormalizedName(); }
0039 
0040   TypeWithDict FunctionWithDict::finalReturnType() const {
0041     auto const& item = returnTypeMap.find(function_);
0042     if (item != returnTypeMap.end()) {
0043       return item->second;
0044     }
0045     TypeWithDict theType = TypeWithDict::byName(function_->GetReturnTypeNormalizedName());
0046     returnTypeMap.insert(std::make_pair(function_, theType));
0047     return theType;
0048   }
0049 
0050   TypeWithDict FunctionWithDict::declaringType() const { return TypeWithDict(function_->GetClass()); }
0051 
0052   bool FunctionWithDict::isConst() const { return function_->Property() & kIsConstMethod; }
0053 
0054   bool FunctionWithDict::isConstructor() const { return function_->ExtraProperty() & kIsConstructor; }
0055 
0056   bool FunctionWithDict::isDestructor() const { return function_->ExtraProperty() & kIsDestructor; }
0057 
0058   bool FunctionWithDict::isOperator() const { return function_->ExtraProperty() & kIsOperator; }
0059 
0060   bool FunctionWithDict::isPublic() const { return function_->Property() & kIsPublic; }
0061 
0062   bool FunctionWithDict::isStatic() const { return function_->Property() & kIsStatic; }
0063 
0064   size_t FunctionWithDict::functionParameterSize(bool required /*= false*/) const {
0065     if (required) {
0066       return function_->GetNargs() - function_->GetNargsOpt();
0067     }
0068     return function_->GetNargs();
0069   }
0070 
0071   size_t FunctionWithDict::size() const { return function_->GetNargs(); }
0072 
0073   /// Call a member function.
0074   void FunctionWithDict::invoke(ObjectWithDict const& obj,
0075                                 ObjectWithDict* ret /*=nullptr*/,
0076                                 std::vector<void*> const& values /*=std::vector<void*>()*/) const {
0077     void** data = const_cast<void**>(values.data());
0078     assert(funcptr_.fGeneric);
0079     if (ret == nullptr) {
0080       (*funcptr_.fGeneric)(obj.address(), values.size(), data, nullptr);
0081       return;
0082     }
0083     (*funcptr_.fGeneric)(obj.address(), values.size(), data, ret->address());
0084   }
0085 
0086   /// Call a static function.
0087   void FunctionWithDict::invoke(ObjectWithDict* ret /*=nullptr*/,
0088                                 std::vector<void*> const& values /*=std::vector<void*>()*/) const {
0089     void** data = const_cast<void**>(values.data());
0090     assert(funcptr_.fGeneric);
0091     if (ret == nullptr) {
0092       (*funcptr_.fGeneric)(nullptr, values.size(), data, nullptr);
0093       return;
0094     }
0095     (*funcptr_.fGeneric)(nullptr, values.size(), data, ret->address());
0096   }
0097 
0098   IterWithDict<TMethodArg> FunctionWithDict::begin() const {
0099     if (function_ == nullptr) {
0100       return IterWithDict<TMethodArg>();
0101     }
0102     return IterWithDict<TMethodArg>(function_->GetListOfMethodArgs());
0103   }
0104 
0105   IterWithDict<TMethodArg> FunctionWithDict::end() const { return IterWithDict<TMethodArg>(); }
0106 
0107 }  // namespace edm