[Liblas-commits] hg-main-tree: added StageBase class,
for getName() and getOption...
liblas-commits at liblas.org
liblas-commits at liblas.org
Fri Jul 22 16:41:26 EDT 2011
details: http://hg.libpc.orghg-main-tree/rev/bfcaede0b667
changeset: 913:bfcaede0b667
user: Michael P. Gerlek <mpg at flaxen.com>
date: Fri Jul 22 11:54:00 2011 -0700
description:
added StageBase class, for getName() and getOptions(); added macros for same
Subject: hg-main-tree: add a really ugly mechanism for static initializers
details: http://hg.libpc.orghg-main-tree/rev/72f8bcb7f7fb
changeset: 914:72f8bcb7f7fb
user: Michael P. Gerlek <mpg at flaxen.com>
date: Fri Jul 22 13:40:46 2011 -0700
description:
add a really ugly mechanism for static initializers
Subject: hg-main-tree: split StageBase out into its own file
details: http://hg.libpc.orghg-main-tree/rev/b2fee5275eb3
changeset: 915:b2fee5275eb3
user: Michael P. Gerlek <mpg at flaxen.com>
date: Fri Jul 22 13:41:04 2011 -0700
description:
split StageBase out into its own file
Subject: hg-main-tree: merge
details: http://hg.libpc.orghg-main-tree/rev/f2ff84a215f9
changeset: 916:f2ff84a215f9
user: Michael P. Gerlek <mpg at flaxen.com>
date: Fri Jul 22 13:41:19 2011 -0700
description:
merge
diffstat:
apps/CMakeLists.txt | 6 +-
include/pdal/Options.hpp | 14 +++
include/pdal/Stage.hpp | 20 +----
include/pdal/StageBase.hpp | 106 ++++++++++++++++++++++++++++
include/pdal/Writer.hpp | 8 +-
include/pdal/drivers/faux/Reader.hpp | 5 +-
include/pdal/drivers/faux/Writer.hpp | 5 +-
include/pdal/drivers/las/Reader.hpp | 5 +-
include/pdal/drivers/las/Writer.hpp | 5 +-
include/pdal/drivers/liblas/Reader.hpp | 5 +-
include/pdal/drivers/liblas/Writer.hpp | 5 +-
include/pdal/drivers/oci/Reader.hpp | 4 +-
include/pdal/drivers/oci/Writer.hpp | 6 +-
include/pdal/drivers/qfit/Reader.hpp | 3 +-
include/pdal/drivers/terrasolid/Reader.hpp | 3 +-
include/pdal/filters/ByteSwapFilter.hpp | 5 +-
include/pdal/filters/CacheFilter.hpp | 5 +-
include/pdal/filters/Chipper.hpp | 5 +-
include/pdal/filters/ColorFilter.hpp | 5 +-
include/pdal/filters/CropFilter.hpp | 5 +-
include/pdal/filters/DecimationFilter.hpp | 5 +-
include/pdal/filters/MosaicFilter.hpp | 5 +-
include/pdal/filters/ReprojectionFilter.hpp | 5 +-
include/pdal/filters/ScalingFilter.hpp | 5 +-
src/CMakeLists.txt | 2 +
src/Options.cpp | 11 ++
src/Stage.cpp | 15 +---
src/StageBase.cpp | 74 +++++++++++++++++++
src/Writer.cpp | 4 +-
src/drivers/faux/Reader.cpp | 17 +---
src/drivers/faux/Writer.cpp | 17 +---
src/drivers/las/Reader.cpp | 17 +---
src/drivers/las/Writer.cpp | 18 +---
src/drivers/liblas/Reader.cpp | 19 +---
src/drivers/liblas/Writer.cpp | 15 +---
src/drivers/oci/Reader.cpp | 16 +---
src/drivers/oci/Writer.cpp | 22 +----
src/drivers/qfit/Reader.cpp | 15 +---
src/drivers/terrasolid/Reader.cpp | 15 +---
src/filters/ByteSwapFilter.cpp | 16 +---
src/filters/CacheFilter.cpp | 16 +---
src/filters/Chipper.cpp | 16 +---
src/filters/ColorFilter.cpp | 17 +---
src/filters/CropFilter.cpp | 17 +---
src/filters/DecimationFilter.cpp | 17 +---
src/filters/MosaicFilter.cpp | 17 +---
src/filters/ReprojectionFilter.cpp | 17 +---
src/filters/ScalingFilter.cpp | 17 +---
test/unit/OptionsTest.cpp | 21 +++++-
49 files changed, 348 insertions(+), 345 deletions(-)
diffs (truncated from 1469 to 300 lines):
diff -r cc1a954b7bac -r f2ff84a215f9 apps/CMakeLists.txt
--- a/apps/CMakeLists.txt Fri Jul 22 10:24:11 2011 -0500
+++ b/apps/CMakeLists.txt Fri Jul 22 13:41:19 2011 -0700
@@ -90,9 +90,9 @@
# if(WITH_GDAL)
# set(PKGCFG_INC_DIR "${PKGCFG_INC_DIR} ${GDAL_INCLUDE_DIR}")
# endif()
- install(FILES ${CMAKE_CURRENT_BINARY_DIR}/pdal.pc
- DESTINATION ${PDAL_LIB_DIR}/pkgconfig
- PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
+ # install(FILES ${CMAKE_CURRENT_BINARY_DIR}/pdal.pc
+ # DESTINATION ${PDAL_LIB_DIR}/pkgconfig
+ # PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
else()
diff -r cc1a954b7bac -r f2ff84a215f9 include/pdal/Options.hpp
--- a/include/pdal/Options.hpp Fri Jul 22 10:24:11 2011 -0500
+++ b/include/pdal/Options.hpp Fri Jul 22 13:41:19 2011 -0700
@@ -154,6 +154,10 @@
// defult ctor, empy options list
Options() {}
+ // construct from an array of Option items
+ // (useful for initialization of a static Options object)
+ Options(std::vector<pdal::Option<std::string> > options);
+
Options(boost::property_tree::ptree t);
// read options from an xml stream
@@ -232,6 +236,16 @@
PDAL_DLL std::ostream& operator<<(std::ostream& ostr, const OptionsOld&);
+// Use this to create a static variable initialized to the given Option items.
+// Note that option_items must use boost::assign syntax, e.g.
+// INIT_OPTIONS(s_defaultOptions, (pdal::Option<std::string>("r","s","t")) (pdal::Option<std::string>("u","v","w")) )
+// The reason for this mess is that we want to initialize static Options objects, and there's no clean way to do that.
+
+#define INIT_OPTIONS(var, option_items) \
+ static const std::vector<pdal::Option<std::string> > var##_vector(boost::assign::list_of option_items); \
+ static const pdal::Options var(var##_vector);
+
+
} // namespace pdal
#endif
diff -r cc1a954b7bac -r f2ff84a215f9 include/pdal/Stage.hpp
--- a/include/pdal/Stage.hpp Fri Jul 22 10:24:11 2011 -0500
+++ b/include/pdal/Stage.hpp Fri Jul 22 13:41:19 2011 -0700
@@ -37,13 +37,11 @@
#include <pdal/pdal.hpp>
-#include <string>
-
+#include <pdal/StageBase.hpp>
#include <pdal/Schema.hpp>
#include <pdal/Bounds.hpp>
#include <pdal/SpatialReference.hpp>
#include <pdal/MetadataRecord.hpp>
-#include <pdal/Options.hpp>
namespace pdal
{
@@ -54,22 +52,12 @@
class StageBlockIterator;
// every stage owns its own header, they are not shared
-class PDAL_DLL Stage
+class PDAL_DLL Stage : public StageBase
{
public:
Stage(const Options& options);
virtual ~Stage();
- const Options& getOptions() const;
-
- // Implement this in your concrete classes to return a constant string
- // as the name of the stage. Use a dotted, XPath-style name for your
- // stage. For example, 'drivers.las.reader' or 'filters.crop'. This
- // XPath-style name will also correspond to an entry in the pdal::Options
- // tree for the given stage.
- virtual const std::string& getName() const = 0;
- virtual const std::string& getDescription() const = 0;
-
// core properties of all stages
const Schema& getSchema() const;
virtual boost::uint64_t getNumPoints() const;
@@ -89,8 +77,6 @@
void dump() const;
protected:
- Options& getOptions();
-
// setters for the core properties
Schema& getSchemaRef();
void setSchema(const Schema&);
@@ -106,8 +92,6 @@
void setCoreProperties(const Stage&);
private:
- Options m_options;
-
Schema m_schema;
boost::uint64_t m_numPoints;
PointCountType m_pointCountType;
diff -r cc1a954b7bac -r f2ff84a215f9 include/pdal/StageBase.hpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/include/pdal/StageBase.hpp Fri Jul 22 13:41:19 2011 -0700
@@ -0,0 +1,106 @@
+/******************************************************************************
+* 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_STAGEBASE_HPP
+#define INCLUDED_STAGEBASE_HPP
+
+#include <pdal/pdal.hpp>
+#include <pdal/Options.hpp>
+
+#include <string>
+
+
+namespace pdal
+{
+
+
+// both Stages and Writers have a few common properties, so
+class PDAL_DLL StageBase
+{
+public:
+ StageBase(const Options& options);
+
+ const Options& getOptions() const;
+
+ // For Name, Description, and DefaultOptions:
+ // each concrete class should provide a static function s_getX() which returns a static object
+ // each concrete class should provide a virtual getX() which returns s_getX()
+ // This is automated via the GenerateStatics() macro below.
+
+ // Use a dotted, XPath-style name for your
+ // stage. For example, 'drivers.las.reader' or 'filters.crop'. This
+ // XPath-style name will also correspond to an entry in the pdal::Options
+ // tree for the given stage.
+
+ virtual const Options& getDefaultOptions() const = 0; // { return s_getDefaultOptions(); }
+ virtual const std::string& getName() const = 0; // { return s_getName(); }
+ virtual const std::string& getDescription() const = 0; // { return s_getDescription(); }
+ //static const Options& s_getDefaultOptions();
+ //static const std::string& s_getName();
+ //static const std::string& s_getDescription();
+
+#define DECLARE_STATICS \
+ public: \
+ static const Options& s_getDefaultOptions(); \
+ virtual const Options& getDefaultOptions() const; \
+ static const std::string& s_getName(); \
+ virtual const std::string& getName() const; \
+ static const std::string& s_getDescription(); \
+ virtual const std::string& getDescription() const; \
+ private:
+
+#define IMPLEMENT_STATICS(T, name, description) \
+ const Options& T::s_getDefaultOptions() { return s_defaultOptions; } \
+ const Options& T::getDefaultOptions() const { return s_getDefaultOptions(); } \
+ const std::string& T::s_getName() { static std::string s(name); return s; } \
+ const std::string& T::getName() const { return s_getName(); } \
+ const std::string& T::s_getDescription() { static std::string s(description); return s; } \
+ const std::string& T::getDescription() const { return s_getDescription(); }
+
+protected:
+ Options& getOptions();
+
+private:
+ Options m_options;
+
+ StageBase& operator=(const StageBase&); // not implemented
+ StageBase(const StageBase&); // not implemented
+};
+
+
+PDAL_DLL std::ostream& operator<<(std::ostream& ostr, const StageBase&);
+
+} // namespace pdal
+
+#endif
diff -r cc1a954b7bac -r f2ff84a215f9 include/pdal/Writer.hpp
--- a/include/pdal/Writer.hpp Fri Jul 22 10:24:11 2011 -0500
+++ b/include/pdal/Writer.hpp Fri Jul 22 13:41:19 2011 -0700
@@ -37,6 +37,7 @@
#include <pdal/pdal.hpp>
#include <pdal/Options.hpp>
+#include <pdal/Stage.hpp>
#include <string>
@@ -46,7 +47,7 @@
class Stage;
class PointBuffer;
-class PDAL_DLL Writer
+class PDAL_DLL Writer : public StageBase
{
public:
Writer(Stage& prevStage, const Options& options);
@@ -61,8 +62,6 @@
// actually written.
boost::uint64_t write(boost::uint64_t targetNumPointsToWrite);
- const Options& getOptions() const;
-
protected:
// this is called once before the loop with the writeBuffer calls
virtual void writeBegin() = 0;
@@ -79,10 +78,7 @@
boost::uint64_t m_actualNumPointsWritten;
boost::uint64_t m_targetNumPointsToWrite;
- Options& getOptions();
-
private:
- Options m_options;
Stage& m_prevStage;
boost::uint32_t m_chunkSize;
static const boost::uint32_t s_defaultChunkSize;
diff -r cc1a954b7bac -r f2ff84a215f9 include/pdal/drivers/faux/Reader.hpp
--- a/include/pdal/drivers/faux/Reader.hpp Fri Jul 22 10:24:11 2011 -0500
+++ b/include/pdal/drivers/faux/Reader.hpp Fri Jul 22 13:41:19 2011 -0700
@@ -65,6 +65,8 @@
//
class PDAL_DLL Reader : public pdal::Reader
{
+ DECLARE_STATICS
+
public:
enum Mode
{
@@ -76,9 +78,6 @@
public:
Reader(const Bounds<double>&, int numPoints, Mode mode);
Reader(const Bounds<double>&, int numPoints, Mode mode, const std::vector<Dimension>& dimensions);
-
- const std::string& getDescription() const;
- const std::string& getName() const;
Mode getMode() const;
diff -r cc1a954b7bac -r f2ff84a215f9 include/pdal/drivers/faux/Writer.hpp
--- a/include/pdal/drivers/faux/Writer.hpp Fri Jul 22 10:24:11 2011 -0500
+++ b/include/pdal/drivers/faux/Writer.hpp Fri Jul 22 13:41:19 2011 -0700
@@ -51,12 +51,11 @@
//
class PDAL_DLL Writer : public pdal::Writer
{
+ DECLARE_STATICS
+
public:
Writer(Stage& prevStage);
- const std::string& getDescription() const;
- const std::string& getName() const;
-
// retrieve the summary info
double getMinX() const { return m_minimumX; }
double getMinY() const { return m_minimumY; }
diff -r cc1a954b7bac -r f2ff84a215f9 include/pdal/drivers/las/Reader.hpp
--- a/include/pdal/drivers/las/Reader.hpp Fri Jul 22 10:24:11 2011 -0500
+++ b/include/pdal/drivers/las/Reader.hpp Fri Jul 22 13:41:19 2011 -0700
More information about the Liblas-commits
mailing list