[Liblas-commits] hg: re-engineer liblas::Writer to be copyable and delegate all o...

liblas-commits at liblas.org liblas-commits at liblas.org
Wed Dec 15 09:38:32 EST 2010


changeset bc334b3ab8bb in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=bc334b3ab8bb
summary: re-engineer liblas::Writer to be copyable and delegate all operations to its PIMPL

diffstat:

 include/liblas/detail/writer/writer.hpp |  14 +++++++++---
 include/liblas/laswriter.hpp            |   1 -
 include/liblas/liblas.hpp               |  10 ++++++--
 src/detail/writer/writer.cpp            |  35 ++++++++++++++++++++------------
 src/laswriter.cpp                       |  17 +++++++--------
 test/unit/laswriter_test.cpp            |   4 +++
 6 files changed, 51 insertions(+), 30 deletions(-)

diffs (189 lines):

diff -r 4ddf274a6814 -r bc334b3ab8bb include/liblas/detail/writer/writer.hpp
--- a/include/liblas/detail/writer/writer.hpp	Tue Dec 14 15:09:52 2010 -0600
+++ b/include/liblas/detail/writer/writer.hpp	Wed Dec 15 08:38:25 2010 -0600
@@ -62,10 +62,14 @@
     WriterImpl(std::ostream& ofs);
     ~WriterImpl();
     LASVersion GetVersion() const;
-    liblas::Header const& WriteHeader(liblas::Header const& header);
-    void UpdateHeader(liblas::Header const& header);
-    void WritePoint(liblas::Point const& record, HeaderPtr header);
+    void WritePoint(liblas::Point const& record);
 
+    liblas::Header& GetHeader() const;
+    void WriteHeader();
+
+    void UpdatePointCount(boost::uint32_t count);
+    void SetHeader(liblas::Header const& header);
+    
     void SetFilters(std::vector<liblas::FilterPtr> const& filters);
     void SetTransforms(std::vector<liblas::TransformPtr> const& transforms);
 
@@ -77,7 +81,9 @@
     HeaderWriterPtr m_header_writer;
 
     std::vector<liblas::FilterPtr> m_filters;
-    std::vector<liblas::TransformPtr> m_transforms;    
+    std::vector<liblas::TransformPtr> m_transforms;
+
+    HeaderPtr m_header;
 
 private:
 
diff -r 4ddf274a6814 -r bc334b3ab8bb include/liblas/laswriter.hpp
--- a/include/liblas/laswriter.hpp	Tue Dec 14 15:09:52 2010 -0600
+++ b/include/liblas/laswriter.hpp	Wed Dec 15 08:38:25 2010 -0600
@@ -108,7 +108,6 @@
 
     const std::auto_ptr<WriterI> m_pimpl;
 
-    HeaderPtr m_header;
 };
 
 } // namespace liblas
diff -r 4ddf274a6814 -r bc334b3ab8bb include/liblas/liblas.hpp
--- a/include/liblas/liblas.hpp	Tue Dec 14 15:09:52 2010 -0600
+++ b/include/liblas/liblas.hpp	Wed Dec 15 08:38:25 2010 -0600
@@ -142,9 +142,13 @@
 {
 public:
 
-    virtual Header const& WriteHeader(Header const& header) = 0;
-    virtual void UpdateHeader(Header const& header) = 0;
-    virtual void WritePoint(const Point& point, HeaderPtr header) = 0;
+
+    virtual liblas::Header& GetHeader() const = 0;
+    virtual void WriteHeader() = 0;
+    virtual void SetHeader(liblas::Header const& header) = 0;
+    
+    virtual void UpdatePointCount(boost::uint32_t count) = 0;
+    virtual void WritePoint(const Point& point) = 0;
 
     virtual void SetFilters(std::vector<liblas::FilterPtr> const& filters) = 0;
     virtual void SetTransforms(std::vector<liblas::TransformPtr> const& transforms) = 0;
diff -r 4ddf274a6814 -r bc334b3ab8bb src/detail/writer/writer.cpp
--- a/src/detail/writer/writer.cpp	Tue Dec 14 15:09:52 2010 -0600
+++ b/src/detail/writer/writer.cpp	Wed Dec 15 08:38:25 2010 -0600
@@ -64,29 +64,29 @@
 }
 
 
-liblas::Header const&  WriterImpl::WriteHeader(liblas::Header const& header)
+void WriterImpl::WriteHeader()
 {
-    m_header_writer = HeaderWriterPtr(new writer::Header(m_ofs,m_pointCount, header) );
+    m_header_writer = HeaderWriterPtr(new writer::Header(m_ofs,m_pointCount, *m_header) );
     
     m_header_writer->write();
-    return m_header_writer->GetHeader();
 }
 
