[geos-commits] r2178 - in branches/3.0/source: headers/geos/io io

svn_geos at osgeo.org svn_geos at osgeo.org
Fri Aug 29 11:00:26 EDT 2008


Author: sgillies
Date: 2008-08-29 11:00:26 -0400 (Fri, 29 Aug 2008)
New Revision: 2178

Added:
   branches/3.0/source/headers/geos/io/CLocalizer.h
   branches/3.0/source/io/CLocalizer.cpp
Modified:
   branches/3.0/source/io/WKTWriter.cpp
Log:
Added CLocalizer class that switches to C locale and restores to the outer context's locale when deleted (#201)

Added: branches/3.0/source/headers/geos/io/CLocalizer.h
===================================================================
--- branches/3.0/source/headers/geos/io/CLocalizer.h	                        (rev 0)
+++ branches/3.0/source/headers/geos/io/CLocalizer.h	2008-08-29 15:00:26 UTC (rev 2178)
@@ -0,0 +1,21 @@
+
+namespace geos {
+namespace io {
+
+/**
+ * \class CLocalizer io.h geos.h
+ */
+
+class CLocalizer
+{
+private:
+    char *outer_locale;
+
+public:
+    CLocalizer();
+    ~CLocalizer();
+};
+
+} // namespace io
+} // namespace geos
+

Added: branches/3.0/source/io/CLocalizer.cpp
===================================================================
--- branches/3.0/source/io/CLocalizer.cpp	                        (rev 0)
+++ branches/3.0/source/io/CLocalizer.cpp	2008-08-29 15:00:26 UTC (rev 2178)
@@ -0,0 +1,34 @@
+#include <geos/io/CLocalizer.h>
+
+#include <string>
+
+using namespace std;
+
+namespace geos {
+namespace io {
+
+CLocalizer::CLocalizer()
+{
+    outer_locale = strdup(std::setlocale(LC_NUMERIC, NULL));
+    if (std::setlocale(LC_NUMERIC, "C") == NULL)
+    {
+        if (outer_locale != NULL)
+        {
+            free(outer_locale);
+            outer_locale = NULL;
+        }
+    }
+}
+
+CLocalizer::~CLocalizer()
+{
+    if (outer_locale != NULL)
+    {
+        std::setlocale(LC_NUMERIC, outer_locale);
+        free(outer_locale);
+        outer_locale = NULL;
+    }
+}
+
+} // namespace geos.io
+} // namespace geos

Modified: branches/3.0/source/io/WKTWriter.cpp
===================================================================
--- branches/3.0/source/io/WKTWriter.cpp	2008-08-29 14:57:50 UTC (rev 2177)
+++ branches/3.0/source/io/WKTWriter.cpp	2008-08-29 15:00:26 UTC (rev 2178)
@@ -54,7 +54,6 @@
 WKTWriter::toLineString(const CoordinateSequence& seq)
 {
 	stringstream buf("LINESTRING ", ios_base::in|ios_base::out);
-    buf.imbue(std::locale("C"));
 	unsigned int npts = seq.getSize();
 	if ( npts == 0 )
 	{
@@ -82,7 +81,6 @@
 WKTWriter::toLineString(const Coordinate& p0, const Coordinate& p1)
 {
 	stringstream ret("LINESTRING (", ios_base::in|ios_base::out);
-    ret.imbue(std::locale("C"));
 	ret << p0.x << " " << p0.y;
 #if PRINT_Z
 	ret << " " << p0.z;
@@ -100,7 +98,6 @@
 WKTWriter::toPoint(const Coordinate& p0)
 {
 	stringstream ret("POINT (", ios_base::in|ios_base::out);
-    ret.imbue(std::locale("C"));
 #if PRINT_Z
 	ret << p0.x << " " << p0.y  << " " << p0.z << " )";
 #else



More information about the geos-commits mailing list