@@ -1266,37 +1266,41 @@ bool Cppyy::IsSubclass(TCppScope_t derived, TCppScope_t base)
1266
1266
return Cpp::IsSubclass (derived, base);
1267
1267
}
1268
1268
1269
+ static std::set<std::string> gSmartPtrTypes =
1270
+ {" std::auto_ptr" , " std::shared_ptr" , " std::unique_ptr" , " std::weak_ptr" };
1271
+
1269
1272
bool Cppyy::IsSmartPtr (TCppScope_t klass)
1270
1273
{
1271
- return Cpp::IsSmartPtrType (Cpp::GetTypeFromScope (klass));
1274
+ const std::string& rn = Cppyy::GetScopedFinalName (klass);
1275
+ if (gSmartPtrTypes .find (rn.substr (0 , rn.find (" <" ))) != gSmartPtrTypes .end ())
1276
+ return true ;
1277
+ return false ;
1278
+ }
1279
+
1280
+ bool Cppyy::GetSmartPtrInfo (
1281
+ const std::string& tname, TCppScope_t* raw, TCppMethod_t* deref)
1282
+ {
1283
+ // TODO: We can directly accept scope instead of name
1284
+ const std::string& rn = ResolveName (tname);
1285
+ if (gSmartPtrTypes .find (rn.substr (0 , rn.find (" <" ))) == gSmartPtrTypes .end ())
1286
+ return false ;
1287
+
1288
+ if (!raw && !deref) return true ;
1289
+
1290
+ TCppScope_t scope = Cppyy::GetScope (rn);
1291
+ if (!scope)
1292
+ return false ;
1293
+
1294
+ std::vector<TCppMethod_t> ops;
1295
+ Cpp::GetOperator (scope, Cpp::OP_Arrow, ops);
1296
+ if (ops.size () != 1 )
1297
+ return false ;
1298
+
1299
+ if (deref) *deref = ops[0 ];
1300
+ if (raw) *raw = Cppyy::GetScopeFromType (Cpp::GetFunctionReturnType (ops[0 ]));
1301
+ return (!deref || *deref) && (!raw || *raw);
1272
1302
}
1273
1303
1274
- // bool Cppyy::GetSmartPtrInfo(
1275
- // const std::string& tname, TCppType_t* raw, TCppMethod_t* deref)
1276
- // {
1277
- // const std::string& rn = ResolveName(tname);
1278
- // if (gSmartPtrTypes.find(rn.substr(0, rn.find("<"))) != gSmartPtrTypes.end()) {
1279
- // if (!raw && !deref) return true;
1280
- //
1281
- // TClassRef& cr = type_from_handle(GetScope(tname));
1282
- // if (cr.GetClass()) {
1283
- // TFunction* func = cr->GetMethod("operator->", "");
1284
- // if (!func) {
1285
- // gInterpreter->UpdateListOfMethods(cr.GetClass());
1286
- // func = cr->GetMethod("operator->", "");
1287
- // }
1288
- // if (func) {
1289
- // if (deref) *deref = (TCppMethod_t)new_CallWrapper(func);
1290
- // if (raw) *raw = GetScope(TClassEdit::ShortType(
1291
- // func->GetReturnTypeNormalizedName().c_str(), 1));
1292
- // return (!deref || *deref) && (!raw || *raw);
1293
- // }
1294
- // }
1295
- // }
1296
- //
1297
- // return false;
1298
- // }
1299
- //
1300
1304
// void Cppyy::AddSmartPtrType(const std::string& type_name)
1301
1305
// {
1302
1306
// gSmartPtrTypes.insert(ResolveName(type_name));
0 commit comments