[Liblas-commits] hg: 2 new changesets

liblas-commits at liblas.org liblas-commits at liblas.org
Tue Oct 5 19:15:04 EDT 2010


changeset 2f8c2ca47bb7 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=2f8c2ca47bb7
summary: Renamed detail/utility.hpp to detail/private_utility.hpp. Return Sizes_array by reference to const instead by value. Initialise a few values on construction instead of declare then initialise. Tidy up.

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

diffstat:

 apps/las2oci.cpp                          |   12 +-
 apps/ts2las.hpp                           |    2 +-
 include/liblas/detail/private_utility.hpp |  495 ++++++++++++++++++++++++++++++
 include/liblas/detail/utility.hpp         |  495 ------------------------------
 include/liblas/detail/writer/base.hpp     |    2 +-
 include/liblas/detail/writer/header.hpp   |    2 +-
 include/liblas/detail/writer/point.hpp    |    2 +-
 include/liblas/guid.hpp                   |    2 +-
 include/liblas/lasbounds.hpp              |    2 +-
 include/liblas/laspoint.hpp               |    2 +-
 include/liblas/lasschema.hpp              |   14 +-
 include/liblas/lasspatialreference.hpp    |    2 +-
 include/liblas/lasvariablerecord.hpp      |    2 +-
 include/liblas/liblas.hpp                 |    2 +-
 src/detail/reader/cachedreader.cpp        |    6 +-
 src/detail/reader/header.cpp              |    4 +-
 src/detail/reader/point.cpp               |    4 +-
 src/detail/reader/reader.cpp              |    4 +-
 src/detail/utility.cpp                    |    2 +-
 src/detail/writer/header.cpp              |    4 +-
 src/detail/writer/point.cpp               |    6 +-
 src/detail/writer/writer.cpp              |    9 +-
 src/lasclassification.cpp                 |    2 +-
 src/lasheader.cpp                         |    4 +-
 src/laspoint.cpp                          |   56 +--
 src/lasschema.cpp                         |   15 +-
 src/lasspatialreference.cpp               |    2 +-
 test/unit/lasreader_iterator_test.cpp     |    2 +-
 28 files changed, 556 insertions(+), 600 deletions(-)

diffs (truncated from 1664 to 300 lines):

diff -r b1f8f5367a6b -r 5898e2ec7f55 apps/las2oci.cpp
--- a/apps/las2oci.cpp	Tue Oct 05 23:01:58 2010 +0100
+++ b/apps/las2oci.cpp	Wed Oct 06 00:14:49 2010 +0100
@@ -1,13 +1,8 @@
 #include "las2oci.hpp"
 
-
-#include <liblas/detail/utility.hpp>
+#include <liblas/detail/private_utility.hpp>
 #include "laskernel.hpp"
 
-
-
-
-
 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
 
 namespace po = boost::program_options;
@@ -15,11 +10,6 @@
 using namespace liblas;
 using namespace std;
 
