OTB  9.0.0
Orfeo Toolbox
otbOGRDataSourceWrapper.hxx
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 
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 GDALDataset& otb::ogr::DataSource::ogr()
46 {
47  assert(m_DataSource && "GDALDataset not initialized");
48  return *m_DataSource;
49 }
50 
52 {
53  assert(int(i) < GetLayersCount() && "Out-of-range index");
54  OGRLayer* layer_ptr = GetLayerUnchecked(i);
55  assert(layer_ptr && "No layer returned by OGR");
56  return otb::ogr::Layer(layer_ptr, IsLayerModifiable(i));
57 }
58 
59 inline otb::ogr::Layer const otb::ogr::DataSource::GetLayer(size_t i) const
60 {
61  return const_cast<DataSource*>(this)->GetLayer(i);
62 }
63 
64 inline otb::ogr::Layer const otb::ogr::DataSource::GetLayer(std::string const& name) const
65 {
66  return const_cast<DataSource*>(this)->GetLayer(name);
67 }
68 
69 
71 {
72  return const_cast<DataSource*>(this)->GetLayerChecked(i);
73 }
74 
75 inline OGRLayer* otb::ogr::DataSource::GetLayerUnchecked(size_t i) const
76 {
77  return const_cast<DataSource*>(this)->GetLayerUnchecked(i);
78 }
79 
80 /*===========================================================================*/
81 /*====================[ otb::ogr::DataSource/iterators ]=====================*/
82 /*===========================================================================*/
83 template <class Value>
84 otb::ogr::DataSource::layer_iter<Value>::layer_iter(container_type& datasource, size_t index) : m_DataSource(&datasource), m_index(index)
85 {
86 }
87 
88 template <class Value>
90 {
91 }
92 
93 template <class Value>
94 template <class OtherValue>
96  typename boost::enable_if<boost::is_convertible<OtherValue*, Value*>, enabler>::type)
97  : m_DataSource(other.m_DataSource), m_index(other.m_index)
98 {
99 }
100 
101 template <class Value>
102 template <class OtherValue>
104 {
105  return m_DataSource == other.m_DataSource && other.m_index == m_index;
106 }
107 
108 template <class Value>
110 {
111  assert(m_DataSource && int(m_index) < m_DataSource->GetLayersCount() && "cannot increment past end()");
112  ++m_index;
113 }
114 
115 template <class Value>
117 {
118  assert(m_DataSource && int(m_index) < m_DataSource->GetLayersCount() && "cannot dereference past end()");
119  return Value(m_DataSource->GetLayerUnchecked(m_index), m_DataSource->IsLayerModifiable(m_index));
120 }
121 
122 
123 #endif // otbOGRDataSourceWrapper_hxx
otb::ogr::DataSource::layer_iter
Implementation class for Layer iterator.
Definition: otbOGRDataSourceWrapper.h:212
otb::ogr::DataSource::GetLayerUnchecked
OGRLayer * GetLayerUnchecked(vcl_size_t i)
otb::ogr::DataSource::layer_iter::enabler
Definition: otbOGRDataSourceWrapper.h:214
otb::ogr::DataSource::layer_iter::layer_iter
friend class layer_iter
Definition: otbOGRDataSourceWrapper.h:243
otb::ogr::DataSource::layer_iter::container_type
boost::mpl::if_< boost::is_const< Value >, otb::ogr::DataSource const, otb::ogr::DataSource >::type container_type
Definition: otbOGRDataSourceWrapper.h:231
otb::ogr::DataSource::layer_iter::equal
bool equal(layer_iter< OtherValue > const &other) const
Definition: otbOGRDataSourceWrapper.hxx:103
otb::ogr::DataSource
Collection of geometric objects.
Definition: otbOGRDataSourceWrapper.h:83
otb::ogr::DataSource::m_DataSource
GDALDataset * m_DataSource
Definition: otbOGRDataSourceWrapper.h:579
otb::ogr::DataSource::ogr
GDALDataset & ogr()
Definition: otbOGRDataSourceWrapper.hxx:45
otb::ogr::DataSource::layer_iter::m_DataSource
container_type * m_DataSource
Definition: otbOGRDataSourceWrapper.h:250
otb::ogr::DataSource::GetLayer
Layer GetLayer(vcl_size_t i)
Definition: otbOGRDataSourceWrapper.hxx:51
otb::ogr::DataSource::layer_iter::m_index
vcl_size_t m_index
Definition: otbOGRDataSourceWrapper.h:251
otb::ogr::DataSource::GetLayerChecked
Layer GetLayerChecked(vcl_size_t i)
otb::ogr::DataSource::layer_iter::dereference
Value dereference() const
Definition: otbOGRDataSourceWrapper.hxx:116
otb::ogr::Layer
Layer of geometric objects.
Definition: otbOGRLayerWrapper.h:80
otb::ogr::DataSource::layer_iter::increment
void increment()
Definition: otbOGRDataSourceWrapper.hxx:109
otbOGRDataSourceWrapper.h