[Liblas-commits] hg: 2 new changesets

liblas-commits at liblas.org liblas-commits at liblas.org
Thu Jul 15 15:49:31 EDT 2010


changeset a863026fe6f9 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=a863026fe6f9
summary: fix #185 iterating multiple times over the same file with CachedReaderImpl

changeset ed85f7afc4a9 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=ed85f7afc4a9
summary: merge

diffstat:

 src/detail/reader/reader.cpp          |  18 +++++++++++-------
 test/unit/common.hpp                  |  12 +++++++-----
 test/unit/lasreader_iterator_test.cpp |  22 +++++++++++++---------
 3 files changed, 31 insertions(+), 21 deletions(-)

diffs (132 lines):

diff -r e46ea45fc0cd -r ed85f7afc4a9 src/detail/reader/reader.cpp
--- a/src/detail/reader/reader.cpp	Thu Jul 15 10:35:21 2010 -0500
+++ b/src/detail/reader/reader.cpp	Thu Jul 15 14:49:18 2010 -0500
@@ -197,13 +197,13 @@
 
 void CachedReaderImpl::CacheData(liblas::uint32_t position, const liblas::Header& header) 
 {
-        int32_t old_cache_start_position = m_cache_start_position;
+        std::vector<uint8_t>::size_type old_cache_start_position = m_cache_start_position;
         m_cache_start_position = position;
 
     std::vector<uint8_t>::size_type header_size = static_cast<std::vector<uint8_t>::size_type>(header.GetPointRecordsCount());
     std::vector<uint8_t>::size_type left_to_cache = std::min(m_cache_size, header_size - m_cache_start_position);
 
-    std::vector<uint8_t>::size_type to_mark = std::max(m_cache_size, left_to_cache);
+    std::vector<uint8_t>::size_type to_mark = std::min(m_cache_size, header_size - old_cache_start_position);
         for (uint32_t i = 0; i < to_mark; ++i) {
             m_mask[old_cache_start_position + i] = 0;
         }
@@ -317,15 +317,19 @@
 void CachedReaderImpl::Reset(liblas::Header const& header)
 {
     
-    if (m_mask.size() > 0) {
+    if (!m_mask.empty()) {
 
-    std::vector<uint8_t>::size_type header_size = static_cast<std::vector<uint8_t>::size_type>(header.GetPointRecordsCount());
-    std::vector<uint8_t>::size_type left_to_cache = std::min(m_cache_size, header_size - m_cache_start_position);
+        typedef std::vector<uint8_t>::size_type size_type;
+        size_type header_size = static_cast<std::vector<uint8_t>::size_type>(header.GetPointRecordsCount());
+        size_type left_to_cache = std::min(m_cache_size, header_size - m_cache_start_position);
+        size_type to_mark = std::max(m_cache_size, left_to_cache);
 
-    std::vector<uint8_t>::size_type to_mark = std::max(m_cache_size, left_to_cache);
         for (uint32_t i = 0; i < to_mark; ++i) {
 
-            m_mask[m_cache_start_position + i] = 0;
+            size_type const mark_pos = m_cache_start_position + i;
+            assert(mark_pos < m_mask.size());
+
+            m_mask[mark_pos] = 0;
         }
 
         m_cache_start_position = 0;
diff -r e46ea45fc0cd -r ed85f7afc4a9 test/unit/common.hpp
--- a/test/unit/common.hpp	Thu Jul 15 10:35:21 2010 -0500
+++ b/test/unit/common.hpp	Thu Jul 15 14:49:18 2010 -0500
@@ -37,10 +37,11 @@
 // Functor to calculate bounding box of a set of points
 struct bbox_calculator
 {
-    // bbox object will store operation result
-    bbox_calculator(liblas::detail::Extents<double>& bbox)
-        : empty(true), bbox(bbox)
-    {}
+    typedef liblas::detail::Extents<double> result_type;
+
+    bbox_calculator() : empty(true) {}
+
+    result_type get_result() const { return bbox; }    
 
     void operator()(liblas::Point const& p)
     {
@@ -62,8 +63,9 @@
         bbox.max.z = std::max(bbox.max.z, p.GetZ());
     }
 
+
     bool empty;
-    liblas::detail::Extents<double>& bbox;
+    liblas::detail::Extents<double> bbox;
 };
 
 // Common test procedure for default constructed point data.
diff -r e46ea45fc0cd -r ed85f7afc4a9 test/unit/lasreader_iterator_test.cpp
--- a/test/unit/lasreader_iterator_test.cpp	Thu Jul 15 10:35:21 2010 -0500
+++ b/test/unit/lasreader_iterator_test.cpp	Thu Jul 15 14:49:18 2010 -0500
@@ -204,8 +204,9 @@
         lasreader_iterator it(reader_); // move to 1st point
         lasreader_iterator end;
 
-        lasreader_iterator::difference_type const d = std::distance(it, end);
-        ensure_equals(d, cnt);
+        typedef lasreader_iterator::difference_type difference_type;
+        difference_type const d = std::distance(it, end);
+        ensure_equals(d, static_cast<difference_type>(cnt));
     }
 
     // Test std::distance operation
@@ -213,13 +214,15 @@
     template<>
     void to::test<15>()
     {
-        std::size_t a = std::distance(lasreader_iterator(reader_), lasreader_iterator());
+        typedef lasreader_iterator::difference_type difference_type;
+        
+        difference_type a = std::distance(lasreader_iterator(reader_), lasreader_iterator());
 
         // Reader state is set to "past-the-end-of-file"
         // So, reset is needed
         reader_.Reset();
 
-        std::size_t b = std::distance(lasreader_iterator(reader_), lasreader_iterator());
+        difference_type b = std::distance(lasreader_iterator(reader_), lasreader_iterator());
 
         ensure_equals(a, b);
     }
@@ -284,8 +287,9 @@
         lasreader_iterator end;
 
         // Count records equal to given point object
-        lasreader_iterator::difference_type const expected = 1;
-        lasreader_iterator::difference_type n = std::count(it, end, pt);
+        typedef lasreader_iterator::difference_type difference_type;
+        difference_type const expected = 1;
+        difference_type n = std::count(it, end, pt);
         ensure_equals(n, expected);
     }
 
@@ -382,9 +386,9 @@
                        point_t(h.GetMaxX(), h.GetMaxY(), h.GetMaxZ()));
 
         // Accumulate points extents to common bounding box
-        bbox_t bbox;
-        std::for_each(it, end, bbox_calculator(bbox));
+        bbox_calculator calculator;
+        std::for_each(it, end, calculator);
 
-        ensure(lasbbox == bbox);
+        ensure(lasbbox == calculator.get_result());
     }
 }


More information about the Liblas-commits mailing list