[Liblas-commits] hg-main-tree: attempt to return an empty value
when an option wi...
liblas-commits at liblas.org
liblas-commits at liblas.org
Mon Jul 11 12:37:18 EDT 2011
details: http://hg.libpc.orghg-main-tree/rev/c2059911fa1e
changeset: 846:c2059911fa1e
user: Howard Butler <hobu.inc at gmail.com>
date: Mon Jul 11 11:36:53 2011 -0500
description:
attempt to return an empty value when an option with a given name is not found -- maybe we should throw our own exception here?
Subject: hg-main-tree: update the QFIT driver to use the new pdal::Options and pdal::Option class
details: http://hg.libpc.orghg-main-tree/rev/21362c2fefc2
changeset: 847:21362c2fefc2
user: Howard Butler <hobu.inc at gmail.com>
date: Mon Jul 11 11:37:13 2011 -0500
description:
update the QFIT driver to use the new pdal::Options and pdal::Option class
diffstat:
include/pdal/Options.hpp | 12 ++++++++++--
include/pdal/drivers/qfit/Reader.hpp | 6 ++----
src/drivers/qfit/Reader.cpp | 15 ++++-----------
test/unit/QFITReaderTest.cpp | 26 ++++++++++----------------
4 files changed, 26 insertions(+), 33 deletions(-)
diffs (145 lines):
diff -r 590af14311a4 -r 21362c2fefc2 include/pdal/Options.hpp
--- a/include/pdal/Options.hpp Mon Jul 11 10:52:02 2011 -0500
+++ b/include/pdal/Options.hpp Mon Jul 11 11:37:13 2011 -0500
@@ -140,8 +140,16 @@
// get value of an option
template<class T> T getValue(std::string const& name) const
{
- boost::property_tree::ptree optionTree = getOptionPTree(name);
- return optionTree.get_child("value").get_value<T>();
+ try
+ {
+ boost::property_tree::ptree optionTree = getOptionPTree(name);
+ return optionTree.get_child("value").get_value<T>();
+ } catch (boost::property_tree::ptree_bad_path const&)
+ {
+ return T();
+ }
+
+
}
// get description of an option
diff -r 590af14311a4 -r 21362c2fefc2 include/pdal/drivers/qfit/Reader.hpp
--- a/include/pdal/drivers/qfit/Reader.hpp Mon Jul 11 10:52:02 2011 -0500
+++ b/include/pdal/drivers/qfit/Reader.hpp Mon Jul 11 11:37:13 2011 -0500
@@ -121,7 +121,7 @@
{
public:
- Reader(OptionsOld& options);
+ Reader(Options& options);
~Reader();
const std::string& getDescription() const;
@@ -140,8 +140,6 @@
pdal::StageSequentialIterator* createSequentialIterator() const;
pdal::StageRandomIterator* createRandomIterator() const;
- OptionsOld& getOptionsOld() const { return m_optionsOld; }
-
std::size_t getPointDataOffset() const { return m_offset; }
boost::uint32_t getPointDataSize() const { return m_size; }
@@ -157,7 +155,7 @@
Reader& operator=(const Reader&); // not implemented
Reader(const Reader&); // not implemented
- OptionsOld& m_optionsOld;
+ // OptionsOld& m_optionsOld;
QFIT_Format_Type m_format;
std::size_t m_offset;
boost::uint32_t m_size;
diff -r 590af14311a4 -r 21362c2fefc2 src/drivers/qfit/Reader.cpp
--- a/src/drivers/qfit/Reader.cpp Mon Jul 11 10:52:02 2011 -0500
+++ b/src/drivers/qfit/Reader.cpp Mon Jul 11 11:37:13 2011 -0500
@@ -221,9 +221,8 @@
-Reader::Reader(OptionsOld& optionsOld)
- : pdal::Reader(Options::none())
- , m_optionsOld(optionsOld)
+Reader::Reader(Options& options)
+ : pdal::Reader(options)
, m_format(QFIT_Format_Unknown)
, m_size(0)
{
@@ -307,15 +306,9 @@
std::string Reader::getFileName() const
{
- try
- {
- return m_optionsOld.GetPTree().get<std::string>("input");
-
- } catch (boost::property_tree::ptree_bad_path const&)
- {
- return std::string("");
- }
+ return getOptions().getValue<std::string>("input");
}
+
void Reader::registerFields()
{
Schema& schema = getSchemaRef();
diff -r 590af14311a4 -r 21362c2fefc2 test/unit/QFITReaderTest.cpp
--- a/test/unit/QFITReaderTest.cpp Mon Jul 11 10:52:02 2011 -0500
+++ b/test/unit/QFITReaderTest.cpp Mon Jul 11 11:37:13 2011 -0500
@@ -71,15 +71,15 @@
double x0 = schema.getDimension(offsetX).applyScaling<boost::int32_t>(x);
double y0 = schema.getDimension(offsetY).applyScaling<boost::int32_t>(y);
- double z0 = schema.getDimension(offsetZ).applyScaling<boost::int32_t>(z);
+ double z0 = static_cast<double>(z);
-
+ //
// std::cout.setf(std::ios_base::fixed, std::ios_base::floatfield);
// std::cout.precision(6);
// std::cout << "expected x: " << xref << " y: " << yref << " z: " << zref << " t: " << tref << std::endl;
//
// std::cout << "actual x: " << x0 << " y: " << y0 << " z: " << z0 << " t: " << t << std::endl;
- //
+
Compare(x0, xref);
Compare(y0, yref);
Compare(z0, zref);
@@ -88,14 +88,11 @@
BOOST_AUTO_TEST_CASE(test_10_word)
{
- pdal::OptionsOld options;
+ pdal::Options options;
// std::string filename = Support::datapath("20050903_231839.qi");
- std::string filename = Support::datapath("qfit/10-word.qi");
-
-
- boost::property_tree::ptree& tree = options.GetPTree();
- tree.put<std::string>("input", filename);
+ pdal::Option<std::string> filename("input", Support::datapath("qfit/10-word.qi"), "Input filename for reader to use" );
+ options.add(filename);
pdal::drivers::qfit::Reader reader(options);
BOOST_CHECK(reader.getDescription() == "QFIT Reader");
BOOST_CHECK_EQUAL(reader.getName(), "drivers.qfit.reader");
@@ -124,15 +121,12 @@
BOOST_AUTO_TEST_CASE(test_14_word)
{
- pdal::OptionsOld options;
- // std::string filename = Support::datapath("20050903_231839.qi");
+ pdal::Options options;
- std::string filename = Support::datapath("qfit/14-word.qi");
-
+ pdal::Option<std::string> filename("input", Support::datapath("qfit/14-word.qi"), "Input filename for reader to use" );
+ options.add(filename);
+ pdal::drivers::qfit::Reader reader(options);
- boost::property_tree::ptree& tree = options.GetPTree();
- tree.put<std::string>("input", filename);
- pdal::drivers::qfit::Reader reader(options);
const Schema& schema = reader.getSchema();
SchemaLayout layout(schema);
More information about the Liblas-commits
mailing list