@@ -1211,6 +1211,57 @@ Cppyy::TCppIndex_t Cppyy::GetNumBases(TCppScope_t klass)
1211
1211
return Cpp::GetNumBases (klass);
1212
1212
}
1213
1213
1214
+ // //////////////////////////////////////////////////////////////////////////////
1215
+ // / \fn Cppyy::TCppIndex_t Cppyy::GetNumBasesLongestBranch(TCppScope_t klass)
1216
+ // / \brief Retrieve number of base classes in the longest branch of the
1217
+ // / inheritance tree of the input class.
1218
+ // / \param[in] klass The class to start the retrieval process from.
1219
+ // /
1220
+ // / This is a helper function for Cppyy::GetNumBasesLongestBranch.
1221
+ // / Given an inheritance tree, the function assigns weight 1 to each class that
1222
+ // / has at least one base. Starting from the input class, the function is
1223
+ // / called recursively on all the bases. For each base the return value is one
1224
+ // / (the weight of the base itself) plus the maximum value retrieved for their
1225
+ // / bases in turn. For example, given the following inheritance tree:
1226
+ // /
1227
+ // / ~~~{.cpp}
1228
+ // / class A {}; class B: public A {};
1229
+ // / class X {}; class Y: public X {}; class Z: public Y {};
1230
+ // / class C: public B, Z {};
1231
+ // / ~~~
1232
+ // /
1233
+ // / calling this function on an instance of `C` will return 3, the steps
1234
+ // / required to go from C to X.
1235
+ Cppyy::TCppIndex_t Cppyy::GetNumBasesLongestBranch (TCppScope_t klass) {
1236
+ std::vector<TCppScope_t> directbases;
1237
+ for (TCppIndex_t ibase = 0 ; ibase < GetNumBases (klass); ++ibase)
1238
+ directbases.push_back (GetScope (GetBaseName (klass, ibase)));
1239
+ return directbases.size ();
1240
+ // if (directbases.empty()) {
1241
+ // // This is a leaf with no bases
1242
+ // return 0;
1243
+ // }
1244
+
1245
+ // else {
1246
+ // // If there is at least one direct base
1247
+ // std::vector<Cppyy::TCppIndex_t> nbases_branches;
1248
+ // nbases_branches.reserve(ndirectbases);
1249
+ // // Traverse all direct bases of the current class and call the function
1250
+ // // recursively
1251
+ // for (auto baseclass : TRangeDynCast<TBaseClass>(directbases)) {
1252
+ // if (!baseclass)
1253
+ // continue;
1254
+ // if (auto baseclass_tclass = baseclass->GetClassPointer()) {
1255
+ // nbases_branches.emplace_back(GetLongestInheritancePath(baseclass_tclass));
1256
+ // }
1257
+ // }
1258
+ // // Get longest path among the direct bases of the current class
1259
+ // auto longestbranch = std::max_element(std::begin(nbases_branches), std::end(nbases_branches));
1260
+ // // Add 1 to include the current class in the count
1261
+ // return 1 + *longestbranch;
1262
+ // }
1263
+ }
1264
+
1214
1265
std::string Cppyy::GetBaseName (TCppType_t klass, TCppIndex_t ibase)
1215
1266
{
1216
1267
return Cpp::GetName (Cpp::GetBaseClass (klass, ibase));
0 commit comments