Orfeo Toolbox  4.0
otbOGRGeometriesVisitor.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
18 #ifndef __otbOGRGeometriesVisitor_h
19 #define __otbOGRGeometriesVisitor_h
20 
21 #include <boost/mpl/assert.hpp>
22 #include <boost/type_traits/is_same.hpp>
23 #include <boost/type_traits/remove_const.hpp>
24 #include "ogr_geometry.h"
25 
26 namespace otb
27 {
28 namespace ogr
29 {
37 template <typename Tin, typename Tout>
39 { typedef Tout type; };
40 template <typename Tin, typename Tout>
41 struct propagate_const<Tin const, Tout>
42 { typedef typename boost::add_const<Tout>::type type; };
45 #define TRY_APPLY(TYPE, geometry, functor) \
46 if (typename propagate_const<TGeometry, TYPE>::type * dc \
47  = dynamic_cast<typename propagate_const<TGeometry, TYPE>::type*>(geometry))\
48 {\
49  return functor(dc); \
50 }
51 
52 
69 template <typename TResult, class TGeometry, typename TFunctor>
70 TResult apply(TGeometry * geometry, TFunctor functor)
71 {
72  BOOST_MPL_ASSERT((boost::is_same<OGRGeometry, typename boost::remove_const<TGeometry>::type >));
73  TRY_APPLY(OGRPoint, geometry, functor)
74  else TRY_APPLY(OGRLinearRing, geometry, functor)
75  else TRY_APPLY(OGRLineString, geometry, functor)
76  // else TRY_APPLY(OGRCurve, geometry, functor)
77  else TRY_APPLY(OGRPolygon, geometry, functor)
78  // else TRY_APPLY(OGRSurface, geometry, functor)
79  else TRY_APPLY(OGRMultiLineString, geometry, functor)
80  else TRY_APPLY(OGRMultiPoint, geometry, functor)
81  else TRY_APPLY(OGRMultiPolygon, geometry, functor)
82  else TRY_APPLY(OGRGeometryCollection, geometry, functor)
83  {
84  // functor(geometry);
85  }
86  return TResult(); // keep compiler happy
87 }
88 } // ogr namespace
89 
90 } // end namespace otb
91 
92 #ifndef OTB_MANUAL_INSTANTIATION
93 // #include "otbOGRGeometriesVisitor.txx"
94 #endif
95 
96 #endif // __otbOGRGeometriesVisitor_h

Generated at Sat Mar 8 2014 16:11:54 for Orfeo Toolbox with doxygen 1.8.3.1