[Liblas-commits] laszip: updated usage example again

liblas-commits at liblas.org liblas-commits at liblas.org
Mon Jun 13 13:16:03 EDT 2011


details:   http://hg.liblas.orglaszip/rev/040439efe9ab
changeset: 242:040439efe9ab
user:      isenburg
date:      Mon Jun 13 10:17:37 2011 -0700
description:
updated usage example again
Subject: laszip: updated error info via const char* get_error()

details:   http://hg.liblas.orglaszip/rev/e8ae0aa64e71
changeset: 243:e8ae0aa64e71
user:      isenburg
date:      Mon Jun 13 10:18:18 2011 -0700
description:
updated error info via const char* get_error()
Subject: laszip: updated error info via const char* get_error()

details:   http://hg.liblas.orglaszip/rev/1765b4d540bd
changeset: 244:1765b4d540bd
user:      isenburg
date:      Mon Jun 13 10:19:15 2011 -0700
description:
updated error info via const char* get_error()

diffstat:

 include/laszip/lasunzipper.hpp |   5 +++-
 include/laszip/laszip.hpp      |   4 +++
 include/laszip/laszipper.hpp   |   5 +++-
 src/lasunzipper.cpp            |  47 +++++++++++++++++++++++++----------------
 src/laszip.cpp                 |   5 ++++
 src/laszipper.cpp              |  41 +++++++++++++++++++++++++-----------
 tools/laszippertest.cpp        |  22 +++++++++---------
 7 files changed, 85 insertions(+), 44 deletions(-)

diffs (truncated from 360 to 300 lines):

diff -r 93b3dc9ecd89 -r 1765b4d540bd include/laszip/lasunzipper.hpp
--- a/include/laszip/lasunzipper.hpp	Mon Jun 13 05:56:51 2011 -0700
+++ b/include/laszip/lasunzipper.hpp	Mon Jun 13 10:19:15 2011 -0700
@@ -62,12 +62,15 @@
   LASunzipper();
   ~LASunzipper();
 
-  char* error_string;
+  // in case a function returns false this string describes the problem
+  const char* get_error() const;
 
 private:
   unsigned int count;
   ByteStreamIn* stream;
   LASreadPoint* reader;
+  bool return_error(const char* err);
+  char* error_string;
 };
 
 #endif
diff -r 93b3dc9ecd89 -r 1765b4d540bd include/laszip/laszip.hpp
--- a/include/laszip/laszip.hpp	Mon Jun 13 05:56:51 2011 -0700
+++ b/include/laszip/laszip.hpp	Mon Jun 13 10:19:15 2011 -0700
@@ -99,6 +99,9 @@
   bool set_chunk_size(const unsigned int chunk_size);             /* for compressor only */
   bool request_version(const unsigned short requested_version);   /* for compressor only */
 
+  // in case a function returns false this string describes the problem
+  const char* get_error() const;
+
   // stored in LASzip VLR data section
   unsigned short compressor;
   unsigned short coder;
@@ -115,6 +118,7 @@
   LASzip();
   ~LASzip();
 
+private:
   bool return_error(const char* err);
   char* error_string;
 };
diff -r 93b3dc9ecd89 -r 1765b4d540bd include/laszip/laszipper.hpp
--- a/include/laszip/laszipper.hpp	Mon Jun 13 05:56:51 2011 -0700
+++ b/include/laszip/laszipper.hpp	Mon Jun 13 10:19:15 2011 -0700
@@ -62,12 +62,15 @@
   LASzipper();
   ~LASzipper();
 
-  char* error_string;
+  // in case a function returns false this string describes the problem
+  const char* get_error() const;
 
 private:
   unsigned int count;
   ByteStreamOut* stream;
   LASwritePoint* writer;
+  bool return_error(const char* err);
+  char* error_string;
 };
 
 #endif
