[Liblas-commits] hg-main-tree: replace INIT_OPTIONS with something more verbose, ...

liblas-commits at liblas.org liblas-commits at liblas.org
Mon Jul 25 20:31:03 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/3b44435ac590
changeset: 930:3b44435ac590
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Mon Jul 25 17:30:59 2011 -0700
description:
replace INIT_OPTIONS with something more verbose, but more explicit and simpler

diffstat:

 include/pdal/Options.hpp           |  21 +++++++--------------
 include/pdal/StageBase.hpp         |   1 -
 src/Options.cpp                    |  33 ++++++++++++++++++++++++++++-----
 src/drivers/faux/Reader.cpp        |   8 +++++++-
 src/drivers/faux/Writer.cpp        |   9 ++++++++-
 src/drivers/las/Reader.cpp         |   8 +++++++-
 src/drivers/las/Writer.cpp         |   8 +++++++-
 src/drivers/liblas/Reader.cpp      |   8 +++++++-
 src/drivers/liblas/Writer.cpp      |   8 +++++++-
 src/drivers/oci/Reader.cpp         |   9 ++++++++-
 src/drivers/oci/Writer.cpp         |   8 +++++++-
 src/drivers/qfit/Reader.cpp        |   8 +++++++-
 src/drivers/terrasolid/Reader.cpp  |   8 +++++++-
 src/filters/ByteSwapFilter.cpp     |   8 +++++++-
 src/filters/CacheFilter.cpp        |   8 +++++++-
 src/filters/Chipper.cpp            |   8 +++++++-
 src/filters/ColorFilter.cpp        |   8 +++++++-
 src/filters/CropFilter.cpp         |   9 ++++++++-
 src/filters/DecimationFilter.cpp   |   8 +++++++-
 src/filters/MosaicFilter.cpp       |   8 +++++++-
 src/filters/ReprojectionFilter.cpp |   9 ++++++++-
 src/filters/ScalingFilter.cpp      |   8 +++++++-
 test/unit/OptionsTest.cpp          |  32 +++++++++++++-------------------
 23 files changed, 185 insertions(+), 58 deletions(-)

diffs (truncated from 635 to 300 lines):

diff -r 5933f9408d44 -r 3b44435ac590 include/pdal/Options.hpp
--- a/include/pdal/Options.hpp	Mon Jul 25 15:29:48 2011 -0500
+++ b/include/pdal/Options.hpp	Mon Jul 25 17:30:59 2011 -0700
@@ -82,7 +82,7 @@
         , m_description(description)
         , m_value(value)
     {}
-    
+
     // construct it from an xml stream
     Option(std::istream& istr)
     {
@@ -154,10 +154,13 @@
     // 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);
+    // what's a better way to do this?
+    Options(const Option<std::string>&);
+    Options(const Option<std::string>&, const Option<std::string>&);
+    Options(const Option<std::string>&, const Option<std::string>&, const Option<std::string>&);
+    Options(const Option<std::string>&, const Option<std::string>&, const Option<std::string>&, const Option<std::string>&);
 
+    // initialize from a property tree
     Options(boost::property_tree::ptree t);
 
     // read options from an xml stream
@@ -236,16 +239,6 @@
 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 5933f9408d44 -r 3b44435ac590 include/pdal/StageBase.hpp
--- a/include/pdal/StageBase.hpp	Mon Jul 25 15:29:48 2011 -0500
+++ b/include/pdal/StageBase.hpp	Mon Jul 25 17:30:59 2011 -0700
@@ -81,7 +81,6 @@
     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(); }  \
diff -r 5933f9408d44 -r 3b44435ac590 src/Options.cpp
--- a/src/Options.cpp	Mon Jul 25 15:29:48 2011 -0500
+++ b/src/Options.cpp	Mon Jul 25 17:30:59 2011 -0700
@@ -55,13 +55,36 @@
 }
 
 
-Options::Options(std::vector<Option<std::string> > options)
+Options::Options(const Option<std::string>& opt1)
 {
-    BOOST_FOREACH(const Option<std::string>& option, options)
-    {
-        add(option);
-    }
+    add(opt1);
+    return;
+}
 
+
+Options::Options(const Option<std::string>& opt1, const Option<std::string>& opt2)
+{
+    add(opt1);
+    add(opt2);
+    return;
+}
+
+
+Options::Options(const Option<std::string>& opt1, const Option<std::string>& opt2, const Option<std::string>& opt3)
+{
+    add(opt1);
+    add(opt2);
+    add(opt3);
+    return;
+}
+
+
+Options::Options(const Option<std::string>& opt1, const Option<std::string>& opt2, const Option<std::string>& opt3, const Option<std::string>& opt4)
+{
+    add(opt1);
+    add(opt2);
+    add(opt3);
+    add(opt4);
     return;
 }
 
