Wrapping classes with deleted methods in Python
Now that VTK is moving towards C++11, people are more careful than ever about properly deleting unused destructors and copy constructors. The wrappers, likewise, need to know when these methods are or are not available.
Background: The Python wrappers can wrap an object "by reference" or "by value". All classes that derive from vtkObjectBase are wrapped "by reference", which means that these objects are always handled via a pointer. Conversely, all other classes are wrapped "by value", meaning that the Python wrappers make their own copy of these objects and use pass-by-value semantics. Obviously, pass-by-value requires a copy constructor, but the wrappers add additional restrictions on top of this.
Currently, for a non-vtkObjectBase object to be wrapped, it must have a public copy constructor and, furthermore, must have a public destructor and a public default constructor. I want to change this, because it is too restrictive. Here are some examples of classes I'd like to wrap:
class vtkFloatingPointExceptions
{
public:
static void Enable();
static void Disable();
private:
vtkFloatingPointExceptions() = delete;
vtkFloatingPointExceptions(const vtkFloatingPointExceptions&) = delete;
void operator=(const vtkFloatingPointExceptions&) = delete;
};
The above class is only used via its static methods, so the fact that it cannot be constructed is a non-issue. It should be wrapped so that its static methods can be used.
class vtkDICOMFile
{
public:
vtkDICOMFile(const char *filepath, int mode);
void Close();
~vtkDICOMFile();
private:
vtkDICOMFile() = delete;
vtkDICOMFile(const vtkDICOMFile&) = delete;
void operator=(const vtkDICOMFile&) = delete;
};
The above class has a deleted copy constructor, and therefore cannot be passed by value, but since we can construct and delete it and call its methods, there is no reason why we shouldn't wrap it. Also, since pass-by-value is impossible, we could allow pass-by-reference and assume that whoever constructed the object is responsible for deleting it.
The wrapper files that need to be fixed are vtkWrapPythonType.c and PyVTKSpecialObject.cxx.