21 #ifndef otbOGRGeometriesVisitor_h
22 #define otbOGRGeometriesVisitor_h
24 #include <boost/mpl/assert.hpp>
25 #include <boost/type_traits/is_same.hpp>
26 #include <boost/type_traits/add_const.hpp>
27 #include <boost/type_traits/remove_const.hpp>
28 #include "ogr_geometry.h"
41 template <
typename Tin,
typename Tout>
46 template <
typename Tin,
typename Tout>
49 typedef typename boost::add_const<Tout>::type
type;
54 #define TRY_APPLY(TYPE, geometry, functor) \
55 if (typename propagate_const<TGeometry, TYPE>::type* dc_##TYPE = dynamic_cast<typename propagate_const<TGeometry, TYPE>::type*>(geometry)) \
57 return functor(dc_##TYPE); \
77 template <
typename TResult,
class TGeometry,
typename TFunctor>
78 TResult
apply(TGeometry* geometry, TFunctor functor)
80 BOOST_MPL_ASSERT((boost::is_same<OGRGeometry,
typename boost::remove_const<TGeometry>::type>));
82 else TRY_APPLY(OGRLinearRing, geometry, functor)
else TRY_APPLY(OGRLineString, geometry, functor)
84 else TRY_APPLY(OGRPolygon, geometry, functor)
87 OGRMultiPolygon, geometry, functor)
else TRY_APPLY(OGRGeometryCollection, geometry, functor)
98 #ifndef OTB_MANUAL_INSTANTIATION
102 #endif // otbOGRGeometriesVisitor_h