OTB  6.7.0
Orfeo Toolbox
otbOGRDataSourceWrapper.hxx
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 
27 #ifndef otbOGRDataSourceWrapper_hxx
28 #define otbOGRDataSourceWrapper_hxx
29 
31 
32 /*===========================================================================*/
33 /*===============================[ Includes ]================================*/
34 /*===========================================================================*/
35 #include <cassert>
36 #include "itkMacro.h" // itk::ExceptionObject
37 #include "ogrsf_frmts.h" // OGRDataSource & OGRLayer
38 
39 /*===========================================================================*/
40 /*=========================[ otb::ogr::DataSource ]==========================*/
41 /*===========================================================================*/
42 // These function definitions are inline so assert() will be expanded according
43 // to the compilation mode of the client code.
44 
45 inline
47 {
48  assert(m_DataSource && "GDALDataset not initialized");
49  return *m_DataSource;
50 }
51 
52 inline
54 {
55  assert(int(i) < GetLayersCount() && "Out-of-range index");
56  OGRLayer * layer_ptr = GetLayerUnchecked(i);
57  assert(layer_ptr && "No layer returned by OGR");
58  return otb::ogr::Layer(layer_ptr, IsLayerModifiable(i));
59 }
60 
61 inline
63 {
64  return const_cast <DataSource*>(this)->GetLayer(i);
65 }
66 
67 inline
68 otb::ogr::Layer const otb::ogr::DataSource::GetLayer(std::string const& name) const
69 {
70  return const_cast <DataSource*>(this)->GetLayer(name);
71 }
72 
73 
74 inline
76 {
77  return const_cast <DataSource*>(this)->GetLayerChecked(i);
78 }
79 
80 inline
81 OGRLayer* otb::ogr::DataSource::GetLayerUnchecked(size_t i) const
82 {
83  return const_cast <DataSource*>(this)->GetLayerUnchecked(i);
84 }
85 
86 /*===========================================================================*/
87 /*====================[ otb::ogr::DataSource/iterators ]=====================*/
88 /*===========================================================================*/
89 template <class Value>
91 : m_DataSource(&datasource), m_index(index)
92 {}
93 
94 template <class Value>
96 : m_DataSource(0), m_index(0)
97 {}
98 
99 template <class Value>
102  typename boost::enable_if<boost::is_convertible<OtherValue*,Value*>
103  , enabler
104  >::type
105 )
106 : m_DataSource(other.m_DataSource), m_index(other.m_index)
107 {}
108 
109 template <class Value>
110 template <class OtherValue>
112 {
113  return m_DataSource == other.m_DataSource && other.m_index == m_index;
114 }
115 
116 template <class Value>
118 {
119  assert(m_DataSource
120  && int(m_index) < m_DataSource->GetLayersCount()
121  && "cannot increment past end()");
122  ++m_index;
123 }
124 
125 template <class Value>
127 {
128  assert(m_DataSource
129  && int(m_index) < m_DataSource->GetLayersCount()
130  && "cannot dereference past end()");
131  return Value(m_DataSource->GetLayerUnchecked(m_index), m_DataSource->IsLayerModifiable(m_index));
132 }
133 
134 
135 #endif // otbOGRDataSourceWrapper_hxx
bool equal(layer_iter< OtherValue > const &other) const
Collection of geometric objects.
Layer GetLayer(vcl_size_t i)
Layer of geometric objets.
boost::mpl::if_< boost::is_const< Value >, otb::ogr::DataSource const , otb::ogr::DataSource >::type container_type
Layer GetLayerChecked(vcl_size_t i)
Implementation class for Layer iterator.
OGRLayer * GetLayerUnchecked(vcl_size_t i)