[Liblas-commits] hg: put a boost::scoped_ptr<LASzip> to manage VLR
and point size...
liblas-commits at liblas.org
liblas-commits at liblas.org
Fri Jun 24 16:10:47 EDT 2011
details: http://hg.liblas.orghg/rev/f2f79555e12b
changeset: 3014:f2f79555e12b
user: Howard Butler <hobu.inc at gmail.com>
date: Fri Jun 24 14:57:25 2011 -0500
description:
put a boost::scoped_ptr<LASzip> to manage VLR and point size stuff in ZipPoint
Subject: hg: use a boost::scoped_ptr instead of a naked array for exception safety for m_lz_point_data
details: http://hg.liblas.orghg/rev/e9bf37763cf5
changeset: 3015:e9bf37763cf5
user: Howard Butler <hobu.inc at gmail.com>
date: Fri Jun 24 15:10:33 2011 -0500
description:
use a boost::scoped_ptr instead of a naked array for exception safety for m_lz_point_data
diffstat:
include/liblas/detail/zippoint.hpp | 11 +-
src/detail/reader/zipreader.cpp | 2 +-
src/detail/zippoint.cpp | 164 +++++++++++++-----------------------
3 files changed, 70 insertions(+), 107 deletions(-)
diffs (255 lines):
diff -r 6013e0dcb9cc -r e9bf37763cf5 include/liblas/detail/zippoint.hpp
--- a/include/liblas/detail/zippoint.hpp Fri Jun 24 10:53:42 2011 -0500
+++ b/include/liblas/detail/zippoint.hpp Fri Jun 24 15:10:33 2011 -0500
@@ -49,10 +49,13 @@
// boost
#include <boost/cstdint.hpp>
#include <boost/shared_ptr.hpp>
+#include <boost/scoped_ptr.hpp>
+#include <boost/scoped_array.hpp>
// liblaszip
class LASzipper;
class LASitem;
+class LASzip;
namespace liblas { namespace detail {
@@ -72,7 +75,7 @@
bool IsZipVLR(const VariableRecord& vlr) const;
private:
- void ConstructItems(PointFormatName);
+ void ConstructItems(unsigned char, unsigned short);
public: // for now
// LASzip::pack() allocates/sets vlr_data and vlr_num for us, and deletes it for us ["his"]
@@ -82,10 +85,10 @@
int our_vlr_num;
unsigned char* our_vlr_data;
- unsigned int m_num_items;
- LASitem* m_items;
+ boost::scoped_ptr<LASzip> m_zip;
+
unsigned char** m_lz_point;
- unsigned char* m_lz_point_data;
+ boost::scoped_array<boost::uint8_t> m_lz_point_data;
unsigned int m_lz_point_size;
};
diff -r 6013e0dcb9cc -r e9bf37763cf5 src/detail/reader/zipreader.cpp
--- a/src/detail/reader/zipreader.cpp Fri Jun 24 10:53:42 2011 -0500
+++ b/src/detail/reader/zipreader.cpp Fri Jun 24 15:10:33 2011 -0500
@@ -231,7 +231,7 @@
unsigned int size = m_zipPoint->m_lz_point_size;
assert(size == data.size());
- unsigned char* p = m_zipPoint->m_lz_point_data;
+ unsigned char* p = m_zipPoint->m_lz_point_data.get();
data.assign(p, p+size);
++m_current;
diff -r 6013e0dcb9cc -r e9bf37763cf5 src/detail/zippoint.cpp
--- a/src/detail/zippoint.cpp Fri Jun 24 10:53:42 2011 -0500
+++ b/src/detail/zippoint.cpp Fri Jun 24 15:10:33 2011 -0500
@@ -66,13 +66,13 @@
, his_vlr_data(0)
, our_vlr_num(0)
, our_vlr_data(0)
- , m_num_items(0)
- , m_items(NULL)
, m_lz_point(NULL)
, m_lz_point_data(NULL)
, m_lz_point_size(0)
{
- ConstructItems(format);
+
+ boost::scoped_ptr<LASzip> s(new LASzip());
+ m_zip.swap(s);
const VariableRecord* vlr = NULL;
for (unsigned int i=0; i<vlrs.size(); i++)
@@ -94,100 +94,6 @@
}
}
- return;
-}
-
-ZipPoint::~ZipPoint()
-{
- m_num_items = 0;
- delete[] m_items;
- m_items = NULL;
-
- delete[] m_lz_point;
- delete[] m_lz_point_data;
-
- delete[] our_vlr_data;
-
- return;
-}
-
-
-void ZipPoint::ConstructItems(PointFormatName format)
-{
- switch (format)
- {
- case ePointFormat0:
- m_num_items = 1;
- m_items = new LASitem[1];
- m_items[0].type = LASitem::POINT10;
- m_items[0].size = 20;
- break;
-
- case ePointFormat1:
- m_num_items = 2;
- m_items = new LASitem[2];
- m_items[0].type = LASitem::POINT10;
- m_items[0].size = 20;
- m_items[1].type = LASitem::GPSTIME11;
- m_items[1].size = 8;
- break;
-
- case ePointFormat2:
- m_num_items = 2;
- m_items = new LASitem[2];
- m_items[0].type = LASitem::POINT10;
- m_items[0].size = 20;
- m_items[1].type = LASitem::RGB12;
- m_items[1].size = 6;
- break;
-
- case ePointFormat3:
- m_num_items = 3;
- m_items = new LASitem[3];
- m_items[0].type = LASitem::POINT10;
- m_items[0].size = 20;
- m_items[1].type = LASitem::GPSTIME11;
- m_items[1].size = 8;
- m_items[2].type = LASitem::RGB12;
- m_items[2].size = 6;
- break;
-
- default:
- throw liblas_error("Bad point format in header");
- }
-
- // construct the object that will hold a laszip point
-
- // compute the point size
- m_lz_point_size = 0;
- for (unsigned int i = 0; i < m_num_items; i++)
- m_lz_point_size += m_items[i].size;
-
- // create the point data
- unsigned int point_offset = 0;
- m_lz_point = new unsigned char*[m_num_items];
- m_lz_point_data = new unsigned char[m_lz_point_size];
- for (unsigned i = 0; i < m_num_items; i++)
- {
- m_lz_point[i] = &(m_lz_point_data[point_offset]);
- point_offset += m_items[i].size;
- }
-
- return;
-}
-
-
-void ZipPoint::ConstructVLR(VariableRecord& v, PointFormatName format) const
-{
- boost::uint16_t record_length_after_header = (boost::uint16_t)(34+6*m_num_items);
-
- // set the header
- v.SetReserved(0xAABB);
- v.SetUserId(laszip_userid);
- v.SetRecordId(laszip_recordid);
- v.SetRecordLength(record_length_after_header);
- v.SetDescription(laszip_description);
-
unsigned char pointFormat = 0;
unsigned short pointSize = 0;
switch (format)
@@ -212,14 +118,62 @@
throw liblas_error("point format not supported by laszip");
}
- LASzip laszip;
- laszip.setup(pointFormat, pointSize);
+ m_zip->setup(pointFormat, pointSize);
- LASzipper zipper;
+ ConstructItems(pointFormat, pointSize);
+
+
+ return;
+}
+
+ZipPoint::~ZipPoint()
+{
+
+ delete[] m_lz_point;
+ delete[] our_vlr_data;
+
+ return;
+}
+
+
+void ZipPoint::ConstructItems(unsigned char pointFormat, unsigned short size)
+{
+ if (!m_zip->setup(pointFormat, size))
+ {
+ std::ostringstream oss;
+ oss << "Error setting up LASzip for format " << pointFormat <<": " << m_zip->get_error();
+ throw liblas_error(oss.str());
+ }
+
+ // construct the object that will hold a laszip point
+
+ // compute the point size
+ m_lz_point_size = 0;
+ for (unsigned int i = 0; i < m_zip->num_items; i++)
+ m_lz_point_size += m_zip->items[i].size;
+
+ // create the point data
+ unsigned int point_offset = 0;
+ m_lz_point = new unsigned char*[m_zip->num_items];
+ boost::scoped_array<boost::uint8_t> d( new boost::uint8_t[ m_lz_point_size ] );
+ m_lz_point_data.swap(d);
+ for (unsigned i = 0; i < m_zip->num_items; i++)
+ {
+ m_lz_point[i] = &(m_lz_point_data[point_offset]);
+ point_offset += m_zip->items[i].size;
+ }
+
+ return;
+}
+
+
+void ZipPoint::ConstructVLR(VariableRecord& v, PointFormatName format) const
+{
+
unsigned char* data;
int num;
- laszip.pack(data, num);
+ m_zip->pack(data, num);
// Ick.
std::vector<boost::uint8_t> vdata;
@@ -227,7 +181,13 @@
{
vdata.push_back(data[i]);
}
-
+
+ // set the header
+ v.SetReserved(0xAABB);
+ v.SetUserId(laszip_userid);
+ v.SetRecordId(laszip_recordid);
+ v.SetRecordLength(num);
+ v.SetDescription(laszip_description);
v.SetData(vdata);
v.SetRecordLength((boost::uint16_t)num);
More information about the Liblas-commits
mailing list