OTB  9.0.0
Orfeo Toolbox
otbOGRFieldWrapper.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 otbOGRFieldWrapper_h
22 #define otbOGRFieldWrapper_h
23 
24 #include <memory>
25 #include <string>
26 
27 class OGRFieldDefn;
28 class OGRFeature;
29 #if defined(_MSC_VER)
30 #pragma warning(push)
31 #pragma warning(disable : 4251)
32 #include "ogr_core.h" // OGR enums
33 #pragma warning(pop)
34 #else
35 #include "ogr_core.h" // OGR enums
36 #endif
37 #include "itkIndent.h"
38 
39 #include "OTBGdalAdaptersExport.h"
40 
41 namespace otb
42 {
43 namespace ogr
44 {
45 
46 /*===========================================================================*/
47 /*===========================[ Field definition ]============================*/
48 /*===========================================================================*/
60 class OTBGdalAdapters_EXPORT FieldDefn
61 {
62 public:
63  FieldDefn(OGRFieldDefn& definition) : m_Definition(&definition)
64  {
65  }
66  std::string GetName() const;
67  OGRFieldType GetType() const;
68 
69 
70  OGRFieldDefn& ogr()
71  {
72  return *m_Definition;
73  }
74  OGRFieldDefn& ogr() const
75  {
76  return *m_Definition;
77  }
78 
79 private:
83  OGRFieldDefn* m_Definition;
84 };
85 
86 inline bool operator==(FieldDefn const& lhs, FieldDefn const& rhs)
87 {
88  return lhs.GetName() == rhs.GetName() && lhs.GetType() == rhs.GetType();
89 }
90 
91 OTBGdalAdapters_EXPORT std::ostream& operator<<(std::ostream& os, FieldDefn const& defn);
92 
93 /*===========================================================================*/
94 /*=================================[ Field ]=================================*/
95 /*===========================================================================*/
96 class Feature;
97 
117 class OTBGdalAdapters_EXPORT Field
118 {
119 public:
120 
127  Field(Feature& feature, int index);
129  FieldDefn const& GetDefinition() const
130  {
131  return m_Definition;
132  }
134  OGRFieldType GetType() const
135  {
136  return m_Definition.GetType();
137  }
139  std::string GetName() const
140  {
141  return m_Definition.GetName();
142  }
144 
146  bool HasBeenSet() const;
148  void Unset() const;
149 
159  template <typename T>
160  void SetValue(T const& value);
161 
172  template <typename T>
173  T GetValue() const;
174 
176  std::ostream& PrintSelf(std::ostream& os, itk::Indent indent) const;
177 
190  void Assign(Field const& f);
192 
194  OGRField& ogr();
195 
202  OGRField& ogr() const;
203 
204 private:
213  bool UncheckedHasBeenSet() const;
214  void UncheckedUnset() const;
215  std::ostream& UncheckedPrintSelf(std::ostream& os, itk::Indent indent) const;
216  void UncheckedAssign(Field const& f);
218 
219 
228  void CheckInvariants() const;
229 
233  std::shared_ptr<OGRFeature>& m_Feature;
240  int m_index;
241 };
242 }
243 } // end namespace otb::ogr
244 
245 #ifndef OTB_MANUAL_INSTANTIATION
246 #include "otbOGRFieldWrapper.hxx"
247 #endif
248 
249 #endif // otbOGRFieldWrapper_h
otb::ogr::FieldDefn
Encapsulation of OGRFieldDefn: field definition.
Definition: otbOGRFieldWrapper.h:60
otb::ogr::operator<<
OTBGdalAdapters_EXPORT std::ostream & operator<<(std::ostream &os, FieldDefn const &defn)
otb::ogr::FieldDefn::m_Definition
OGRFieldDefn * m_Definition
Definition: otbOGRFieldWrapper.h:83
otb::ogr::Field::m_Definition
FieldDefn m_Definition
Definition of the field.
Definition: otbOGRFieldWrapper.h:231
otb::ogr::Field::GetName
std::string GetName() const
Field name accessor.
Definition: otbOGRFieldWrapper.h:139
otb::ogr::operator==
OTBGdalAdapters_EXPORT bool operator==(Feature const &lhs, Feature const &rhs)
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otbOGRFieldWrapper.hxx
otb::ogr::FieldDefn::ogr
OGRFieldDefn & ogr() const
Definition: otbOGRFieldWrapper.h:74
otb::ogr::FieldDefn::FieldDefn
FieldDefn(OGRFieldDefn &definition)
Definition: otbOGRFieldWrapper.h:63
otb::ogr::FieldDefn::GetType
OGRFieldType GetType() const
Field type accessor.
otb::ogr::Field
Encapsulation of OGRField Instances of Field are expected to be built from an existing Feature with w...
Definition: otbOGRFieldWrapper.h:117
otb::ogr::FieldDefn::GetName
std::string GetName() const
Field name accessor.
otb::ogr::Field::GetDefinition
FieldDefn const & GetDefinition() const
Field definition accessor.
Definition: otbOGRFieldWrapper.h:129
otb::ogr::Feature
Geometric object with descriptive fields.
Definition: otbOGRFeatureWrapper.h:63
otb::Wrapper::MetaDataHelper::GetType
OTBApplicationEngine_EXPORT MDType GetType(const std::string &val)
otb::ogr::Field::GetType
OGRFieldType GetType() const
Field type accessor.
Definition: otbOGRFieldWrapper.h:134
otb::ogr::FieldDefn::ogr
OGRFieldDefn & ogr()
Definition: otbOGRFieldWrapper.h:70
otb::ogr::Field::m_index
int m_index
Definition: otbOGRFieldWrapper.h:240
otb::ogr::Field::m_Feature
std::shared_ptr< OGRFeature > & m_Feature
Link to the actual OGRFeature in charge of the fields.
Definition: otbOGRFieldWrapper.h:233