[Insight-users] Data Representation Objects

Ofri Sadowsky ofri@cs.jhu.edu
Mon, 25 Nov 2002 17:29:28 -0500


This is a multi-part message in MIME format.
--------------E41C391064B2CAF344BDAAC0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

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.


Luis Ibanez wrote:

> Hi Ofri,
>
> I don't think we need the friend on the templated
> class. This should work ok with just the trait.
>
> Adding the Adapter to the traits is possible but it
> will be a contradiction with what an Adapter is
> supposed to be. In principle and Adapter of class A
> to class B should be an external class that makes
> A look like B without A,B having to know about each
> other.
>
> Puting the adaptor inside the container forces the
> container to know about all the other classes.
>
> Regardless of this, the main objection for putting it
> inside is maintainability. We anticipate a long like
> for ITK (e.g. VTK is over eigh years now). If we put
> the adaptor inside the Vector container, we will have
> to put an identical copy inside the MapContainer, and
> hope that if four years from now somebody modifies the
> version on the VectorContainer he will also update the
> one on the MapContainer.
>
> The templated version shouldn't be too hard to
> implement.
>
> Luis
>
> =================================================
>
> Ofri Sadowsky wrote:
>
> > Having a templated adapter is a good idea. But I am not sure if we can use friends in
> > templates. Maybe we don't need the friends.
> > Would it be possible to add the templated adapter to the container's traits? Or would that
> > create a circular reference?
> >

--------------E41C391064B2CAF344BDAAC0
Content-Type: application/x-zip-compressed;
 name="StlContainerAdapter.zip"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
 filename="StlContainerAdapter.zip"

UEsDBBQAAAAIABCJeS2utwqQbQIAABsGAAAdAAAAaXRrU1RMQ29uc3RDb250YWluZXJBZGFw
dGVyLmiNVN2LGjEQf3Zh/4cBoVU59H31hOMo7UP7UqUUeiIxmdW0a7Jks55y3P/emUT3Vjxr
fRCymd/HfKWrc6Mwh+VS+z+z+ddHaypPf15og+5BidKjW27SpEtR9Ol2YJqMBgN4koWoKrgW
mCYDeDAg4gns6jdKD34jPEhR+QoE/JIMBFLLsp/7fcOwAG28PV1XXmXZfr9fMKMwCtCIVYFE
ICWSAYr0G4SaknTFQZs1KOEFwVwtfe1wyLg5RUS/uoLS2Z1WqCC3jqXQ5ULSPcnpyqORB3jW
fnNM7SKrsqirIBkNLmBrlc41uiHMtCEi3KE7+A1bIbUQdMcAh3w2FgySOPmWoihCnQI5zg8l
Ztm3yKZ6ffIWdBTGZKwLuXwhoo9cv7oSa1Lbi21ZINj8mmH+hSJf69Uk3P5AlmjuJjWVY23I
aWHN+g4+FbhF49nkdAo7lEdwTzSQ/vgk12rdLtBO2nD4wHi4b7EMP6Of+aKh+o55741uNALF
baaSVrE3jB8OuR6jNPFIFRAeJ57Yjdgip9tQTdPk1qi+pElZrwotszTpMAkvTDOdTXy7UeNW
5Fn/jom26zW+YD1DtNvGX2Au3BobJC9c6fSOEmR7LSjVcbs8nqlgMbjDy7mh+Q6zI215AG4A
zxuNm30Ga4oDKO14H4Mbni1tDU8QQ04ry5XtXKtZL+bxzsSRqTAI0Up0wmsrdlYrsCU6QXbu
I32b5VKEqJr43s3QRrXdzKv+z8sYc8Y+ITrZWVF7r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