[Insight-users] Data Representation Objects
Luis Ibanez
luis.ibanez@kitware.com
Tue, 26 Nov 2002 13:12:58 -0500
Hi Ofri,
Thanks for contributing the code of the STL adaptor.
The files have been modified a bit an added to the repository.
The MapContainer and VectorContainer were modified in order to
support the Adaptors.
The test was enlarged and extended to cover the MapContainer
both in const and non-const access.
The test was checked in under
Insight/Testing/Code/Common.
---
About the casting: the traditional casting style
of
(type)variable
has been replaced with
static_cast<type>( variable )
mainly because its syntactic ambiguity.
You will also find a lot of dynamic_cast<type> in ITK,
since the toolkit take advantage of the RTTI information
(e.g. in exceptions and events).
Please let us know if you notice any issues.
Thanks again,
Luis
-------------------------------------------
Ofri Sadowsky wrote:
> I attach a zip file containing templated code for the adapters, and an example file using them.
>
> In order for the adapters to work, it is necessary to make the following changes in the
> original ITK container (e.g itk::VectorContainer).
> 1. Declare the type
>
> typedef VectorType STLContainerType;
>
> 2. Declare cast methods:
>
> STLContainerType & CastToStlContainer()
> {
> return static_cast<STLContainerType &>(*this);
> }
>
> const STLContainerType & CastToStlConstContainer() const
> {
> return static_cast<const STLContainerType &>(*this);
> }
>
> 3. The cast methods and the STLContainerType may be public or private. If any of them is
> private, it is necessary to declare the Adapter classes as friends, as follows:
>
> template<typename itkContainer>
> class STLContainerAdapter;
> friend class STLContainerAdapter;
>
> template<typename itkContainer>
> class STLConstContainerAdapter;
> friend class STLConstContainerAdapter;
>
> There may be another way to declare friends, but this one worked for me.
>
>
> I don't have much experience using the static_cast operator. I guess it does more rigorous
> type-checking than the C-style (target_type) cast operation, and it is surely a cleaner syntax.
> In any case, not even a friend can static_cast<class_B &>(class_A_object), when class A is
> declared with inheritance "private B". That is, at least on my VC++. Which is why I had the
> cast methods defined. Maybe there's a nicer way to do that. I was not so impressed of the C++
> cast overloading the last time I looked at it.
>
>
> Ofri.