Skip to content

Commit 35b6461

Browse files
implement Cppyy::GetSmartPtrType function
1 parent 9e1b9d7 commit 35b6461

File tree

2 files changed

+32
-28
lines changed

2 files changed

+32
-28
lines changed

clingwrapper/src/clingwrapper.cxx

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,37 +1266,41 @@ bool Cppyy::IsSubclass(TCppScope_t derived, TCppScope_t base)
12661266
return Cpp::IsSubclass(derived, base);
12671267
}
12681268

1269+
static std::set<std::string> gSmartPtrTypes =
1270+
{"std::auto_ptr", "std::shared_ptr", "std::unique_ptr", "std::weak_ptr"};
1271+
12691272
bool Cppyy::IsSmartPtr(TCppScope_t klass)
12701273
{
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);
12721302
}
12731303

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-
//
13001304
// void Cppyy::AddSmartPtrType(const std::string& type_name)
13011305
// {
13021306
// gSmartPtrTypes.insert(ResolveName(type_name));

clingwrapper/src/cpp_cppyy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ namespace Cppyy {
244244
RPY_EXPORTED
245245
bool IsSmartPtr(TCppScope_t klass);
246246
RPY_EXPORTED
247-
bool GetSmartPtrInfo(const std::string&, TCppType_t* raw, TCppMethod_t* deref) { assert(0 && "GetSmartPtrInfo"); return false; }
247+
bool GetSmartPtrInfo(const std::string&, TCppType_t* raw, TCppMethod_t* deref);
248248
RPY_EXPORTED
249249
void AddSmartPtrType(const std::string&) { assert(0 && "AddSmartPtrType"); return; }
250250

0 commit comments

Comments
 (0)