OTB  10.0.0
Orfeo Toolbox
otbOGRFieldWrapper.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 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;
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
Geometric object with descriptive fields.
Encapsulation of OGRFieldDefn: field definition.
OGRFieldDefn & ogr() const
OGRFieldDefn & ogr()
OGRFieldType GetType() const
Field type accessor.
FieldDefn(OGRFieldDefn &definition)
OGRFieldDefn * m_Definition
std::string GetName() const
Field name accessor.
Encapsulation of OGRField Instances of Field are expected to be built from an existing Feature with w...
void UncheckedAssign(Field const &f)
Definition of the field.
Field(Feature &feature, int index)
std::string GetName() const
Field name accessor.
FieldDefn m_Definition
Definition of the field.
bool UncheckedHasBeenSet() const
Definition of the field.
std::shared_ptr< OGRFeature > & m_Feature
Link to the actual OGRFeature in charge of the fields.
void UncheckedUnset() const
Definition of the field.
std::ostream & UncheckedPrintSelf(std::ostream &os, itk::Indent indent) const
Definition of the field.
OGRFieldType GetType() const
Field type accessor.
FieldDefn const & GetDefinition() const
Field definition accessor.
OTBGdalAdapters_EXPORT bool operator==(Feature const &lhs, Feature const &rhs)
OTBGdalAdapters_EXPORT std::ostream & operator<<(std::ostream &os, FieldDefn const &defn)
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.