-void WriterImpl::UpdateHeader(liblas::Header const& header)
+void WriterImpl::UpdatePointCount(boost::uint32_t count)
 {
-    if (m_pointCount != header.GetPointRecordsCount())
-    {
-        // Skip to first byte of number of point records data member
-        std::streamsize const dataPos = 107; 
-        m_ofs.seekp(dataPos, std::ios::beg);
-        detail::write_n(m_ofs, m_pointCount , sizeof(m_pointCount));
-    }
+    boost::uint32_t out = m_pointCount;
+    
+    if ( count != 0 ) { out = count; }
+    
+    // Skip to first byte of number of point records data member
+    std::streamsize const dataPos = 107; 
+    m_ofs.seekp(dataPos, std::ios::beg);
+    detail::write_n(m_ofs, out , sizeof(out));
 }
 
-void WriterImpl::WritePoint(liblas::Point const& point, HeaderPtr header)
+void WriterImpl::WritePoint(liblas::Point const& point)
 {
     if (m_point_writer == 0) {
-        m_point_writer = PointWriterPtr(new writer::Point(m_ofs, m_pointCount, header));
+        m_point_writer = PointWriterPtr(new writer::Point(m_ofs, m_pointCount, m_header));
     } 
     m_point_writer->write(point);
 
@@ -107,6 +107,15 @@
     m_transforms = transforms;
 }
 
+liblas::Header& WriterImpl::GetHeader() const
+{
+    *m_header;
+}
+void WriterImpl::SetHeader(liblas::Header const& header)
+{
+    m_header = HeaderPtr(new liblas::Header(header));
+}
+
 WriterImpl* WriterFactory::Create(std::ostream& ofs)
 {
     if (!ofs)
diff -r 4ddf274a6814 -r bc334b3ab8bb src/laswriter.cpp
--- a/src/laswriter.cpp	Tue Dec 14 15:09:52 2010 -0600
+++ b/src/laswriter.cpp	Wed Dec 15 08:38:25 2010 -0600
@@ -54,29 +54,28 @@
 {
 
 Writer::Writer(std::ostream& ofs, Header const& header) :
-    m_pimpl(detail::WriterFactory::Create(ofs)), m_header(HeaderPtr(new liblas::Header(header))) 
+    m_pimpl(detail::WriterFactory::Create(ofs))
 
 {
-    liblas::Header const& h = m_pimpl->WriteHeader(*m_header);
-    m_header = HeaderPtr(new liblas::Header(h));
-
+    m_pimpl->SetHeader(header);
+    m_pimpl->WriteHeader();
 }
 
 Writer::~Writer()
 {
     assert(0 != m_pimpl.get());
 
-    m_pimpl->UpdateHeader(*m_header);
+    m_pimpl->UpdatePointCount(0);
 }
 
 Header const& Writer::GetHeader() const
 {
-    return *m_header;
+    return m_pimpl->GetHeader();
 }
 
 bool Writer::WritePoint(Point const& point)
 {
-    m_pimpl->WritePoint(point, m_header);
+    m_pimpl->WritePoint(point);
     return true;
 }
 
@@ -84,8 +83,8 @@
 {
     // The writer may update our header as part of its 
     // writing process (change VLRs for SRS's, for instance).
-    liblas::Header const& h = m_pimpl->WriteHeader(header);
-    m_header = HeaderPtr(new liblas::Header(h));
+    m_pimpl->SetHeader(header);
+    m_pimpl->WriteHeader();
 }
 
 void Writer::SetTransforms(std::vector<liblas::TransformPtr> const& transforms)
diff -r 4ddf274a6814 -r bc334b3ab8bb test/unit/laswriter_test.cpp
--- a/test/unit/laswriter_test.cpp	Tue Dec 14 15:09:52 2010 -0600
+++ b/test/unit/laswriter_test.cpp	Wed Dec 15 08:38:25 2010 -0600
@@ -214,6 +214,10 @@
             writer.WriteHeader(header);
             liblas::Header const& written_header = writer.GetHeader();
             ensure_equals("written_header fileSource id", written_header.GetFileSourceId(), 65535);
+            ensure_equals("written_header SystemId", written_header.GetSystemId(), "Unit Test libLAS System");
+            ensure_equals("written_header SoftwareId", written_header.GetSoftwareId(), "Unit Test libLAS Software");
+            ensure_equals("written_header CreationDOY", written_header.GetCreationDOY(), 100);
+            ensure_equals("written_header CreationYear", written_header.GetCreationYear(), 2008);
 
         }
 


More information about the Liblas-commits mailing list