[Liblas-commits] hg: Get rid of external point count management for writers. The...

liblas-commits at liblas.org liblas-commits at liblas.org
Tue Jan 25 14:43:51 EST 2011


details:   http://hg.liblas.orghg/rev/a9e44a39eb45
changeset: 2817:a9e44a39eb45
user:      Howard Butler <hobu.inc at gmail.com>
date:      Tue Jan 25 13:43:46 2011 -0600
description:
Get rid of external point count management for writers.  The writer's header now contains the canonical value(s) for the point count.  This way they don't have to be manually kept in sync for no reason

diffstat:

 include/liblas/detail/writer/base.hpp   |  77 ---------------------------------
 include/liblas/detail/writer/header.hpp |   9 +--
 include/liblas/detail/writer/point.hpp  |   7 +--
 src/CMakeLists.txt                      |   2 -
 src/detail/writer/base.cpp              |  61 --------------------------
 src/detail/writer/header.cpp            |  18 +++----
 src/detail/writer/point.cpp             |   8 +--
 src/detail/writer/writer.cpp            |   9 +--
 src/detail/writer/zipwriter.cpp         |   2 +-
 9 files changed, 21 insertions(+), 172 deletions(-)

diffs (truncated from 356 to 300 lines):

diff -r a1f77b9fe3d6 -r a9e44a39eb45 include/liblas/detail/writer/base.hpp
--- a/include/liblas/detail/writer/base.hpp	Tue Jan 25 12:07:21 2011 -0600
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,77 +0,0 @@
-/******************************************************************************
- * $Id$
- *
- * Project:  libLAS - http://liblas.org - A BSD library for LAS format data.
- * Purpose:  LAS writer implementation for C++ libLAS 
- * Author:   Mateusz Loskot, mateusz at loskot.net
- *
- ******************************************************************************
- * Copyright (c) 2008, Mateusz Loskot
- *
- * All rights reserved.
- * 
- * Redistribution and use in source and binary forms, with or without 
- * modification, are permitted provided that the following 
- * conditions are met:
- * 
- *     * Redistributions of source code must retain the above copyright 
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright 
- *       notice, this list of conditions and the following disclaimer in 
- *       the documentation and/or other materials provided 
- *       with the distribution.
- *     * Neither the name of the Martin Isenburg or Iowa Department 
- *       of Natural Resources nor the names of its contributors may be 
- *       used to endorse or promote products derived from this software 
- *       without specific prior written permission.
- * 
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
- * OF SUCH DAMAGE.
- ****************************************************************************/
-
-#ifndef LIBLAS_DETAIL_WRITER_BASE_HPP_INCLUDED
-#define LIBLAS_DETAIL_WRITER_BASE_HPP_INCLUDED
-
-#include <liblas/version.hpp>
-#include <liblas/detail/fwd.hpp>
-#include <liblas/detail/private_utility.hpp>
-// boost
-#include <boost/cstdint.hpp>
-// std
-#include <iosfwd>
-
-namespace liblas { namespace detail {
-
-class WriterBase
-{
-public:
-
-    WriterBase(std::ostream& ofs, boost::uint32_t& count);
-    ~WriterBase();
- 
-protected:
-    std::ostream& m_ofs;
-    boost::uint32_t& m_pointCount;
-
-        
-private:
-
-    // Blocked copying operations, declared but not defined.
-    WriterBase(WriterBase const& other);
-    WriterBase& operator=(WriterBase const& rhs);
-
-};
-
-}} // namespace liblas::detail
-
-#endif // LIBLAS_DETAIL_WRITER_BASE_HPP_INCLUDED
diff -r a1f77b9fe3d6 -r a9e44a39eb45 include/liblas/detail/writer/header.hpp
--- a/include/liblas/detail/writer/header.hpp	Tue Jan 25 12:07:21 2011 -0600
+++ b/include/liblas/detail/writer/header.hpp	Tue Jan 25 13:43:46 2011 -0600
@@ -45,7 +45,6 @@
 #include <liblas/header.hpp>
 #include <liblas/detail/fwd.hpp>
 #include <liblas/detail/private_utility.hpp>
