[Liblas-commits] hg: Re-committing r2086: Removed use of temporary files for the ...

liblas-commits at liblas.org liblas-commits at liblas.org
Tue Aug 24 09:42:58 EDT 2010


changeset d3e162291582 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=d3e162291582
summary: Re-committing r2086: Removed use of temporary files for the sake of printing GeoTIFF directory in SpatialReference::GetGTIFFText. Instead, use custom print method buffering directory in string.

diffstat:

 src/lasspatialreference.cpp |  68 ++++----------------------------------------
 1 files changed, 7 insertions(+), 61 deletions(-)

diffs (91 lines):

diff -r f6fdb3dc46d0 -r d3e162291582 src/lasspatialreference.cpp
--- a/src/lasspatialreference.cpp	Tue Aug 24 13:57:30 2010 +0100
+++ b/src/lasspatialreference.cpp	Tue Aug 24 14:42:48 2010 +0100
@@ -44,11 +44,14 @@
 #include <liblas/detail/utility.hpp>
 // boost
 #include <boost/concept_check.hpp>
+#include <boost/cstdint.hpp>
 // std
 #include <stdexcept>
 #include <string>
 #include <vector>
 
+using namespace boost;
+
 namespace liblas {
 
 SpatialReference::SpatialReference()
@@ -672,68 +675,11 @@
 {
 #ifndef HAVE_LIBGEOTIFF
     return std::string("");
-#else    
-    std::string filename;
-    // FIXME: How do we do this with an ostream instead of having to 
-    // use temporary FILE* ?  -- hobu
-    // replace this with a custom buffer
-    // http://stackoverflow.com/questions/1231461/inheriting-stdistream-or-equivalent
-#ifdef _MSC_VER
+#else
 
-#ifndef L_tmpnam_s
-// MSVC 2003 doesn't have tmpnam_s, so we'll have to use the old functions
-
-    char* tmpName = NULL;
-    tmpName = tmpnam( NULL );
-    
-    if (tmpName == NULL)
-        throw std::runtime_error("Could not allocate temporary file name");
-     
-#else 
-    char tmpName[L_tmpnam_s];
-    errno_t err = tmpnam_s(tmpName, L_tmpnam_s);
-    if (err)
-        throw std::runtime_error("Could not allocate temporary file name");
-
-#endif
-    if (tmpName[0] == '\\')
-        filename = std::string(tmpName + 1);
-    else
-        filename = std::string(tmpName);
-
-#else
-    char tmpName[6] = "XXXXX";
-    if (mkstemp(tmpName) == 0)
-        throw std::runtime_error("Could not allocate temporary file name");
-    filename = tmpName;
-#endif
-
-
-    FILE* f = fopen(filename.c_str(), "wb");
-    GTIFPrint((GTIF*)m_gtiff, 0, f);
-    fclose(f);
-    
-    FILE* f2 = fopen(filename.c_str(), "rb");
-
-    
-    fseek(f2, 0, SEEK_END);
-    long size = ftell(f2);
-    fseek(f2, 0, SEEK_SET);
-    
-    char* data = NULL;
-    data = (char*) malloc((size_t)size+1);
-    if(!data) throw std::runtime_error("Could not allocate data!");
-    
-    size_t read = 0;
-    
-    read = fread(data, 1, (size_t)size, f2);
-    
-    data[read] = 0;
-    std::string output(data);
-
-    free(data);
-    fclose(f2);
-    return output;
+    detail::geotiff_dir_printer geotiff_printer;
+    GTIFPrint(m_gtiff, detail::GeoTiffPrintMethod, &geotiff_printer);
+    return geotiff_printer.output();
 #endif
 }
 


More information about the Liblas-commits mailing list