OTB  6.7.0
Orfeo Toolbox
otbOGRFieldWrapper.h
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 #ifndef otbOGRFieldWrapper_h
22 #define otbOGRFieldWrapper_h
23 
24 #include <string>
25 #include <boost/shared_ptr.hpp>
26 class OGRFieldDefn;
27 class OGRFeature;
28 #if defined(_MSC_VER)
29 #pragma warning ( push )
30 #pragma warning ( disable: 4251 )
31 #include "ogr_core.h" // OGR enums
32 #pragma warning ( pop )
33 #else
34 #include "ogr_core.h" // OGR enums
35 #endif
36 #include "itkIndent.h"
37 
38 #include "OTBGdalAdaptersExport.h"
39 
40 namespace otb { namespace ogr {
41 
42 /*===========================================================================*/
43 /*===========================[ Field definition ]============================*/
44 /*===========================================================================*/
56 class OTBGdalAdapters_EXPORT FieldDefn
57  {
58 public:
59  FieldDefn(OGRFieldDefn& definition) : m_Definition(&definition){ }
60  std::string GetName() const;
61  OGRFieldType GetType() const;
62 
63 
64  OGRFieldDefn & ogr() { return *m_Definition; }
65  OGRFieldDefn & ogr() const { return *m_Definition; }
66 
67 private:
71  OGRFieldDefn * m_Definition;
72  };
73 
74 inline
75 bool operator==(FieldDefn const& lhs, FieldDefn const& rhs)
76  {
77  return lhs.GetName() == rhs.GetName()
78  && lhs.GetType() == rhs.GetType();
79  }
80 
81 OTBGdalAdapters_EXPORT
82 std::ostream & operator<<(std::ostream & os, FieldDefn const& defn);
83 
84 /*===========================================================================*/
85 /*=================================[ Field ]=================================*/
86 /*===========================================================================*/
87 class Feature;
88 
108 class OTBGdalAdapters_EXPORT Field
109 {
110 public:
111 
118  Field(Feature & feature, int index);
120  FieldDefn const& GetDefinition() const
121  { return m_Definition; }
123  OGRFieldType GetType() const
124  { return m_Definition.GetType(); }
126  std::string GetName() const
127  { return m_Definition.GetName(); }
129 
131  bool HasBeenSet() const;
133  void Unset() const;
134 
144  template <typename T> void SetValue(T const& value);
145 
156  template <typename T> T GetValue() const;
157 
159  std::ostream & PrintSelf(std::ostream&os, itk::Indent indent) const;
160 
173  void Assign(Field const& f);
175 
177  OGRField & ogr();
178 
185  OGRField & ogr() const;
186 
187 private:
196  bool UncheckedHasBeenSet() const;
197  void UncheckedUnset() const;
198  std::ostream & UncheckedPrintSelf(std::ostream&os, itk::Indent indent) const;
199  void UncheckedAssign(Field const& f);
201 
202 
211  void CheckInvariants() const;
212 
216  boost::shared_ptr<OGRFeature> & m_Feature;
223  int m_index;
224 };
225 
226 }
227 } // end namespace otb::ogr
228 
229 #ifndef OTB_MANUAL_INSTANTIATION
230 #include "otbOGRFieldWrapper.hxx"
231 #endif
232 
233 #endif // otbOGRFieldWrapper_h
OTBGdalAdapters_EXPORT std::ostream & operator<<(std::ostream &os, FieldDefn const &defn)
OGRFieldType GetType() const
Field type accessor.
OGRFieldDefn & ogr()
FieldDefn(OGRFieldDefn &definition)
OTBGdalAdapters_EXPORT bool operator==(Feature const &lhs, Feature const &rhs)
OGRFieldDefn & ogr() const
FieldDefn m_Definition
Definition of the field.
FieldDefn const & GetDefinition() const
Field definition accessor.
OTBApplicationEngine_EXPORT MDType GetType(const std::string &val)
std::string GetName() const
Field name accessor.
OGRFieldDefn * m_Definition
Geometric objet with descriptive fields.
Encapsulation of OGRField Instances of Field are expected to be built from an existing Feature with w...
std::string GetName() const
Field name accessor.
Encapsulation of OGRFieldDefn: field definition.
boost::shared_ptr< OGRFeature > & m_Feature
Link to the actual OGRFeature in charge of the fields.
OGRFieldType GetType() const
Field type accessor.