OTB  9.0.0
Orfeo Toolbox
otbOGRGeometriesVisitor.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 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 {
44  typedef Tout type;
45 };
46 template <typename Tin, typename Tout>
47 struct propagate_const<Tin const, Tout>
48 {
49  typedef typename boost::add_const<Tout>::type type;
50 };
51 
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)) \
56  { \
57  return functor(dc_##TYPE); \
58  }
59 
60 
77 template <typename TResult, class TGeometry, typename TFunctor>
78 TResult apply(TGeometry* geometry, TFunctor functor)
79 {
80  BOOST_MPL_ASSERT((boost::is_same<OGRGeometry, typename boost::remove_const<TGeometry>::type>));
81  TRY_APPLY(OGRPoint, geometry, functor)
82  else TRY_APPLY(OGRLinearRing, geometry, functor) else TRY_APPLY(OGRLineString, geometry, functor)
83  // else TRY_APPLY(OGRCurve, geometry, functor)
84  else TRY_APPLY(OGRPolygon, geometry, functor)
85  // else TRY_APPLY(OGRSurface, geometry, functor)
86  else TRY_APPLY(OGRMultiLineString, geometry, functor) else TRY_APPLY(OGRMultiPoint, geometry, functor) else TRY_APPLY(
87  OGRMultiPolygon, geometry, functor) 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
otb::ogr::apply
TResult apply(TGeometry *geometry, TFunctor functor)
Definition: otbOGRGeometriesVisitor.h:78
TRY_APPLY
#define TRY_APPLY(TYPE, geometry, functor)
Definition: otbOGRGeometriesVisitor.h:54
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::ogr::propagate_const::type
Tout type
Definition: otbOGRGeometriesVisitor.h:44
otb::ogr::propagate_const
propagation of const-qualifier.
Definition: otbOGRGeometriesVisitor.h:42
otb::ogr::propagate_const< Tin const, Tout >::type
boost::add_const< Tout >::type type
Definition: otbOGRGeometriesVisitor.h:49