-#include <liblas/detail/writer/base.hpp>
 // boost
 #include <boost/cstdint.hpp>
 // std
@@ -53,13 +52,12 @@
 
 namespace liblas { namespace detail { namespace writer {
 
-class Header : public WriterBase
+class Header 
 {
     
 public:
-    typedef WriterBase Base;
 
-    Header(std::ostream& ofs, boost::uint32_t& count, liblas::Header const& header );
+    Header(std::ostream& ofs, liblas::Header const& header );
 
     liblas::Header const& GetHeader() const { return m_header; }
     void write();
@@ -69,8 +67,9 @@
     void WriteVLRs();
     void WriteLAS10PadSignature();
     boost::int32_t GetRequiredHeaderSize() const;
+
     
-    
+    std::ostream& m_ofs;    
     liblas::Header m_header;
 };
 
diff -r a1f77b9fe3d6 -r a9e44a39eb45 include/liblas/detail/writer/point.hpp
--- a/include/liblas/detail/writer/point.hpp	Tue Jan 25 12:07:21 2011 -0600
+++ b/include/liblas/detail/writer/point.hpp	Tue Jan 25 13:43:46 2011 -0600
@@ -46,7 +46,6 @@
 #include <liblas/schema.hpp>
 #include <liblas/header.hpp>
 #include <liblas/detail/private_utility.hpp>
-#include <liblas/detail/writer/base.hpp>
 #include <liblas/detail/fwd.hpp>
 // boost
 #include <boost/cstdint.hpp>
@@ -57,13 +56,11 @@
 
 namespace liblas { namespace detail { namespace writer {
 
-class Point : public WriterBase
+class Point 
 {
 public:
     
-    typedef WriterBase Base;
-    
-    Point(std::ostream& ofs, boost::uint32_t& count, HeaderPtr header);
+    Point(std::ostream& ofs, HeaderPtr header);
     virtual ~Point();
 
     // const liblas::Point& GetPoint() const { return m_point; }
diff -r a1f77b9fe3d6 -r a9e44a39eb45 src/CMakeLists.txt
--- a/src/CMakeLists.txt	Tue Jan 25 12:07:21 2011 -0600
+++ b/src/CMakeLists.txt	Tue Jan 25 13:43:46 2011 -0600
@@ -106,7 +106,6 @@
 set(LIBLAS_DETAIL_WRITER_HPP
   ${LIBLAS_HEADERS_DIR}/detail/writer/writer.hpp
   ${LIBLAS_HEADERS_DIR}/detail/writer/zipwriter.hpp
-  ${LIBLAS_HEADERS_DIR}/detail/writer/base.hpp
   ${LIBLAS_HEADERS_DIR}/detail/writer/point.hpp
   ${LIBLAS_HEADERS_DIR}/detail/writer/header.hpp)
 
@@ -145,7 +144,6 @@
   detail/reader/cachedreader.cpp)
 
 set(LIBLAS_DETAIL_WRITER_CPP
-  detail/writer/base.cpp
   detail/writer/header.cpp
   detail/writer/point.cpp
   detail/writer/zipwriter.cpp
diff -r a1f77b9fe3d6 -r a9e44a39eb45 src/detail/writer/base.cpp
--- a/src/detail/writer/base.cpp	Tue Jan 25 12:07:21 2011 -0600
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,61 +0,0 @@
-/******************************************************************************
- * $Id$
- *
- * Project:  libLAS - http://liblas.org - A BSD library for LAS format data.
- * Purpose:  LAS writer implementation for C++ libLAS 
- * Author:   Mateusz Loskot, mateusz at loskot.net
- *
- ******************************************************************************
- * Copyright (c) 2008, Mateusz Loskot
- *
- * All rights reserved.
- * 
- * Redistribution and use in source and binary forms, with or without 
- * modification, are permitted provided that the following 
- * conditions are met:
- * 
- *     * Redistributions of source code must retain the above copyright 
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright 
- *       notice, this list of conditions and the following disclaimer in 
- *       the documentation and/or other materials provided 
- *       with the distribution.
- *     * Neither the name of the Martin Isenburg or Iowa Department 
- *       of Natural Resources nor the names of its contributors may be 
- *       used to endorse or promote products derived from this software 
- *       without specific prior written permission.
- * 
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
- * OF SUCH DAMAGE.
- ****************************************************************************/
-
-#include <liblas/detail/writer/writer.hpp>
-// boost
-#include <boost/cstdint.hpp>
-// std
-#include <ostream>
-
-namespace liblas { namespace detail {
-
-WriterBase::WriterBase(std::ostream& ofs, boost::uint32_t& count)
-    : m_ofs(ofs)
-    , m_pointCount(count)
-{
-}
-
-
-WriterBase::~WriterBase()
-{
-}
-
-}} // namespace liblas::detail
diff -r a1f77b9fe3d6 -r a9e44a39eb45 src/detail/writer/header.cpp
--- a/src/detail/writer/header.cpp	Tue Jan 25 12:07:21 2011 -0600
+++ b/src/detail/writer/header.cpp	Tue Jan 25 13:43:46 2011 -0600
@@ -64,10 +64,10 @@
 
 namespace liblas { namespace detail { namespace writer {
 
-Header::Header(std::ostream& ofs, uint32_t& count, liblas::Header const& header)
-    : Base(ofs, count)
+Header::Header(std::ostream& ofs, liblas::Header const& header)
+    : m_ofs(ofs)
+    , m_header(header)
 {
-    m_header = header;
 }
 
 void Header::write()
@@ -101,11 +101,7 @@
     {
         // We're opened in append mode
         
-        if (m_header.Compressed())
-        {
-            m_pointCount = m_header.GetPointRecordsCount();
-        }
-        else
+        if (!m_header.Compressed())
         {
             ios::off_type points = end - static_cast<ios::off_type>(m_header.GetDataOffset());
             ios::off_type count = points / static_cast<ios::off_type>(m_header.GetDataRecordLength());
@@ -118,8 +114,8 @@
                     <<" offset value?";
                 throw std::runtime_error(oss.str());
             }
-
-            m_pointCount = static_cast<uint32_t>(count);
+            
+            m_header.SetPointRecordsCount(count);
         }
 
         // Position to the beginning of the file to start writing the header
@@ -311,7 +307,7 @@
     }           
     // If we already have points, we're going to put it at the end of the file.  
     // If we don't have any points,  we're going to leave it where it is.
-    if (m_pointCount != 0)
+    if (m_header.GetPointRecordsCount() != 0)
     {
         m_ofs.seekp(0, std::ios::end);
     }
diff -r a1f77b9fe3d6 -r a9e44a39eb45 src/detail/writer/point.cpp
--- a/src/detail/writer/point.cpp	Tue Jan 25 12:07:21 2011 -0600
+++ b/src/detail/writer/point.cpp	Tue Jan 25 13:43:46 2011 -0600
@@ -55,9 +55,8 @@
 
 namespace liblas { namespace detail { namespace writer {
 
-Point::Point(std::ostream& ofs, uint32_t& count, HeaderPtr header)
-    : Base(ofs, count)
-    , m_ofs(ofs)
+Point::Point(std::ostream& ofs, HeaderPtr header)
+    : m_ofs(ofs)
     , m_header(header)
     , m_format(header->GetSchema())
 {
@@ -92,8 +91,7 @@
     std::vector<boost::uint8_t> const& data = point.GetData();    
     detail::write_n(m_ofs, data.front(), m_header->GetDataRecordLength());
 
-    m_pointCount++;


More information about the Liblas-commits mailing list