OTB  6.7.0
Orfeo Toolbox
otbOGRGeometriesVisitor.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbOGRGeometriesVisitor_h
22 #define otbOGRGeometriesVisitor_h
23 
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"
29 
30 namespace otb
31 {
32 namespace ogr
33 {
41 template <typename Tin, typename Tout>
43 { typedef Tout type; };
44 template <typename Tin, typename Tout>
45 struct propagate_const<Tin const, Tout>
46 { typedef typename boost::add_const<Tout>::type type; };
47 
50 #define TRY_APPLY(TYPE, geometry, functor) \
51 if (typename propagate_const<TGeometry, TYPE>::type * dc_##TYPE \
52  = dynamic_cast<typename propagate_const<TGeometry, TYPE>::type*>(geometry))\
53 {\
54  return functor(dc_##TYPE); \
55 }
56 
57 
74 template <typename TResult, class TGeometry, typename TFunctor>
75 TResult apply(TGeometry * geometry, TFunctor functor)
76 {
77  BOOST_MPL_ASSERT((boost::is_same<OGRGeometry, typename boost::remove_const<TGeometry>::type >));
78  TRY_APPLY(OGRPoint, geometry, functor)
79  else TRY_APPLY(OGRLinearRing, geometry, functor)
80  else TRY_APPLY(OGRLineString, geometry, functor)
81  // else TRY_APPLY(OGRCurve, geometry, functor)
82  else TRY_APPLY(OGRPolygon, geometry, functor)
83  // else TRY_APPLY(OGRSurface, geometry, functor)
84  else TRY_APPLY(OGRMultiLineString, geometry, functor)
85  else TRY_APPLY(OGRMultiPoint, geometry, functor)
86  else TRY_APPLY(OGRMultiPolygon, geometry, functor)
87  else TRY_APPLY(OGRGeometryCollection, geometry, functor)
88  {
89  // functor(geometry);
90  }
91  return TResult(); // keep compiler happy
92 }
93 } // ogr namespace
95 
96 } // end namespace otb
97 
98 #ifndef OTB_MANUAL_INSTANTIATION
99 // #include "otbOGRGeometriesVisitor.hxx"
100 #endif
101 
102 #endif // otbOGRGeometriesVisitor_h
TResult apply(TGeometry *geometry, TFunctor functor)
propagation of const-qualifier.
#define TRY_APPLY(TYPE, geometry, functor)