Skip to content

Add a size hint macro for the wrappers

David Gobbi requested to merge dgobbi/vtk:sizehint into master

VTK_SIZEHINT(a, n) hints that the parameter "a" has a size "n". If only one argument is given, VTK_SIZEHINT(n), then the hint is for the size of the return value (i.e. like the old "hints" file). Note that if a hint is added to a base class method, it will be inherited by all overrides (but override methods are allowed to override the hints). The "size" can be any expression that evaluates to an integer.

Examples:

double *GetPoint()
  VTK_SIZEHINT(3);

void InsertNextCell(vtkIdType nPts, vtkIdType* ptIds)
  VTK_SIZEHINT(ptIds, nPts);

A further change in this MR is that refs to pointers are wrapped:

void GetCell(vtkIdType loc, vtkIdType &npts, vtkIdType* &pts)
  VTK_SIZEHINT(pts, npts);

Like other parameters that are returned by reference, the use of these parameters requires the use of "vtk.reference()":

npts = vtk.reference(0)    # create a proxy to a Python int object
pts = vtk.reference((0,))  # create a proxy to a Python tuple
cellarray.GetCell(0, npts, pts)

The int and tuple inside of "npts" and "pts" will be replaced with new ones. Since "pts" is a proxy for a tuple, you can use it anywhere you would use a tuple, or you can use pts.get() to get the tuple object (i.e. it works like a smart pointer).

Note that "vtk.reference" was introduced to VTK many years ago as "vtk.mutable", but for this MR, I have decided to change the name to reflect the usage (the old name will still work).

Edited by David Gobbi

Merge request reports