[vtk-developers] Another 'major' change in vtkSetGet

Andy Cedilnik Andy.Cedilnik at kitware.com
Fri Feb 8 09:48:13 EST 2002


Hi All!

I made a change to vtkSetGet yesterday. It should not change anything
for existing projects, but I propose a small addition to the coding
standard for VTK.

* Only include those files in the header file that are absolutely
	necessary.

Let me explain that. So far, header files in VTK include several other
header files, where most of them are unnecessary. For example
vtkLight includes vtkMatrix4x4, which is only needed because
of the vtkSetObjectMacro. I added macro vtkSetObjectImplementationMacro,
which solves that problem. The way it works is that you put the actual
prototype for the set method:

	void SetTransformMatrix(vtkMatrix4x4*);

to header file and put the macro in the c++ file:

vtkSetObjectImplementationMacro(vtkLight,TransformMatrix,vtkMatrix4x4);

This eliminates need for the inclusion of additional header files.
It will therefore clean the header files and the inclusion process
will be much more direct. The header will only include the path from the
header file to the vtkObject class instead of several other branches in
VTK hierarchy.

So, what does that mean?

If possible, for the new projects reduce or stop using vtkSetObjectMacro.
vtkSetObjectMacro calls methods on the class, so it needs the class
header file. vtkSetObjectMacro will stay and I guess old files will
still use it. All new classes should use vtkSetObjectImplementationMacro.

There is also another addition to vtkSetGet.
Before if you were trying to do something after setting object, you
essentially had to implement your own vtkSetObjectMacro. The alternative
was to add another method that called vtkSetObjectMacro. I added
another macro called vtkSetObjectBodyMacro, which defines the body
of vtkSetObjectMacro and vtkSetObjectImplementationMacro. So, now
you can implement your own vtkSetObjectMacro by doing something like:


void vtkSomeClass::SetSomeMember(vtkMemberClass *arg)
{
	this->DoSomethingBeforeSetting(arg);
	vtkSetObjectBodyMacro(SomeMeber, vtkMemberClass, arg);
	this->DoSomethingAfterSetting(arg);
}

Sounds good?

Please comment on that.


				Andy Cedilnik




More information about the vtk-developers mailing list