[vtk-developers] Handling of static function keyword in Java

David Gobbi david.gobbi at gmail.com
Thu Feb 10 09:26:34 EST 2011


Hi Mathieu,

There was a discussion on the list about CanReadFile() a few months
ago, all instances of this method should be virtual.

There are two distinct use cases for CanReadFile()
1) checking to see if a particular object can be used to read a file
2) checking to see if a particular class can be used to read a file

The VTK CanReadFile() is exclusively for use case #1.  It is too bad
that the readers don't have a second method called ClassCanReadFile()
to support use case #2.  As it stands, some authors have chosen to
make CanReadFile() static, rather than choosing a different method
name.

 - David


On Thu, Feb 10, 2011 at 3:53 AM, Mathieu Malaterre
<mathieu.malaterre at gmail.com> wrote:
> Hi,
>
>  I have push a minor change to gerrit to handle static keyword in the
> Java wrapped interface:
>
> http://review.source.kitware.com/#change,888
>
>  This works with a very minor patch to the vtkPaseJava code. However
> there is a single case which is not handled, which can be seen here:
>
> http://review.source.kitware.com/#patch,sidebyside,888,2,IO/vtkGenericEnSightReader.h
>
>  This is a case in C++, which cannot be reproduced in Java, this can
> be summarized by:
>
> struct vtkGenericEnSightReader
> {
> static int CanReadFile(const char*) { return 0; }
> };
>
> struct vtkEnSightMasterServerReader : public vtkGenericEnSightReader
> {
> int CanReadFile(const char *) { return 2; }
> };
>
> int main()
> {
>  vtkGenericEnSightReader* o = vtkEnSightMasterServerReader::New();
>  int v = o->CanReadFile(NULL);
>  std::cout << v << std::endl;
>  return 0;
> }
>
> Which prints '0', even thought the object is of type
> vtkEnSightMasterServerReader. I believe this breaks the paradigm in
> VTK.
>
> So my proposition is to change the 'static' keyword into 'virtual'. This will:
> - mimic the behavior found in vtkImageReader2 subclass
> - allow the wrapping of VTK in Java and support static keyword
>
> Thanks for comments,
> --
> Mathieu
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtk-developers
>
>



More information about the vtk-developers mailing list