OTB  9.0.0
Orfeo Toolbox
otbOGRHelpers.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 otbOGRHelpers_h
22 #define otbOGRHelpers_h
23 
24 #include "itkMacro.h"
25 #include <string>
26 #include <vector>
27 #include <cassert>
28 #include <boost/range/begin.hpp>
29 #include <boost/range/end.hpp>
30 #include "ogr_feature.h"
31 #if defined(__GNUC__) || defined(__clang__)
32 #pragma GCC diagnostic push
33 #pragma GCC diagnostic ignored "-Wunused-local-typedefs"
34 #include <boost/range/size.hpp>
35 #pragma GCC diagnostic pop
36 #else
37 #include <boost/range/size.hpp>
38 #endif
39 #include <boost/mpl/assert.hpp>
40 #include <boost/type_traits/is_same.hpp>
41 #if !defined(NDEBUG)
42 #include "cpl_string.h" // CSLCount
43 #endif
44 
45 #include "OTBGdalAdaptersExport.h"
46 
47 class GDALDataset;
48 
49 namespace otb
50 {
51 namespace ogr
52 {
73 struct OTBGdalAdapters_EXPORT StringListConverter
74 {
76 
77  template <class ContainerType>
88  explicit StringListConverter(ContainerType const& strings)
89  {
90  BOOST_MPL_ASSERT((boost::is_same<typename ContainerType::value_type, std::string>));
91  m_raw.reserve(boost::size(strings) + 1);
92  for (typename ContainerType::const_iterator b = boost::begin(strings), e = boost::end(strings); b != e; ++b)
93  {
94  m_raw.push_back(b->c_str());
95  }
96  m_raw.push_back(nullptr);
97  assert(CSLCount(const_cast<char**>(&m_raw[0])) == static_cast<int>(boost::size(strings)));
98  }
99 
103  char** to_ogr() const
104  {
105  return m_raw.size() == 1 ? nullptr : const_cast<char**>(&m_raw[0]);
106  }
107 
108 private:
109  std::vector<char const*> m_raw;
110 };
111 
117 OTBGdalAdapters_EXPORT std::vector<std::string> GetAvailableDriversAsStringVector();
118 
128 OTBGdalAdapters_EXPORT std::vector<std::string> GetFileListAsStringVector(GDALDataset* dataset);
129 
136 OTBGdalAdapters_EXPORT bool IsFieldSetAndNotNull(OGRFeature* feat, int index);
137 
138 } // ogr namespace
139 } // end namespace otb
140 
141 #endif // otbOGRHelpers_h
otb::ogr::StringListConverter
Helper class to convert a set of standard C++ string into char** as OGR API expects.
Definition: otbOGRHelpers.h:73
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::ogr::IsFieldSetAndNotNull
OTBGdalAdapters_EXPORT bool IsFieldSetAndNotNull(OGRFeature *feat, int index)
otb::ogr::StringListConverter::m_raw
std::vector< char const * > m_raw
Definition: otbOGRHelpers.h:109
otb::ogr::GetFileListAsStringVector
OTBGdalAdapters_EXPORT std::vector< std::string > GetFileListAsStringVector(GDALDataset *dataset)
otb::ogr::StringListConverter::to_ogr
char ** to_ogr() const
Definition: otbOGRHelpers.h:103
otb::ogr::StringListConverter::StringListConverter
StringListConverter(ContainerType const &strings)
Definition: otbOGRHelpers.h:88
otb::ogr::GetAvailableDriversAsStringVector
OTBGdalAdapters_EXPORT std::vector< std::string > GetAvailableDriversAsStringVector()