[geos-devel] Delocalizing the WKT writer?
Mateusz Loskot
mateusz at loskot.net
Thu Aug 28 16:29:39 EDT 2008
Sean Gillies wrote:
> Yep, works. Any objections to the changes?
>
> http://trac.osgeo.org/geos/changeset/2172
Sean,
Generally, it solves the problem of lack of locale independence of GEOS
but this code is far from exception safety.
Frank's CPLLocaleC can solve it but, I am personally allergic to C-style
locale management.
In C library, there is only one global locale object.
In C++, locale management makes it possible to change locales for
particular scope/operation only, without influencing any external parts
of software.
Using setlocale from C library switches C++ library to C-style locale
management.
I agree with you that implementation WKTReader/Writer is not very clean,
and it mixes use of C and C++ I/O, what also makes a mess regarding
locale management.
I'm going to try to review and reafactor WKT classes to base on C++ I/O
then switching locales for particular instance of WKT writing (ie. in
GEOSGeomToWKT) will be as easy as:
Geometry* g =
...
{
std::ostringstring os;
std::locale loc("C"); // global locale untouched
s.imbue(loc);
char* wkt = g->toString(os); //
return wkt;
}
> Would anyone like to see me use a macro instead?
I would not like to see macros :-)
Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net
Charter Member of OSGeo, http://osgeo.org
More information about the geos-devel
mailing list