[Insight-developers] Cell Interface Test

Luis Ibanez luis.ibanez at kitware.com
Sun Aug 5 09:13:32 EDT 2007


Hi Alex,

When testing const methods, what matters is the constness of the
object whose method is being called.

In the case

                         A = B->F()

the const version of "F()" will be called if "B" is const.


For the test case that you are interested on, the easiest way
to trigger the invocation of the const version of PointIdsBegin()
is to do:


   const PolygonCellType * cell2 = cell;

   PointIdConstIterator  pointItr = cell2->PointsIdBegin();

   Note that you don't need to use the autopointer in this case,
   since there is no reason to fear that "cell" will be destroyed
   before you are done using "cell2".



   Regards,


      Luis


---------------------------
Alexandre GOUAILLARD wrote:
> Hi,
> 
> Trying to extend the coverage for QuadEdgeMEshPolygonCell, I realyzed that
> the itkCellInterfaceTest was not covering the const versions of GetPointIds,
> PointIdsBegin, and PointIdsEnd.
> 
> My understanding of const correctnes is still limited so I'm not sure if all
> I'm going to say is correct. Please correct me.
> 
> My guess is that the following lines were supposed to do that,
> std::cout << "    ConstIterator test: PointIds for empty cell: ";
> Typename Tcell::PointIdConstIterator cpointId = cell->PointIdsBegin();
> Typename Tcell::PointIdConstIterator cendId   = cell->PointIdsEnd();
> While(...)
>   { ... }
> 
> but it seems that the object itself must be const, and not only the return
> type, to call the right method.
> 
> I could not create a const version of the cells and pass it through because
> the first lines of the function:
> CellAutoPointer cell(aCell,true);
> Create a new cell, dropping the const attribute.
> 
> The only solution I found is to change the cpointId and cendId as follows:
> Typename Tcell::PointIdConstIterator cpointId
>   = (const_cast<const Tcell*>(aCell))->PointIdsBegin();
> Typename Tcell::PointIdConstIterator cendId   = cell->PointIdsEnd();
>   = (const_cast<const Tcell*>(aCell))->PointIdsEnd();
> 
> It solves the probleme (and increase the coverage of every single cell type)
> but is it really the right way to do it?
> 
> Alex Hanfei.
> 
> 
> _______________________________________________
> Insight-developers mailing list
> Insight-developers at itk.org
> http://www.itk.org/mailman/listinfo/insight-developers
> 


More information about the Insight-developers mailing list