-
-
-
-
-
 void OCIGDALDebugErrorHandler(CPLErr eErrClass, int err_no, const char *msg)
 {
     ostringstream oss;
diff -r b1f8f5367a6b -r 5898e2ec7f55 apps/ts2las.hpp
--- a/apps/ts2las.hpp	Tue Oct 05 23:01:58 2010 +0100
+++ b/apps/ts2las.hpp	Wed Oct 06 00:14:49 2010 +0100
@@ -1,6 +1,6 @@
 #ifndef TS2LAS_HPP_INCLUDED
 
-#include <liblas/detail/utility.hpp>
+#include <liblas/detail/private_utility.hpp>
 
 #include <liblas/laswriter.hpp>
 #include <liblas/laspoint.hpp>
diff -r b1f8f5367a6b -r 5898e2ec7f55 include/liblas/detail/private_utility.hpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/liblas/detail/private_utility.hpp	Wed Oct 06 00:14:49 2010 +0100
@@ -0,0 +1,495 @@
+/******************************************************************************
+ * $Id$
+ *
+ * Project:  libLAS - http://liblas.org - A BSD library for LAS format data.
+ * Purpose:  A grab bucket 'o fun 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_UTILITY_HPP_INCLUDED
+#define LIBLAS_DETAIL_UTILITY_HPP_INCLUDED
+
+#include <liblas/detail/pointrecord.hpp>
+#include <liblas/detail/endian.hpp>
+// boost
+#include <boost/concept_check.hpp>
+#include <boost/cstdint.hpp>
+// std
+#include <cassert>
+#include <cstddef>
+#include <cstring>
+#include <algorithm>
+#include <iosfwd>
+#include <limits>
+#include <sstream>
+#include <stdexcept>
+#include <cmath>
+#include <vector>
+
+/// Defines utilities for internal use in libLAS.
+/// The liblas::detail elements do not belong to the public
+/// interface of libLAS.
+namespace liblas { namespace detail {
+
+// From http://stackoverflow.com/questions/485525/round-for-float-in-c
+inline double sround(double r) {
+    return (r > 0.0) ? floor(r + 0.5) : ceil(r - 0.5);
+}
+
+
+/// Compile-time calculation size of array defined statically.
+template <typename T, std::size_t N>
+inline std::size_t static_array_size(T (&t)[N])
+{
+    boost::ignore_unused_variable_warning(t);
+    return (sizeof(t) / sizeof(t[0]));
+}
+
+/// Simple RAII wrapper.
+/// It's dedicated to use with types associated with custom deleter,
+/// opaque pointers and C API objects.
+template <typename T>
+class raii_wrapper
+{
+    typedef void(*deleter_type)(T* p);
+
+public:
+
+    raii_wrapper(T* p, deleter_type d)
+        : p_(p), del_(d)
+    {
+        assert(0 != p_);
+        assert(0 != del_);
+    }
+
+    raii_wrapper& operator=(raii_wrapper const& rhs)
+    {
+        if (&rhs != this)
+        {
+            p_ = rhs.p_;
+            del_ = rhs.del_;
+        }
+        return *this;        
+    }
+    
+    
+    ~raii_wrapper()
+    {
+        do_delete(p_);
+    }
+
+    void reset(T* p)
+    {
+        do_delete(p_);
+        p_= p;
+    }
+
+    T* get() const
+    {
+        return p_;
+    }
+
+    void swap(raii_wrapper& other)
+    {
+        std::swap(p_, other.p_);
+    }
+
+    
+private:
+
+    raii_wrapper(raii_wrapper const& other);
+    // raii_wrapper& operator=(raii_wrapper const& rhs);
+
+    void do_delete(T* p)
+    {
+        assert(del_);
+        if (0 != p)
+            del_(p);
+    }
+
+    T* p_;
+    deleter_type del_;
+};
+
+
+/// Definition of variable-length record header.
+struct VLRHeader
+{
+  boost::uint16_t reserved;
+  char userId[16]; // TODO: replace wtih boost::array --mloskot
+  boost::uint16_t recordId;
+  boost::uint16_t recordLengthAfterHeader;
+  char description[32]; // TODO: replace wtih boost::array --mloskot
+};
+
+template <typename T> 
+bool compare_distance(const T& actual, const T& expected);
+
+template <typename T>
+struct Point
+{
+    Point()
+        : x(T()), y(T()), z(T())
+    {}
+    
+    Point(T const& x, T const& y, T const& z)
+        : x(x), y(y), z(z)
+    {}
+
+    bool equal(Point<T> const& other) const
+    {
+        return (compare_distance(x, other.x)
+                && compare_distance(y, other.y)
+                && compare_distance(z, other.z));
+    }
+
+    T x;
+    T y;
+    T z;
+};
+
+template <typename T>
+bool operator==(Point<T> const& lhs, Point<T> const& rhs)
+{
+    return lhs.equal(rhs);
+}
+
+template <typename T>
+bool operator!=(Point<T> const& lhs, Point<T> const& rhs)
+{
+    return (!lhs.equal(rhs));
+}
+
+// template <typename T>
+// struct Extents
+// {
+//     Extents() {}
+//     Extents(detail::Point<T> const& min, detail::Point<T> const& max)
+//         : min(min), max(max)
+//     {}
+// 
+//     bool equal(Extents<T> const& other) const
+//     {
+//         return (min == other.min && max == other.max);
+//     }
+// 
+//     typename detail::Point<T> min;
+//     typename detail::Point<T> max;
+// };
+// 
+// template <typename T>
+// bool operator==(Extents<T> const& lhs, Extents<T> const& rhs)
+// {
+//     return lhs.equal(rhs);
+// }
+// 
+// template <typename T>
+// bool operator!=(Extents<T> const& lhs, Extents<T> const& rhs)
+// {
+//     return (!lhs.equal(rhs));
+// }
+
+template <typename T>
+inline T generate_random_byte()
+{
+    // Requires pseudo-random numbers generator to be initialized
+    // in create_random_based() function - a poor man solution.
+    T const rmin = (std::numeric_limits<T>::min)();
+    T const rmax = (std::numeric_limits<T>::max)();
+    unsigned int const rnd = std::rand() % rmax + rmin;
+
+    assert(rnd <= 255);
+    return static_cast<T>(rnd);
+}
+
+template <typename T> 
+bool compare_distance(const T& actual, const T& expected) 
+{ 
+    const T epsilon = std::numeric_limits<T>::epsilon();  
+    const T diff = actual - expected; 
+
+    if ( !((diff <= epsilon) && (diff >= -epsilon )) ) 
+    { 
+        return false; 
+    } 
+
+    return true;
+}
+
+template<typename T>
+inline char* as_buffer(T& data)
+{
+    return static_cast<char*>(static_cast<void*>(&data));


More information about the Liblas-commits mailing list