|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r64596 - in sandbox/geometry: boost/geometry/extensions/gis/io/shapelib libs/geometry/example/extensions/gis/io/shapelib
From: barend.gehrels_at_[hidden]
Date: 2010-08-04 11:46:02
Author: barendgehrels
Date: 2010-08-04 11:45:23 EDT (Wed, 04 Aug 2010)
New Revision: 64596
URL: http://svn.boost.org/trac/boost/changeset/64596
Log:
Small tweaks in shapelib extension
Text files modified:
sandbox/geometry/boost/geometry/extensions/gis/io/shapelib/dbf_write_attribute.hpp | 34 ++++++++++++++++++++++------------
sandbox/geometry/boost/geometry/extensions/gis/io/shapelib/shape_creator.hpp | 13 +++++++++----
sandbox/geometry/libs/geometry/example/extensions/gis/io/shapelib/shapelib.cpp | 10 +++++-----
3 files changed, 36 insertions(+), 21 deletions(-)
Modified: sandbox/geometry/boost/geometry/extensions/gis/io/shapelib/dbf_write_attribute.hpp
==============================================================================
--- sandbox/geometry/boost/geometry/extensions/gis/io/shapelib/dbf_write_attribute.hpp (original)
+++ sandbox/geometry/boost/geometry/extensions/gis/io/shapelib/dbf_write_attribute.hpp 2010-08-04 11:45:23 EDT (Wed, 04 Aug 2010)
@@ -19,19 +19,16 @@
namespace boost { namespace geometry
{
-
-template <typename T>
-struct DBFFieldType
+namespace detail
{
- // IS integer etc.
-};
+// Called with promote so not all cases necessary
+template <typename T> struct DBFFieldType {};
template <> struct DBFFieldType<int> { static ::DBFFieldType const value = FTInteger; };
-template <> struct DBFFieldType<float> { static ::DBFFieldType const value = FTDouble; };
template <> struct DBFFieldType<double> { static ::DBFFieldType const value = FTDouble; };
template <> struct DBFFieldType<std::string> { static ::DBFFieldType const value = FTString; };
-
+// Also called with promote
template <typename T> struct DBFWriteAttribute
{
};
@@ -39,7 +36,8 @@
template <> struct DBFWriteAttribute<int>
{
template <typename T>
- inline static void apply(DBFHandle dbf, int row_index, int field_index, T const& value)
+ inline static void apply(DBFHandle dbf, int row_index, int field_index,
+ T const& value)
{
DBFWriteIntegerAttribute(dbf, row_index, field_index, value);
}
@@ -48,7 +46,8 @@
template <> struct DBFWriteAttribute<double>
{
template <typename T>
- inline static void apply(DBFHandle dbf, int row_index, int field_index, T const& value)
+ inline static void apply(DBFHandle dbf, int row_index, int field_index,
+ T const& value)
{
DBFWriteDoubleAttribute(dbf, row_index, field_index, value);
}
@@ -56,19 +55,30 @@
template <> struct DBFWriteAttribute<std::string>
{
- template <typename T>
- inline static void apply(DBFHandle dbf, int row_index, int field_index, T const& value)
+ inline static void apply(DBFHandle dbf, int row_index, int field_index,
+ std::string const& value)
{
- DBFWriteStringAttribute(dbf, row_index, field_index, value);
+ DBFWriteStringAttribute(dbf, row_index, field_index, value.c_str());
}
};
+// Derive char* variants from std::string,
+// implicitly casting to a temporary std::string
+// (note that boost::remove_const does not remove const from "const char*")
template <int N>
struct DBFWriteAttribute<char[N]> : DBFWriteAttribute<std::string> {};
+template <int N>
+struct DBFWriteAttribute<const char[N]> : DBFWriteAttribute<std::string> {};
+
+template <>
+struct DBFWriteAttribute<const char*> : DBFWriteAttribute<std::string> {};
+
template <>
struct DBFWriteAttribute<char*> : DBFWriteAttribute<std::string> {};
+}
+
}} // namespace boost::geometry
Modified: sandbox/geometry/boost/geometry/extensions/gis/io/shapelib/shape_creator.hpp
==============================================================================
--- sandbox/geometry/boost/geometry/extensions/gis/io/shapelib/shape_creator.hpp (original)
+++ sandbox/geometry/boost/geometry/extensions/gis/io/shapelib/shape_creator.hpp 2010-08-04 11:45:23 EDT (Wed, 04 Aug 2010)
@@ -12,7 +12,7 @@
#include "shapefil.h"
#include <boost/noncopyable.hpp>
-#include <boost/type_traits/remove_const.hpp>
+#include <boost/type_traits/promote.hpp>
#include <boost/geometry/extensions/gis/io/wkt/wkt.hpp>
#include <boost/geometry/extensions/gis/io/shapelib/shp_create_object.hpp>
@@ -105,15 +105,20 @@
template <typename T>
inline void AddField(std::string const& name, int width = 16, int decimals = 0)
{
- ::DBFAddField(m_dbf, name.c_str(), DBFFieldType<T>::value, width, decimals);
+ ::DBFAddField(m_dbf, name.c_str(),
+ detail::DBFFieldType
+ <
+ typename boost::promote<T>::type
+ >::value,
+ width, decimals);
}
template <typename T>
inline void WriteField(int row_index, int field_index, T const& value)
{
- DBFWriteAttribute
+ detail::DBFWriteAttribute
<
- typename boost::remove_const<T>::type
+ typename boost::promote<T>::type
>::apply(m_dbf, row_index, field_index, value);
}
Modified: sandbox/geometry/libs/geometry/example/extensions/gis/io/shapelib/shapelib.cpp
==============================================================================
--- sandbox/geometry/libs/geometry/example/extensions/gis/io/shapelib/shapelib.cpp (original)
+++ sandbox/geometry/libs/geometry/example/extensions/gis/io/shapelib/shapelib.cpp 2010-08-04 11:45:23 EDT (Wed, 04 Aug 2010)
@@ -87,7 +87,7 @@
{
shape_creator<bg::segment<point_type const> > sc("out/seg");
- sc.AddField<int>("dummy", 10);
+ sc.AddField<short>("dummy", 10);
// This time, write to shape as geometry and not as WKT
// (because bg::segment is currently const -> no WKT support)
@@ -102,16 +102,16 @@
{
shape_creator<bg::multi_point<point_type> > sc("out/mpnt");
- sc.AddField<int>("dummy", 10);
+ sc.AddField<float>("dummy", 10);
int r = sc.AddGeomFromText("MULTIPOINT((0 0),(1 1),(5 2),(7 3))");
- sc.WriteField(r, 0, 10);
+ sc.WriteField(r, 0, 10.1f);
}
{
shape_creator<bg::multi_linestring<bg::linestring<point_type> > > sc("out/ml");
- sc.AddField<int>("dummy", 10);
+ sc.AddField<double>("dummy", 10);
int r = sc.AddGeomFromText("MULTILINESTRING((0 0,1 1,2 0,3 1),(4 4,5 3,6 5))");
- sc.WriteField(r, 0, 10);
+ sc.WriteField(r, 0, 10.2);
}
{
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk