[Liblas-commits] hg: Return references instead of shared_ptr for ReadNextPoint

liblas-commits at liblas.org liblas-commits at liblas.org
Mon Aug 16 16:54:06 EDT 2010


changeset 39b49201c1ea in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=39b49201c1ea
summary: Return references instead of shared_ptr for ReadNextPoint

diffstat:

 include/liblas/detail/reader/cachedreader.hpp |   6 +++---
 include/liblas/detail/reader/reader.hpp       |   2 +-
 include/liblas/liblas.hpp                     |   2 +-
 src/detail/reader/cachedreader.cpp            |  20 +++++++-------------
 src/detail/reader/reader.cpp                  |  14 ++++++++------
 src/lasreader.cpp                             |   9 +++++----
 6 files changed, 25 insertions(+), 28 deletions(-)

diffs (178 lines):

diff -r 951cd16484b9 -r 39b49201c1ea include/liblas/detail/reader/cachedreader.hpp
--- a/include/liblas/detail/reader/cachedreader.hpp	Mon Aug 16 14:21:42 2010 -0500
+++ b/include/liblas/detail/reader/cachedreader.hpp	Mon Aug 16 15:53:59 2010 -0500
@@ -63,7 +63,7 @@
     // ~CachedReaderImpl();
 
     HeaderPtr ReadHeader();
-    PointPtr ReadNextPoint(HeaderPtr header);
+    liblas::Point const& ReadNextPoint(HeaderPtr header);
     liblas::Point const& ReadPointAt(std::size_t n, HeaderPtr header);
     // void SetOutputSRS(const SpatialReference& srs, const liblas::Header& header);
 
@@ -77,7 +77,7 @@
     // Blocked copying operations, declared but not defined.
     CachedReaderImpl(CachedReaderImpl const& other);
     CachedReaderImpl& operator=(CachedReaderImpl const& rhs);
-    PointPtr ReadCachedPoint(boost::uint32_t position, HeaderPtr header);
+    liblas::Point const& ReadCachedPoint(boost::uint32_t position, HeaderPtr header);
     
     void CacheData(boost::uint32_t position, HeaderPtr header);
 
@@ -87,7 +87,7 @@
     cache_mask_type::size_type m_cache_start_position;
     cache_mask_type::size_type m_cache_read_position;
 
-    typedef std::vector<PointPtr> cache_type;
+    typedef std::vector<liblas::Point> cache_type;
     cache_type m_cache;
 };
 
diff -r 951cd16484b9 -r 39b49201c1ea include/liblas/detail/reader/reader.hpp
--- a/include/liblas/detail/reader/reader.hpp	Mon Aug 16 14:21:42 2010 -0500
+++ b/include/liblas/detail/reader/reader.hpp	Mon Aug 16 15:53:59 2010 -0500
@@ -65,7 +65,7 @@
     ~ReaderImpl();
 
     HeaderPtr ReadHeader();
-    PointPtr ReadNextPoint(HeaderPtr header);
+    liblas::Point const& ReadNextPoint(HeaderPtr header);
     liblas::Point const& ReadPointAt(std::size_t n, HeaderPtr header);
     void Seek(std::size_t n, HeaderPtr header);
     
diff -r 951cd16484b9 -r 39b49201c1ea include/liblas/liblas.hpp
--- a/include/liblas/liblas.hpp	Mon Aug 16 14:21:42 2010 -0500
+++ b/include/liblas/liblas.hpp	Mon Aug 16 15:53:59 2010 -0500
@@ -172,7 +172,7 @@
 public:
 
     virtual HeaderPtr ReadHeader() = 0;
-    virtual PointPtr ReadNextPoint(HeaderPtr header) = 0;
+    virtual Point const& ReadNextPoint(HeaderPtr header) = 0;
     virtual Point const& ReadPointAt(std::size_t n, HeaderPtr header) = 0;
     virtual void Seek(std::size_t n, HeaderPtr header) = 0;
     
diff -r 951cd16484b9 -r 39b49201c1ea src/detail/reader/cachedreader.cpp
--- a/src/detail/reader/cachedreader.cpp	Mon Aug 16 14:21:42 2010 -0500
+++ b/src/detail/reader/cachedreader.cpp	Mon Aug 16 15:53:59 2010 -0500
@@ -127,7 +127,7 @@
     }
 }
 
-PointPtr CachedReaderImpl::ReadCachedPoint(boost::uint32_t position, HeaderPtr header) {
+liblas::Point const& CachedReaderImpl::ReadCachedPoint(boost::uint32_t position, HeaderPtr header) {
     
     int32_t cache_position = position - m_cache_start_position ;
 
@@ -179,16 +179,17 @@
     }
 }
 
