[Liblas-commits] libpc: move boost test DYN_LINK into cmake

liblas-commits at liblas.org liblas-commits at liblas.org
Sat Feb 26 21:40:47 EST 2011


details:   http://hg.liblas.orglibpc/rev/5ce4ff1eecba
changeset: 106:5ce4ff1eecba
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Fri Feb 25 13:37:04 2011 -0800
description:
move boost test DYN_LINK into cmake
Subject: libpc: cmd line app harness

details:   http://hg.liblas.orglibpc/rev/418da484bf92
changeset: 107:418da484bf92
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Fri Feb 25 17:53:33 2011 -0800
description:
cmd line app harness
Subject: libpc: tidy up Application class usage

details:   http://hg.liblas.orglibpc/rev/1599ae95a5eb
changeset: 108:1599ae95a5eb
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Sat Feb 26 17:45:08 2011 -0800
description:
tidy up Application class usage
Subject: libpc: use fixed date

details:   http://hg.liblas.orglibpc/rev/f1495def975f
changeset: 109:f1495def975f
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Sat Feb 26 18:08:04 2011 -0800
description:
use fixed date
Subject: libpc: unit test for progress meter

details:   http://hg.liblas.orglibpc/rev/6e318e420965
changeset: 110:6e318e420965
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Sat Feb 26 18:14:43 2011 -0800
description:
unit test for progress meter
Subject: libpc: added -timer

details:   http://hg.liblas.orglibpc/rev/ac9b1b9ea2aa
changeset: 111:ac9b1b9ea2aa
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Sat Feb 26 18:30:26 2011 -0800
description:
added -timer
Subject: libpc: merge

details:   http://hg.liblas.orglibpc/rev/6fe8cd222568
changeset: 112:6fe8cd222568
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Sat Feb 26 18:40:20 2011 -0800
description:
merge

diffstat:

 apps/Application.cpp              |  178 ++++++++++++++++++++++++++++++++++++++
 apps/Application.hpp              |   95 ++++++++++++++++++++
 apps/CMakeLists.txt               |    4 +-
 apps/pc2pc.cpp                    |   48 +++++++++-
 apps/pcinfo.cpp                   |   38 ++++++-
 include/libpc/LiblasHeader.hpp    |   63 -------------
 include/libpc/LiblasReader.hpp    |   86 ------------------
 include/libpc/LiblasWriter.hpp    |   76 ----------------
 include/libpc/Signaller.hpp       |    4 +
 src/CMakeLists.txt                |   14 +-
 src/LiblasHeader.cpp              |   66 --------------
 src/LiblasReader.cpp              |  132 ----------------------------
 src/LiblasWriter.cpp              |  124 --------------------------
 src/drivers/CMakeLists.txt        |   12 ++
 src/drivers/las/CMakeLists.txt    |    8 +
 src/drivers/liblas/CMakeLists.txt |   18 +++
 src/drivers/liblas/header.cpp     |   66 ++++++++++++++
 src/drivers/liblas/header.hpp     |   63 +++++++++++++
 src/drivers/liblas/reader.cpp     |  132 ++++++++++++++++++++++++++++
 src/drivers/liblas/reader.hpp     |   86 ++++++++++++++++++
 src/drivers/liblas/writer.cpp     |  126 ++++++++++++++++++++++++++
 src/drivers/liblas/writer.hpp     |   76 ++++++++++++++++
 test/unit/BoundsTest.cpp          |   36 +++++++-
 test/unit/CMakeLists.txt          |    4 +
 test/unit/ColorTest.cpp           |   36 +++++++-
 test/unit/ConfigTest.cpp          |   34 +++++++-
 test/unit/CropFilterTest.cpp      |   36 +++++++-
 test/unit/DimensionTest.cpp       |   34 +++++++-
 test/unit/FauxReaderTest.cpp      |   34 +++++++-
 test/unit/FauxWriterTest.cpp      |   34 +++++++-
 test/unit/LiblasReaderTest.cpp    |   38 +++++++-
 test/unit/LiblasWriterTest.cpp    |   38 +++++++-
 test/unit/PointDataTest.cpp       |   36 +++++++-
 test/unit/RangeTest.cpp           |   36 +++++++-
 test/unit/SchemaTest.cpp          |   36 +++++++-
 test/unit/SignallerTest.cpp       |  123 ++++++++++++++++++++++++++
 test/unit/UtilsTest.cpp           |   36 +++++++-
 test/unit/VectorTest.cpp          |   36 +++++++-
 test/unit/main.cpp                |   37 +++++++-
 test/unit/support.cpp             |   36 +++++++-
 test/unit/support.hpp             |   41 ++++++++-
 41 files changed, 1647 insertions(+), 609 deletions(-)

