Reflection Wrappers : Handle methods with different types of arguments
When wrapping a class we may encounter Methods with same number of arguments but with different types.
For example for vtkAlgorithmRXX.cxx
:
if (method == "SetInputArrayToProcess" && args.size() == 5)
{
vtkRLogF("vtkAlgorithm(%p)::SetInputArrayToProcess", object);
auto temp4 = vtk::variant_cast<int32_t>(args[0]);
auto value0 = static_cast<int>(temp4);
auto temp5 = vtk::variant_cast<int32_t>(args[1]);
auto value1 = static_cast<int>(temp5);
auto temp6 = vtk::variant_cast<int32_t>(args[2]);
auto value2 = static_cast<int>(temp6);
auto temp7 = vtk::variant_cast<int32_t>(args[3]);
auto value3 = static_cast<int>(temp7);
std::string temp8 = vtk::variant_cast<std::string>(args[4]);
const char* value4 = temp8.c_str();
target->SetInputArrayToProcess(value0, value1, value2, value3, value4);
return true;
}
if (method == "SetInputArrayToProcess" && args.size() == 5)
{
vtkRLogF("vtkAlgorithm(%p)::SetInputArrayToProcess", object);
auto temp9 = vtk::variant_cast<int32_t>(args[0]);
auto value0 = static_cast<int>(temp9);
auto temp10 = vtk::variant_cast<int32_t>(args[1]);
auto value1 = static_cast<int>(temp10);
auto temp11 = vtk::variant_cast<int32_t>(args[2]);
auto value2 = static_cast<int>(temp11);
auto temp12 = vtk::variant_cast<int32_t>(args[3]);
auto value3 = static_cast<int>(temp12);
auto temp13 = vtk::variant_cast<int32_t>(args[4]);
auto value4 = static_cast<int>(temp13);
target->SetInputArrayToProcess(value0, value1, value2, value3, value4);
return true;
}
if (method == "SetInputArrayToProcess" && args.size() == 5)
{
vtkRLogF("vtkAlgorithm(%p)::SetInputArrayToProcess", object);
auto temp15 = vtk::variant_cast<int32_t>(args[0]);
auto value0 = static_cast<int>(temp15);
auto temp16 = vtk::variant_cast<int32_t>(args[1]);
auto value1 = static_cast<int>(temp16);
auto temp17 = vtk::variant_cast<int32_t>(args[2]);
auto value2 = static_cast<int>(temp17);
std::string temp18 = vtk::variant_cast<std::string>(args[3]);
const char* value3 = temp18.c_str();
std::string temp19 = vtk::variant_cast<std::string>(args[4]);
const char* value4 = temp19.c_str();
target->SetInputArrayToProcess(value0, value1, value2, value3, value4);
return true;
}
Currently we always pick the first we encounter. We can improve by trying all 3 inside a try-catch
block based on whether the variant_cast
raises an exception or not.
Edited by Christos Tsolakis