MantisBT - VTK
View Issue Details
0007192VTK(No Category)public2008-06-14 17:432016-08-12 09:54
Tom Fogal 
Kitware Robot 
normalminoralways
closedmoved 
 
 
0007192: Read-only access to objects is not const correct
Accessing data within a VTK object is a mutable operation, even when the data access itself does not actually mutate the object's state. This imposes difficulties when using VTK in a const-correct environment.
Attached is a small patch aimed at allowing easier use of VTK in a const correct program. The current definition of vtkGetObjectMacro essentially expands into:
    virtual type *GetWhateverYouSay() { ... }
This causes the macro to expand into:
    virtual type *GetWhateverYouSay() { ... }
    virtual const type *GetWhateverYouSay() const { ... }

As it provides both versions, it provides a backwards-compatible API while allowing new code to utilize the const correct version.

The change to vtkObject was necessary to get the build to work; I made the `GetDebug' method const.


Would you accept more patches of this nature?
No tags attached.
patch const.patch (1,627) 2008-06-14 17:43
https://www.vtk.org/Bug/file/6529/const.patch
Issue History
2008-06-14 17:43Tom FogalNew Issue
2008-06-14 17:43Tom FogalFile Added: const.patch
2008-06-14 19:16Tom FogalNote Added: 0012344
2011-06-16 13:11Zack GalbreathCategory => (No Category)
2016-08-12 09:54Kitware RobotNote Added: 0036988
2016-08-12 09:54Kitware RobotStatusexpired => closed
2016-08-12 09:54Kitware RobotResolutionopen => moved
2016-08-12 09:54Kitware RobotAssigned To => Kitware Robot

Notes
(0012344)
Tom Fogal   
2008-06-14 19:16   
I was thinking that it might be better for constants to utilize references instead of pointers. This would differentiate their use -- since stack-based VTK objects are currently disallowed, it would call attention to the fact that whatever VTK object you have obtained via such a mechanism is constant.

More concretely, this would mean that as I read code such as:
   v = XYZ->GetFoo().GetBar().GetBaz();

I know that
   1) `XYZ' is a pointer; it is likely to be a mutable pointer.
   2) I don't know the return type of GetFoo, but I know that the `Foo' is RO.
   3) Likewise with `Bar', and `Baz'

(1) comes from the fact that if the VTK library provides const& methods but not many const* methods, then the programmer would have to `break convention' to obtain a constant pointer (e.g. call a mutable method that returns a pointer, but store it in a pointer to const). (2) and (3) are useful because they do not require me to go load up the vtk.org doxygen documentation.

Thoughts?
(0036988)
Kitware Robot   
2016-08-12 09:54   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current VTK Issues page linked in the banner at the top of this page.