diffs (truncated from 2590 to 300 lines):

diff -r 4736b915dee3 -r 6fe8cd222568 apps/Application.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/Application.cpp	Sat Feb 26 18:40:20 2011 -0800
@@ -0,0 +1,178 @@
+/******************************************************************************
+* Copyright (c) 2011, Michael P. Gerlek (mpg at flaxen.com)
+*
+* 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 Hobu, Inc. or Flaxen Geo Consulting 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 <iostream>
+
+#include <boost/timer.hpp>
+
+#include "libpc/libpc_config.hpp"
+
+#include "Application.hpp"
+
+using namespace libpc;
+namespace po = boost::program_options;
+
+
+Application::Application(int argc, char* argv[], const std::string& appName)
+    : m_argc(argc)
+    , m_argv(argv)
+    , m_appName(appName)
+    , m_isVerbose(false)
+{
+    return;
+}
+
+int Application::run()
+{
+    // add -h, -v, etc
+    addBasicOptionSet();
+
+    // add the options for the derived application
+    addOptions();
+
+    // parse the command line
+    parseOptions();
+
+    // handle the well-known options
+    if (hasOption("version")) 
+    {
+        outputVersion(std::cout);
+        return 0;
+    }
+    
+    if (hasOption("help")) 
+    {
+        outputHelp(std::cout);
+        return 0;
+    }
+
+    boost::timer timer;
+    
+    // call derived function
+    int status = execute();
+
+    if (hasOption("timer"))
+    {
+        const double t = timer.elapsed();
+        std::cout << "Elapsed time: " << t << " seconds" << std::endl;
+    }
+
+    return status;
+}
+
+
+bool Application::hasOption(const std::string& name)
+{
+    return m_variablesMap.count(name) > 0;
+}
+
+
+bool Application::isVerbose() const
+{
+    return m_isVerbose;
+}
+
+
+void Application::addOptionSet(po::options_description* options)
+{
+    m_options.push_back(options);
+}
+
+
+void Application::outputHelp(std::ostream& oss)
+{
+    outputVersion(oss);
+
+    std::vector<po::options_description*>::const_iterator iter;
+    for (iter = m_options.begin(); iter != m_options.end(); ++iter)
+    {
+        const po::options_description* options = *iter;
+        oss << *options;
+    }
+
+    oss <<"\nFor more information, see the full documentation for libPC at:\n";
+    
+    oss << " http://libpc.org/\n";
+    oss << "----------------------------------------------------------\n";
+}
+
+
+void Application::outputVersion(std::ostream& oss)
+{
+    oss << "--------------------------------------------------------------------\n";
+    oss << "    pc2pc (" << libpc::GetFullVersionString() << ")\n";
+    oss << "--------------------------------------------------------------------\n";
+}
+
+
+void Application::addBasicOptionSet()
+{
+    po::options_description* basic_options = new po::options_description("basic options");
+
+    basic_options->add_options()
+        ("help,h", "produce help message")
+        ("verbose,v", po::value<bool>(&m_isVerbose)->zero_tokens(), "Verbose message output")
+        ("version", "Show version info")
+        ("timer", "Show execution time")
+        ;
+
+    addOptionSet(basic_options);
+
+    return;
+}
+
+
+void Application::parseOptions()
+{
+    po::options_description options;
+
+    std::vector<po::options_description*>::iterator iter;
+    for (iter = m_options.begin(); iter != m_options.end(); ++iter)
+    {
+        po::options_description* sub_options = *iter;
+        options.add(*sub_options);
+    }
+
+    //po::positional_options_description p;
+    //p.add("input", 1);
+    //p.add("output", 1);
+
+    po::store(po::command_line_parser(m_argc, m_argv).
+        options(options)/*.positional(p)*/.run(), m_variablesMap);
+
+    po::notify(m_variablesMap);
+
+    return;
+}
+
diff -r 4736b915dee3 -r 6fe8cd222568 apps/Application.hpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/Application.hpp	Sat Feb 26 18:40:20 2011 -0800
@@ -0,0 +1,95 @@
+/******************************************************************************
+* Copyright (c) 2011, Michael P. Gerlek (mpg at flaxen.com)
+*
+* 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 Hobu, Inc. or Flaxen Geo Consulting 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 INCLUDED_APPLICATION_HPP
+#define INCLUDED_APPLICATION_HPP
+
+#include <iosfwd>
+
+
+#ifdef _MSC_VER
+#  pragma warning(push)
+#  pragma warning(disable: 4512)  // assignment operator could not be generated
+#endif
+#include <boost/program_options.hpp>
+#ifdef _MSC_VER
+#  pragma warning(pop)
+#endif
+
+
+//
+// The pplication base class gives us these common options:
+//    --help / -h
+//    --verbose / -v
+//    --version
+//    --timer
+//
+class Application
+{
+public:
+    // call this, to start the machine
+    int run();
+
+protected:
+    // implement this, with calls to addOptionSet()
+    virtual void addOptions() = 0;
+
+    // implement this, to do your actual work
+    virtual int execute() = 0;
+
+protected:
+    Application(int argc, char* argv[], const std::string& appName);
+    void addOptionSet(boost::program_options::options_description* options);
+    bool isVerbose() const;
+    bool hasOption(const std::string& name);
+
+private:
+    void parseOptions();
+    void outputHelp(std::ostream& oss);
+    void outputVersion(std::ostream& oss);
+    void addBasicOptionSet();
+
+    bool m_isVerbose;
+    const int m_argc;
+    char** m_argv;
+    const std::string m_appName;
+
+    std::vector<boost::program_options::options_description*> m_options;
+    boost::program_options::variables_map m_variablesMap;
+
+    Application& operator=(const Application&); // not implemented
+    Application(const Application&); // not implemented
+};
+
+#endif
diff -r 4736b915dee3 -r 6fe8cd222568 apps/CMakeLists.txt
--- a/apps/CMakeLists.txt	Fri Feb 25 13:04:51 2011 -0800
+++ b/apps/CMakeLists.txt	Sat Feb 26 18:40:20 2011 -0800
@@ -46,12 +46,12 @@
 
 # Build pcinfo
 if(PCINFO)
-    add_executable(${PCINFO} pcinfo.cpp)
+    add_executable(${PCINFO} pcinfo.cpp Application.cpp Application.hpp)
     target_link_libraries(${PCINFO} ${APPS_CPP_DEPENDENCIES} )
 endif()
 
 if(PC2PC)
-    add_executable(${PC2PC} pc2pc.cpp)
+    add_executable(${PC2PC} pc2pc.cpp Application.cpp Application.hpp)
     target_link_libraries(${PC2PC} ${APPS_CPP_DEPENDENCIES} )
 endif()
 
diff -r 4736b915dee3 -r 6fe8cd222568 apps/pc2pc.cpp


More information about the Liblas-commits mailing list