[Liblas-commits] hg-main-tree: improved Options API,
added support for debug/vebo...
liblas-commits at liblas.org
liblas-commits at liblas.org
Fri Jul 29 12:50:59 EDT 2011
details: http://hg.libpc.orghg-main-tree/rev/a7b9128d7b29
changeset: 962:a7b9128d7b29
user: Michael P. Gerlek <mpg at flaxen.com>
date: Fri Jul 29 09:50:54 2011 -0700
description:
improved Options API, added support for debug/vebose opts
diffstat:
include/pdal/Options.hpp | 25 ++++++++++++++++++++++++
src/StageBase.cpp | 4 +-
src/drivers/las/Reader.cpp | 4 +--
src/filters/CropFilter.cpp | 2 +-
test/unit/LasReaderTest.cpp | 46 +++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 75 insertions(+), 6 deletions(-)
diffs (132 lines):
diff -r 36fc7fac39f9 -r a7b9128d7b29 include/pdal/Options.hpp
--- a/include/pdal/Options.hpp Thu Jul 28 21:03:54 2011 -0700
+++ b/include/pdal/Options.hpp Fri Jul 29 09:50:54 2011 -0700
@@ -204,6 +204,31 @@
throw option_not_found(name);
}
+ // get value of an option, or throw option_not_found if option not present
+ template<typename T> T getValueOrThrow(std::string const& name) const
+ {
+ Option<T> opt = getOption<T>(name); // might throw
+ return opt.getValue();
+ }
+
+ // get value of an option, or use given default if option not present
+ template<typename T> T getValueOrDefault(std::string const& name, T defaultValue) const
+ {
+ T result;
+
+ try
+ {
+ Option<T> opt = getOption<T>(name); // might throw
+ result = opt.getValue();
+ }
+ catch (option_not_found)
+ {
+ result = defaultValue;
+ }
+
+ return result;
+ }
+
// returns true iff the option name is valid
template<typename T> bool hasOption(std::string const& name) const
{
diff -r 36fc7fac39f9 -r a7b9128d7b29 src/StageBase.cpp
--- a/src/StageBase.cpp Thu Jul 28 21:03:54 2011 -0700
+++ b/src/StageBase.cpp Fri Jul 29 09:50:54 2011 -0700
@@ -45,8 +45,8 @@
StageBase::StageBase(const Options& options)
: m_options(options)
- , m_debug(false)
- , m_verbose(0)
+ , m_debug(options.getValueOrDefault<bool>("debug", false))
+ , m_verbose(options.getValueOrDefault<boost::uint8_t>("verbose", 0))
{
return;
}
diff -r 36fc7fac39f9 -r a7b9128d7b29 src/drivers/las/Reader.cpp
--- a/src/drivers/las/Reader.cpp Thu Jul 28 21:03:54 2011 -0700
+++ b/src/drivers/las/Reader.cpp Fri Jul 29 09:50:54 2011 -0700
@@ -52,10 +52,8 @@
LasReader::LasReader(const Options& options)
: LasReaderBase(options)
- , m_filename("")
+ , m_filename(options.getValueOrThrow<std::string>("filename"))
{
- m_filename = options.getOption<std::string>("filename").getValue();
-
initialize();
return;
diff -r 36fc7fac39f9 -r a7b9128d7b29 src/filters/CropFilter.cpp
--- a/src/filters/CropFilter.cpp Thu Jul 28 21:03:54 2011 -0700
+++ b/src/filters/CropFilter.cpp Fri Jul 29 09:50:54 2011 -0700
@@ -47,7 +47,7 @@
CropFilter::CropFilter(const Stage& prevStage, const Options& options)
: pdal::Filter(prevStage, options)
- , m_bounds(options.getOption<Bounds<double> >("bounds").getValue())
+ , m_bounds(options.getValueOrThrow<Bounds<double> >("bounds"))
{
initialize();
diff -r 36fc7fac39f9 -r a7b9128d7b29 test/unit/LasReaderTest.cpp
--- a/test/unit/LasReaderTest.cpp Thu Jul 28 21:03:54 2011 -0700
+++ b/test/unit/LasReaderTest.cpp Fri Jul 29 09:50:54 2011 -0700
@@ -47,6 +47,52 @@
BOOST_AUTO_TEST_SUITE(LasReaderTest)
+BOOST_AUTO_TEST_CASE(test_base_options)
+{
+ const std::string file(Support::datapath("1.2-with-color.las"));
+
+ const pdal::Option<std::string> opt_filename("filename", file);
+ const pdal::Option<std::string> opt_verbose_string("verbose", "99");
+ const pdal::Option<boost::uint8_t> opt_verbose_uint8("verbose", 99);
+ const pdal::Option<std::string> opt_debug_string("debug", "true");
+ const pdal::Option<bool> opt_debug_bool("debug", true);
+
+ {
+ pdal::Options opts;
+ opts.add(opt_filename);
+
+ pdal::drivers::las::LasReader reader(opts);
+ BOOST_CHECK(reader.getFileName() == file);
+ BOOST_CHECK(reader.getVerboseLevel() == 0);
+ BOOST_CHECK(reader.isDebug() == false);
+ }
+
+ {
+ pdal::Options opts;
+ opts.add(opt_filename);
+ opts.add(opt_verbose_string);
+ opts.add(opt_debug_string);
+ pdal::drivers::las::LasReader reader(opts);
+ BOOST_CHECK(reader.getFileName() == file);
+ BOOST_CHECK(reader.getVerboseLevel() == 99);
+ BOOST_CHECK(reader.isDebug() == true);
+ }
+
+ {
+ pdal::Options opts;
+ opts.add(opt_filename);
+ opts.add(opt_verbose_uint8);
+ opts.add(opt_debug_bool);
+ pdal::drivers::las::LasReader reader(opts);
+ BOOST_CHECK(reader.getFileName() == file);
+ BOOST_CHECK(reader.getVerboseLevel() == 99);
+ BOOST_CHECK(reader.isDebug() == true);
+ }
+
+ return;
+}
+
+
BOOST_AUTO_TEST_CASE(test_sequential)
{
pdal::drivers::las::LasReader reader(Support::datapath("1.2-with-color.las"));
More information about the Liblas-commits
mailing list