diff -r 93b3dc9ecd89 -r 1765b4d540bd src/lasunzipper.cpp
--- a/src/lasunzipper.cpp	Mon Jun 13 05:56:51 2011 -0700
+++ b/src/lasunzipper.cpp	Mon Jun 13 10:19:15 2011 -0700
@@ -39,49 +39,46 @@
 
 bool LASunzipper::open(FILE* infile, const LASzip* laszip)
 {
-  if (!infile) { error_string = strdup("FILE* infile pointer is NULL"); return false; };
-  if (!laszip) { error_string = strdup("const LASzip* laszip pointer is NULL"); return false; };
+  if (!infile) return return_error("FILE* infile pointer is NULL");
+  if (!laszip) return return_error("const LASzip* laszip pointer is NULL");
   count = 0;
   if (reader) delete reader;
   reader = new LASreadPoint();
-  if (!reader) { error_string = strdup("alloc of LASreadPoint failed"); return false; };
-  if (!reader->setup(laszip->num_items, laszip->items, laszip)) { error_string = strdup("setup() of LASreadPoint failed"); return false; };
+  if (!reader) return return_error("alloc of LASreadPoint failed");
+  if (!reader->setup(laszip->num_items, laszip->items, laszip)) return return_error("setup() of LASreadPoint failed");
   if (stream) delete stream;
   if (IS_LITTLE_ENDIAN())
     stream = new ByteStreamInFileLE(infile);
   else
     stream = new ByteStreamInFileBE(infile);
-  if (!stream) { error_string = strdup("alloc of ByteStreamInFile failed"); return false; };
-  if (!reader->init(stream)) { error_string = strdup("init() of LASreadPoint failed"); return false; };
+  if (!stream) return return_error("alloc of ByteStreamInFile failed");
+  if (!reader->init(stream)) return return_error("init() of LASreadPoint failed");
   return true;
 }
 
 bool LASunzipper::open(istream& instream, const LASzip* laszip)
 {
-  if (!laszip) { error_string = strdup("const LASzip* laszip pointer is NULL"); return false; };
+  if (!laszip) return return_error("const LASzip* laszip pointer is NULL");
   count = 0;
   if (reader) delete reader;
   reader = new LASreadPoint();
-  if (!reader) { error_string = strdup("alloc of LASreadPoint failed"); return false; };
-  if (!reader->setup(laszip->num_items, laszip->items, laszip)) { error_string = strdup("setup() of LASreadPoint failed"); return false; };
+  if (!reader) return return_error("alloc of LASreadPoint failed");
+  if (!reader->setup(laszip->num_items, laszip->items, laszip)) return return_error("setup() of LASreadPoint failed");
   if (stream) delete stream;
   if (IS_LITTLE_ENDIAN())
     stream = new ByteStreamInIstreamLE(instream);
   else
     stream = new ByteStreamInIstreamBE(instream);
-  if (!stream) { error_string = strdup("alloc of ByteStreamInStream failed"); return false; };
-  if (!reader->init(stream)) { error_string = strdup("init() of LASreadPoint failed"); return false; };
+  if (!stream) return return_error("alloc of ByteStreamInStream failed");
+  if (!reader->init(stream)) return return_error("init() of LASreadPoint failed");
   return true;
 }
 
 bool LASunzipper::seek(const unsigned int position)
 {
-  if (reader->seek(count, position))
-  {
-    count = position;
-    return true;
-  }
-  return false;
+  if (!reader->seek(count, position)) return return_error("seek() of LASreadPoint failed");
+  count = position;
+  return true;
 }
 
 unsigned int LASunzipper::tell() const
@@ -109,10 +106,24 @@
     delete stream;
     stream = 0;
   }
-  if (!done) { error_string = strdup("done() of LASreadPoint failed"); return false; }
+  if (!done) return return_error("done() of LASreadPoint failed");
   return true;
 }
 
+const char* LASunzipper::get_error() const
+{
+  return error_string;
+}
+
+bool LASunzipper::return_error(const char* error)
+{
+  char err[256];
+  sprintf(err, "%s (LASzip v%d.%dr%d)", error, LASZIP_VERSION_MAJOR, LASZIP_VERSION_MINOR, LASZIP_VERSION_REVISION);
+  if (error_string) free(error_string);
+  error_string = strdup(err);
+  return false;
+}
+
 LASunzipper::LASunzipper()
 {
   error_string = 0;
diff -r 93b3dc9ecd89 -r 1765b4d540bd src/laszip.cpp
--- a/src/laszip.cpp	Mon Jun 13 05:56:51 2011 -0700
+++ b/src/laszip.cpp	Mon Jun 13 10:19:15 2011 -0700
@@ -179,6 +179,11 @@
   return true;
 }
 
