Orfeo Toolbox  4.0
otbOGRFieldWrapper.cxx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
18 
19 /*===========================================================================*/
20 /*===============================[ Includes ]================================*/
21 /*===========================================================================*/
22 #include "otbOGRFieldWrapper.h"
23 #include "ogr_feature.h"
24 #include "otbOGRFeatureWrapper.h"
25 #include "otbJoinContainer.h"
26 #include <boost/array.hpp>
27 /*===========================================================================*/
28 /*===========================[ Static Assertions ]===========================*/
29 /*===========================================================================*/
30 namespace otb { namespace ogr {
31 namespace internal {
32 BOOST_STATIC_ASSERT(!(boost::is_same<
33  MemberGetterPtr<int, &OGRFeature::GetFieldAsInteger>,
34  MemberGetterPtr<double, &OGRFeature::GetFieldAsDouble>
35  >::value
36  ));
37 
38 BOOST_STATIC_ASSERT(!(boost::is_same< int, float >::value));
39 BOOST_STATIC_ASSERT(!(boost::is_same<
40  int_<OFTReal >::type,
41  int_<OFTString>::type
42  >::value
43 ));
44 BOOST_STATIC_ASSERT(!(boost::is_same<
45  at<FieldType_Map, float>,
46  void_
47  >::value
48 ));
49 BOOST_STATIC_ASSERT(!(boost::is_same<
50  at<FieldType_Map, double>,
51  int_<OFTReal>
52  >::value
53 ));
54 BOOST_STATIC_ASSERT(!(boost::is_same<
55  at<FieldType_Map, double >::type,
56  at<FieldType_Map, int >::type
57  >::value
58 ));
60  at<FieldType_Map, double>::type::value !=
61  at<FieldType_Map, int >::type::value
62 ));
63 BOOST_STATIC_ASSERT(!(boost::is_same<
64  at<FieldGetters_Map, int_<OFTReal> >,
65  at<FieldGetters_Map, int_<OFTString> >
66  >::value
67 ));
68 
69 BOOST_MPL_ASSERT((boost::is_array<int[42]>));
70 BOOST_MPL_ASSERT_NOT((boost::is_array<boost::array<int, 42> >));
71 BOOST_MPL_ASSERT_NOT((boost::is_array<std::vector<int> >));
72 
73 BOOST_STATIC_ASSERT((boost::is_contiguous<int*>::value));
74 BOOST_STATIC_ASSERT((boost::is_contiguous<int[42]>::value));
75 BOOST_STATIC_ASSERT((boost::is_contiguous<boost::array<int, 42> >::value));
76 BOOST_STATIC_ASSERT((boost::is_contiguous<std::vector<int> >::value));
77 
78 BOOST_MPL_ASSERT((boost::is_same<int, CppToOGRConverter_trait<int>::type >));
79 BOOST_MPL_ASSERT((boost::is_same<char*, CppToOGRConverter_trait<char[8]>::type >));
80 BOOST_MPL_ASSERT_NOT((boost::is_same<char*, char[8] >));
81 
82 }
83 } } // end namespace otb::ogr
84 
85 /*===========================================================================*/
86 /*===============================[ FieldDefn ]===============================*/
87 /*===========================================================================*/
88 
89 std::string otb::ogr::FieldDefn::GetName() const
90 {
91  assert(m_Definition && "No field definition wrapped");
92  return m_Definition->GetNameRef();
93 }
94 
95 OGRFieldType otb::ogr::FieldDefn::GetType() const
96 {
97  assert(m_Definition && "No field definition wrapped");
98  return m_Definition->GetType();
99 }
100 
101 
102 std::ostream & otb::ogr::operator<<(std::ostream & os, otb::ogr::FieldDefn const& defn)
103 {
104  return os << defn.GetName()
105  << " (" << OGRFieldDefn::GetFieldTypeName(defn.GetType()) << ")";
106 }
107 /*===========================================================================*/
108 /*=================================[ Field ]=================================*/
109 /*===========================================================================*/
110 
112 : m_Definition(*feature.ogr().GetFieldDefnRef(index))
113 , m_Feature(feature.sptr())
114 , m_index(index)
115 {
116  CheckInvariants();
117 }
118 
120  std::ostream& os, itk::Indent indent) const
121 {
122  //const itk::Indent one_indent = itk::Indent().GetNextIndent();
123  // os << indent << "|" << one_indent << "+ ";
124  os << indent << this->GetName() << ": ";
125  switch (this->GetType())
126  {
127  case OFTInteger:
128  os << this->GetValue<int>();
129  break;
130  case OFTIntegerList:
131  os << '{';
132  otb::Join(os, this->GetValue<std::vector<int> >(), ", ") << '}';
133  break;
134  case OFTReal :
135  os << this->GetValue<double>();
136  break;
137  case OFTRealList:
138  os << '{';
139  otb::Join(os, this->GetValue<std::vector<double> >(), ", ") << '}';
140  break;
141  case OFTString :
142  os << this->GetValue<std::string>();
143  break;
144  default:
145  os << "??? -> " << this->GetType();
146  break;
147  }
148  os << " (" << OGRFieldDefn::GetFieldTypeName(this->GetType()) << ")";
149  os << "\n";
150  return os;
151 }
152 
154 {
155  return m_Feature->IsFieldSet(m_index);
156 }
157 
159 {
160  m_Feature->UnsetField(m_index);
161 }
162 
164 {
165  if (f.HasBeenSet())
166  {
167  OGRField & of = f.ogr();
168  m_Feature->SetField(m_index, &of); // OGR API copies *of
169  }
170  else // not sure OGR setField handle the case where new fields are unset
171  {
172  this->Unset();
173  }
174 }

Generated at Sat Mar 8 2014 16:11:54 for Orfeo Toolbox with doxygen 1.8.3.1