-PointPtr CachedReaderImpl::ReadNextPoint(HeaderPtr header)
+liblas::Point const& CachedReaderImpl::ReadNextPoint(HeaderPtr header)
 {
     if (m_cache_read_position == m_size )
     {
         throw std::out_of_range("file has no more points to read, end of file reached");
     }
     
-    PointPtr ptr = ReadCachedPoint(m_cache_read_position, header);
+    // PointPtr ptr = ReadCachedPoint(m_cache_read_position, header);
+    liblas::Point const& point = ReadCachedPoint(m_cache_read_position, header);
     ++m_cache_read_position;
-    return ptr;
+    return point;
 }
 
 liblas::Point const& CachedReaderImpl::ReadPointAt(std::size_t n, HeaderPtr header)
@@ -206,16 +207,9 @@
         throw std::runtime_error(out);
     }
 
-    PointPtr ptr = ReadCachedPoint(n, header);
-    if (ptr.get() == 0 ) {
-        std::ostringstream output;
-        output << "unable to fetch point from cache at position : " 
-               << n;
-        std::string out(output.str());
-        throw std::runtime_error(out);
-    }
+    liblas::Point const& p = ReadCachedPoint(n, header);
     m_cache_read_position = n;
-    return *ptr;
+    return p;
 }
 
 void CachedReaderImpl::Reset(HeaderPtr header)
diff -r 951cd16484b9 -r 39b49201c1ea src/detail/reader/reader.cpp
--- a/src/detail/reader/reader.cpp	Mon Aug 16 14:21:42 2010 -0500
+++ b/src/detail/reader/reader.cpp	Mon Aug 16 15:53:59 2010 -0500
@@ -104,7 +104,7 @@
     return h;
 }
 
-PointPtr ReaderImpl::ReadNextPoint(HeaderPtr header)
+liblas::Point const& ReaderImpl::ReadNextPoint(HeaderPtr header)
 {
     if (0 == m_current)
     {
@@ -117,12 +117,14 @@
     {
         m_point_reader->read();
         
-        PointPtr ptr = PointPtr(new liblas::Point(m_point_reader->GetPoint()));
-        if (ptr.get() == 0) {
-            throw std::runtime_error("Unable to fetch point from reader");
-        }
+        // PointPtr ptr = PointPtr(new liblas::Point(m_point_reader->GetPoint()));
+        // if (ptr.get() == 0) {
+        //     throw std::runtime_error("Unable to fetch point from reader");
+        // }
+        
         ++m_current;
-        return ptr;
+        // return ptr;
+        return m_point_reader->GetPoint();
 
     } else if (m_current == m_size ){
         throw std::out_of_range("file has no more points to read, end of file reached");
diff -r 951cd16484b9 -r 39b49201c1ea src/lasreader.cpp
--- a/src/lasreader.cpp	Mon Aug 16 14:21:42 2010 -0500
+++ b/src/lasreader.cpp	Mon Aug 16 15:53:59 2010 -0500
@@ -58,7 +58,7 @@
 {
 
 Reader::Reader(std::istream& ifs) :
-    m_pimpl(new detail::CachedReaderImpl(ifs,3)),
+    m_pimpl(new detail::ReaderImpl(ifs)),
     m_header(HeaderPtr()),
     m_point(0),
     m_empty_point(new Point()),
@@ -96,7 +96,7 @@
 }
 
 Reader::Reader(std::istream& ifs, Header& header) :
-    m_pimpl(new detail::CachedReaderImpl(ifs,20)),
+    m_pimpl(new detail::ReaderImpl(ifs)),
     m_header(HeaderPtr( )),    
     m_point(0),
     m_empty_point(new Point()),
@@ -148,7 +148,8 @@
     }
     
     try {
-        m_point = m_pimpl->ReadNextPoint(m_header).get();
+        // m_point = m_pimpl->ReadNextPoint(m_header).get();
+        m_point = const_cast<Point*>(&(m_pimpl->ReadNextPoint(m_header)));
         if (bHaveFilters) {
         if (m_filters->size() != 0) {
             // We have filters, filter this point.  All filters must 
@@ -264,7 +265,7 @@
         custom_header = *m_header;
     }
 
-    m_header = HeaderPtr(m_pimpl->ReadHeader());
+    m_header = m_pimpl->ReadHeader();
 
         // throw std::runtime_error("public header block reading failure");
 


More information about the Liblas-commits mailing list