[vtk-developers] STL policy
Will Schroeder
will.schroeder at kitware.com
Sat Jan 18 06:41:48 EST 2003
Hi Folks-
I'd like to add a FAQ entry (and update the VTK User's Guide) and describe
VTK's STL policy. Here's what I'm thinking:
1. STL is for implementation, not interface. All STL references should be
contained in a .cxx class implementation file, never the .h header file.
2. Use the PIMPL idiom to forward reference/contain STL classes.
STL-derived classes such be private, not protected or public to avoid dll
boundary issues.
3. Use the vtkstd:: namespace to refer to STL classes and functions.
Here's an example (from vtkInterpolateVelocityField):
In the .h file (the PIMPL) forward declare
class vtkInterpolatedVelocityFieldDataSetsType;
class VTK_COMMON_EXPORT vtkInterpolatedVelocityField : public vtkFunctionSet
{
private:
vtkInterpolatedVelocityFieldDataSetsType* DataSets;
};
In the .cxx file define the class (here deriving from a STL container)
typedef vtkstd::vector< vtkSmartPointer<vtkDataSet> > DataSetsTypeBase;
class vtkInterpolatedVelocityFieldDataSetsType: public DataSetsTypeBase {};
In the .cxx file construct and destruct the class:
vtkInterpolatedVelocityField::vtkInterpolatedVelocityField()
{
this->DataSets = new vtkInterpolatedVelocityFieldDataSetsType;
}
vtkInterpolatedVelocityField::~vtkInterpolatedVelocityField()
{
delete this->DataSets;
}
Comments?
Will
More information about the vtk-developers
mailing list