From 08a273e9fff28818bc22cadabbc49730a55655eb Mon Sep 17 00:00:00 2001
From: Luc Hermitte <luc.hermitte@c-s.fr>
Date: Thu, 19 Apr 2012 17:46:28 +0200
Subject: [PATCH] ENH: OTB-134/OGR: printf-self

---
 .../OGRAdapters/otbOGRFeatureWrapper.cxx          | 12 +++++++++---
 .../OGRAdapters/otbOGRLayerWrapper.cxx            | 15 +++++++++++----
 .../OGRAdapters/otbOGRLayerWrapper.h              |  4 ++++
 3 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/Code/UtilitiesAdapters/OGRAdapters/otbOGRFeatureWrapper.cxx b/Code/UtilitiesAdapters/OGRAdapters/otbOGRFeatureWrapper.cxx
index d294d8465c..bf73dea0ec 100644
--- a/Code/UtilitiesAdapters/OGRAdapters/otbOGRFeatureWrapper.cxx
+++ b/Code/UtilitiesAdapters/OGRAdapters/otbOGRFeatureWrapper.cxx
@@ -61,8 +61,15 @@ otb::ogr::Feature otb::ogr::Feature::clone() const
 void otb::ogr::Feature::PrintSelf(std::ostream & os, itk::Indent indent) const
 {
   CheckInvariants();
+  const itk::Indent one_indent = itk::Indent().GetNextIndent();
+  const int nbFields = m_Feature->GetFieldCount();
   os << indent << "+";
-  os << " " << m_Feature->GetFieldCount() << " fields\n";
+  os << " " << nbFields << " fields\n";
+  for (int i=0; i!=nbFields; ++i) {
+    os << indent << "|" << one_indent << "+ ";
+    os << const_cast<Feature*>(this)->ogr().GetFieldDefnRef(i)->GetType() << ": " // << *this
+      << "\n";
+  }
 }
 
 bool otb::ogr::operator==(otb::ogr::Feature const& lhs, otb::ogr::Feature const& rhs)
@@ -76,6 +83,5 @@ bool otb::ogr::operator==(otb::ogr::Feature const& lhs, otb::ogr::Feature const&
     (l == r ) // incl. ==0
     ||
     (l && r && l->Equal(r)) // must be non-null to compare them with Equal
-   ;
+;
 }
-
diff --git a/Code/UtilitiesAdapters/OGRAdapters/otbOGRLayerWrapper.cxx b/Code/UtilitiesAdapters/OGRAdapters/otbOGRLayerWrapper.cxx
index f48efca58d..288dfd4129 100644
--- a/Code/UtilitiesAdapters/OGRAdapters/otbOGRLayerWrapper.cxx
+++ b/Code/UtilitiesAdapters/OGRAdapters/otbOGRLayerWrapper.cxx
@@ -131,15 +131,12 @@ void otb::ogr::Layer::PrintSelf(std::ostream& os, itk::Indent indent) const
   os << indent << "+";
   if (m_Layer) // in case for odd reason the layer that should exist can't be found
     {
-    os << "Layer <" << GetName() << ">\n";
+    os << "Layer <" << GetName() << "> of "<< OGRGeometryTypeToName(GetGeomType()) <<"\n";
     indent = indent.GetNextIndent();
     BOOST_FOREACH(Feature f, *this)
       {
       f.PrintSelf(os, indent);
       }
-    // boost::for_each( // for each feature
-      // *this,
-      // boost::bind(&Feature::PrintSelf, _1, boost::ref(os), indent.GetNextIndent()));
     }
   else
     {
@@ -249,3 +246,13 @@ void otb::ogr::Layer::ReorderFields(int * map)
     }
 #endif
 }
+
+OGRwkbGeometryType otb::ogr::Layer::GetGeomType() const
+{
+  assert(m_Layer && "OGRLayer not initialized");
+#if GDAL_VERSION_NUM < 1800
+  return GetLayerDefn().GetGeomType();
+#else
+  return m_Layer->GetGeomType();
+#endif
+}
diff --git a/Code/UtilitiesAdapters/OGRAdapters/otbOGRLayerWrapper.h b/Code/UtilitiesAdapters/OGRAdapters/otbOGRLayerWrapper.h
index c2f4170c9b..1b86974620 100644
--- a/Code/UtilitiesAdapters/OGRAdapters/otbOGRLayerWrapper.h
+++ b/Code/UtilitiesAdapters/OGRAdapters/otbOGRLayerWrapper.h
@@ -25,6 +25,8 @@ PURPOSE.  See the above copyright notices for more information.
 #include <boost/utility/enable_if.hpp>
 #include "itkIndent.h"
 #include "otbOGRFeatureWrapper.h"
+
+#include "ogr_core.h" // OGRwkbGeometryType
 class OGRLayer; // fwd declarations
 class OGRDataSource;
 class OGRGeometry;
@@ -204,6 +206,8 @@ public:
   void ReorderFields(int *map);
   void SetIgnoredFields(int *);
   //@}
+
+  OGRwkbGeometryType GetGeomType() const;
 private:
   /**
    * Internal encapsulation of \c OGRLayer::GetNextFeature().
-- 
GitLab