+const char* LASzip::get_error() const
+{
+  return error_string;
+}
+
 bool LASzip::return_error(const char* error)
 {
   char err[256];
diff -r 93b3dc9ecd89 -r 1765b4d540bd src/laszipper.cpp
--- a/src/laszipper.cpp	Mon Jun 13 05:56:51 2011 -0700
+++ b/src/laszipper.cpp	Mon Jun 13 10:19:15 2011 -0700
@@ -39,38 +39,38 @@
 
 bool LASzipper::open(FILE* outfile, const LASzip* laszip)
 {
-  if (!outfile) { error_string = strdup("FILE* outfile pointer is NULL"); return false; };
-  if (!laszip) { error_string = strdup("const LASzip* laszip pointer is NULL"); return false; };
+  if (!outfile) return return_error("FILE* outfile pointer is NULL");
+  if (!laszip) return return_error("const LASzip* laszip pointer is NULL");
   count = 0;
   if (writer) delete writer;
   writer = new LASwritePoint();
-  if (!writer) { error_string = strdup("alloc of LASwritePoint failed"); return false; };
-  if (!writer->setup(laszip->num_items, laszip->items, laszip)) { error_string = strdup("setup() of LASwritePoint failed"); return false; };
+  if (!writer) return return_error("alloc of LASwritePoint failed");
+  if (!writer->setup(laszip->num_items, laszip->items, laszip)) return return_error("setup() of LASwritePoint failed");
   if (stream) delete stream;
   if (IS_LITTLE_ENDIAN())
     stream = new ByteStreamOutFileLE(outfile);
   else
     stream = new ByteStreamOutFileBE(outfile);
-  if (!stream) { error_string = strdup("alloc of ByteStreamOutFile failed"); return false; };
-  if (!writer->init(stream)) { error_string = strdup("init() of LASwritePoint failed"); return false; };
+  if (!stream) return return_error("alloc of ByteStreamOutFile failed");
+  if (!writer->init(stream)) return return_error("init() of LASwritePoint failed");
   return true;
 }
 
 bool LASzipper::open(ostream& outstream, const LASzip* laszip)
 {
-  if (!laszip) { error_string = strdup("const LASzip* laszip pointer is NULL"); return false; };
+  if (!laszip) return return_error("const LASzip* laszip pointer is NULL");
   count = 0;
   if (writer) delete writer;
   writer = new LASwritePoint();
-  if (!writer) { error_string = strdup("alloc of LASwritePoint failed"); return false; };
-  if (!writer->setup(laszip->num_items, laszip->items, laszip)) { error_string = strdup("setup() of LASwritePoint failed"); return false; };
+  if (!writer) return return_error("alloc of LASwritePoint failed");
+  if (!writer->setup(laszip->num_items, laszip->items, laszip)) return return_error("setup() of LASwritePoint failed");
   if (stream) delete stream;
   if (IS_LITTLE_ENDIAN())
     stream = new ByteStreamOutOstreamLE(outstream);
   else
     stream = new ByteStreamOutOstreamBE(outstream);
-  if (!stream) { error_string = strdup("alloc of ByteStreamOutStream failed"); return false; };
-  if (!writer->init(stream)) { error_string = strdup("init() of LASwritePoint failed"); return false; };
+  if (!stream) return return_error("alloc of ByteStreamOutStream failed");
+  if (!writer->init(stream)) return return_error("init() of LASwritePoint failed");
   return true;
 }
 
@@ -82,7 +82,8 @@
 
 bool LASzipper::chunk()
 {
-  return (writer->chunk() == TRUE);
+  if (!writer->chunk()) return return_error("chunk() of LASwritePoint failed");
+  return true;
 }
 
 bool LASzipper::close()
@@ -99,10 +100,24 @@
     delete stream;
     stream = 0;
   }
-  if (!done) { error_string = strdup("done() of LASwritePoint failed"); return false; }
+  if (!done) return return_error("done() of LASwritePoint failed");
   return true;
 }
 
+const char* LASzipper::get_error() const
+{
+  return error_string;
+}
+
+bool LASzipper::return_error(const char* error)
+{
+  char err[256];
+  sprintf(err, "%s (LASzip v%d.%dr%d)", error, LASZIP_VERSION_MAJOR, LASZIP_VERSION_MINOR, LASZIP_VERSION_REVISION);
+  if (error_string) free(error_string);
+  error_string = strdup(err);
+  return false;
+}
+
 LASzipper::LASzipper()
 {
   error_string = 0;
diff -r 93b3dc9ecd89 -r 1765b4d540bd tools/laszippertest.cpp
--- a/tools/laszippertest.cpp	Mon Jun 13 05:56:51 2011 -0700
+++ b/tools/laszippertest.cpp	Mon Jun 13 10:19:15 2011 -0700
@@ -275,7 +275,7 @@
     success = zipper->open(ost->ofile, laszip);
   if (!success)
   {
-    log("ERROR: could not open laszipper with %s\n", ost->m_filename);
+    log("ERROR: could not open laszipper with %s because %s\n", ost->m_filename, zipper->get_error());
     exit(1);
   }
   return zipper;
@@ -298,7 +298,7 @@
     success = unzipper->open(ist->ifile, laszip);
   if (!success)
   {
-    log("ERROR: could not open laszipper with %s\n", ist->m_filename);
+    log("ERROR: could not open laszipper with %s because %s\n", ist->m_filename, unzipper->get_error());
     exit(1);
   }
   return unzipper;
@@ -349,7 +349,7 @@
 
   if (!zipper->close())
   {
-    log("ERROR on zipper->close(): %s\n", zipper->error_string);
+    log("ERROR on zipper->close(): %s\n", zipper->get_error());
   }
   end_time = taketime();
 
@@ -416,7 +416,7 @@
 
   if (!unzipper->close())
   {
-    log("ERROR on unzipper->close(): %s\n", unzipper->error_string);
+    log("ERROR on unzipper->close(): %s\n", unzipper->get_error());
   }
   end_time = taketime();
 
@@ -478,7 +478,7 @@
 
   if (!zipper->close())


More information about the Liblas-commits mailing list