Skip to content

Commit c0ed57d

Browse files
fix implementation of GetNumBasesLongestBranch (#166)
1 parent e63b71d commit c0ed57d

File tree

1 file changed

+5
-26
lines changed

1 file changed

+5
-26
lines changed

clingwrapper/src/clingwrapper.cxx

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,33 +1289,12 @@ Cppyy::TCppIndex_t Cppyy::GetNumBases(TCppScope_t klass)
12891289
/// calling this function on an instance of `C` will return 3, the steps
12901290
/// required to go from C to X.
12911291
Cppyy::TCppIndex_t Cppyy::GetNumBasesLongestBranch(TCppScope_t klass) {
1292-
std::vector<TCppScope_t> directbases;
1292+
std::vector<size_t> num;
12931293
for (TCppIndex_t ibase = 0; ibase < GetNumBases(klass); ++ibase)
1294-
directbases.push_back(GetScope(GetBaseName(klass, ibase)));
1295-
return directbases.size();
1296-
// if (directbases.empty()) {
1297-
// // This is a leaf with no bases
1298-
// return 0;
1299-
// }
1300-
1301-
// else {
1302-
// // If there is at least one direct base
1303-
// std::vector<Cppyy::TCppIndex_t> nbases_branches;
1304-
// nbases_branches.reserve(ndirectbases);
1305-
// // Traverse all direct bases of the current class and call the function
1306-
// // recursively
1307-
// for (auto baseclass : TRangeDynCast<TBaseClass>(directbases)) {
1308-
// if (!baseclass)
1309-
// continue;
1310-
// if (auto baseclass_tclass = baseclass->GetClassPointer()) {
1311-
// nbases_branches.emplace_back(GetLongestInheritancePath(baseclass_tclass));
1312-
// }
1313-
// }
1314-
// // Get longest path among the direct bases of the current class
1315-
// auto longestbranch = std::max_element(std::begin(nbases_branches), std::end(nbases_branches));
1316-
// // Add 1 to include the current class in the count
1317-
// return 1 + *longestbranch;
1318-
// }
1294+
num.push_back(GetNumBasesLongestBranch(Cppyy::GetBaseScope(klass, ibase)));
1295+
if (num.empty())
1296+
return 0;
1297+
return *std::max_element(num.begin(), num.end()) + 1;
13191298
}
13201299

13211300
std::string Cppyy::GetBaseName(TCppType_t klass, TCppIndex_t ibase)

0 commit comments

Comments
 (0)