diff -r 5933f9408d44 -r 3b44435ac590 src/drivers/faux/Reader.cpp
--- a/src/drivers/faux/Reader.cpp	Mon Jul 25 15:29:48 2011 -0500
+++ b/src/drivers/faux/Reader.cpp	Mon Jul 25 17:30:59 2011 -0700
@@ -43,7 +43,6 @@
 namespace pdal { namespace drivers { namespace faux {
 
 
-static Options s_defaultOptions;
 IMPLEMENT_STATICS(Reader, "drivers.faux.reader", "Faux Reader")
 
 
@@ -91,6 +90,13 @@
 }
 
 
+const Options& Reader::s_getDefaultOptions()
+{
+    static Options options;
+    return options;
+}
+
+
 Reader::Mode Reader::getMode() const
 {
     return m_mode;
diff -r 5933f9408d44 -r 3b44435ac590 src/drivers/faux/Writer.cpp
--- a/src/drivers/faux/Writer.cpp	Mon Jul 25 15:29:48 2011 -0500
+++ b/src/drivers/faux/Writer.cpp	Mon Jul 25 17:30:59 2011 -0700
@@ -40,7 +40,6 @@
 namespace pdal { namespace drivers { namespace faux {
 
     
-static Options s_defaultOptions;
 IMPLEMENT_STATICS(Writer, "drivers.faux.writer", "Faux Writer")
 
 
@@ -51,6 +50,14 @@
 }
 
 
+const Options& Writer::s_getDefaultOptions()
+{
+    static Options options;
+    return options;
+}
+
+
+
 void Writer::writeBegin()
 {
     m_minimumX = m_minimumY = m_minimumZ = std::numeric_limits<double>::max();
diff -r 5933f9408d44 -r 3b44435ac590 src/drivers/las/Reader.cpp
--- a/src/drivers/las/Reader.cpp	Mon Jul 25 15:29:48 2011 -0500
+++ b/src/drivers/las/Reader.cpp	Mon Jul 25 17:30:59 2011 -0700
@@ -47,7 +47,6 @@
 namespace pdal { namespace drivers { namespace las {
 
 
-static Options s_defaultOptions;
 IMPLEMENT_STATICS(LasReader, "drivers.las.reader", "Las Reader")
 
 
@@ -82,6 +81,13 @@
 }
 
 
+const Options& LasReader::s_getDefaultOptions()
+{
+    static Options options;
+    return options;
+}
+
+
 const std::string& LasReader::getFileName() const
 {
     return m_filename;
diff -r 5933f9408d44 -r 3b44435ac590 src/drivers/las/Writer.cpp
--- a/src/drivers/las/Writer.cpp	Mon Jul 25 15:29:48 2011 -0500
+++ b/src/drivers/las/Writer.cpp	Mon Jul 25 17:30:59 2011 -0700
@@ -54,7 +54,6 @@
 namespace pdal { namespace drivers { namespace las {
 
 
-static Options s_defaultOptions;
 IMPLEMENT_STATICS(LasWriter, "drivers.las.writer", "Las Writer")
 
 
@@ -84,6 +83,13 @@
 }
 
 
+const Options& LasWriter::s_getDefaultOptions()
+{
+    static Options options;
+    return options;
+}
+
+
 void LasWriter::setCompressed(bool v)
 {
     m_lasHeader.SetCompressed(v);
diff -r 5933f9408d44 -r 3b44435ac590 src/drivers/liblas/Reader.cpp
--- a/src/drivers/liblas/Reader.cpp	Mon Jul 25 15:29:48 2011 -0500
+++ b/src/drivers/liblas/Reader.cpp	Mon Jul 25 17:30:59 2011 -0700
@@ -45,7 +45,6 @@
 namespace pdal { namespace drivers { namespace liblas {
 
     
-static Options s_defaultOptions;
 IMPLEMENT_STATICS(LiblasReader, "drivers.liblas.reader", "Liblas Reader")
 
 
@@ -93,6 +92,13 @@
 }
 
 
+const Options& LiblasReader::s_getDefaultOptions()
+{
+    static Options options;
+    return options;
+}
+
+
 const std::string& LiblasReader::getFileName() const
 {
     return m_filename;
diff -r 5933f9408d44 -r 3b44435ac590 src/drivers/liblas/Writer.cpp
--- a/src/drivers/liblas/Writer.cpp	Mon Jul 25 15:29:48 2011 -0500
+++ b/src/drivers/liblas/Writer.cpp	Mon Jul 25 17:30:59 2011 -0700
@@ -51,7 +51,6 @@
 namespace pdal { namespace drivers { namespace liblas {
 
 
-static Options s_defaultOptions;
 IMPLEMENT_STATICS(LiblasWriter, "drivers.liblas.writer", "Liblas Writer")
 
 
@@ -83,6 +82,13 @@
 }
 
 
+const Options& LiblasWriter::s_getDefaultOptions()
+{
+    static Options options;
+    return options;
+}
+
+
 void LiblasWriter::setupExternalHeader()
 {
     setFormatVersion(1,2);
diff -r 5933f9408d44 -r 3b44435ac590 src/drivers/oci/Reader.cpp
--- a/src/drivers/oci/Reader.cpp	Mon Jul 25 15:29:48 2011 -0500
+++ b/src/drivers/oci/Reader.cpp	Mon Jul 25 17:30:59 2011 -0700
@@ -45,7 +45,6 @@
 namespace pdal { namespace drivers { namespace oci {
 
 
-static Options s_defaultOptions;
 IMPLEMENT_STATICS(Reader, "drivers.oci.reader", "OCI Reader")
 
 static OptionsOld dummy;
@@ -116,6 +115,14 @@
     // setNumPoints(1000);
 }    
 
+
+const Options& Reader::s_getDefaultOptions()
+{
+    static Options options;
+    return options;
+}
+
+
 bool Reader::isVerbose() const
 {
     return m_optionsOld.GetPTree().get<bool>("verbose");
diff -r 5933f9408d44 -r 3b44435ac590 src/drivers/oci/Writer.cpp
--- a/src/drivers/oci/Writer.cpp	Mon Jul 25 15:29:48 2011 -0500
+++ b/src/drivers/oci/Writer.cpp	Mon Jul 25 17:30:59 2011 -0700
@@ -269,7 +269,6 @@
 }
 
 
-static Options s_defaultOptions;
 IMPLEMENT_STATICS(Writer, "drivers.oci.writer", "OCI Writer")
 
 static OptionsOld dummy;
@@ -309,6 +308,13 @@
 }
 
 
+const Options& Writer::s_getDefaultOptions()
+{
+    static Options options;
+    return options;
+}
+


More information about the Liblas-commits mailing list