[Liblas-commits] hg-main-tree: implemented further Options support

liblas-commits at liblas.org liblas-commits at liblas.org
Fri Jun 24 19:43:08 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/aba2fce34167
changeset: 809:aba2fce34167
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Fri Jun 24 16:42:57 2011 -0700
description:
implemented further Options support

diffstat:

 include/pdal/Options.hpp         |  130 +++++++++++++++++++++++++++++---------
 include/pdal/PipelineManager.hpp |   19 +++++-
 src/Options.cpp                  |   47 ++++++++++++++
 src/PipelineManager.cpp          |    4 +
 test/unit/CMakeLists.txt         |    1 +
 test/unit/OptionsTest.cpp        |  109 ++++++++++++++++++++++++++++++++
 6 files changed, 275 insertions(+), 35 deletions(-)

diffs (truncated from 397 to 300 lines):

diff -r d04af5e08d51 -r aba2fce34167 include/pdal/Options.hpp
--- a/include/pdal/Options.hpp	Fri Jun 24 09:42:35 2011 -0700
+++ b/include/pdal/Options.hpp	Fri Jun 24 16:42:57 2011 -0700
@@ -43,38 +43,7 @@
 namespace pdal
 {
 
-template <typename T>
-class PDAL_DLL Option
-{
-
     
-private:
-    T m_value;
-    std::string m_description;
-    std::string m_name;
-
-public:
-
-    Option(std::string const& name, T value, std::string const& description) 
-    : m_value(value), m_description(description), m_name(name) {}
-    
-    std::string const& getName() const { return m_name; }
-    std::string const& getDescription() const { return m_description; }
-    T const& getValue() const { return m_value; }
-    
-    boost::property_tree::ptree& getTree() const 
-    {
-        boost::property_tree::ptree t;
-        t.put("description", getDescription());
-        t.put("value", getValue());
-        boost::property_tree::ptree output;
-        output.put_child(getName(), t);
-        return output;
-    }
-
-};
-
-
 class PDAL_DLL Options
 {
 
@@ -85,16 +54,111 @@
 
     Options();
     Options(boost::property_tree::ptree const& tree) { m_tree = tree; }
-    template<class T> void add(Option<T> const& option) { m_tree.put_child(option.getTree()); }
-    template<class T> Option<T> const& get(std::string const& name) { return m_tree.get<T>(name); }
+    //template<class T> void add(Option<T> const& option) { m_tree.put_child(option.getTree()); }
+    //template<class T> Option<T> const& get(std::string const& name) { return m_tree.get<T>(name); }
     
     boost::property_tree::ptree& GetPTree() { return m_tree; }
     boost::property_tree::ptree const& GetPTree() const { return m_tree; }
 };
 
 
+// An Option is just a record with three fields: name, value, and description.
+//
+// Dumped as XML, it looks like this:
+//     <?xml...>
+//     <name>my name</name>
+//     <description>my descr</description>
+//     <value>17</value>
+// although of course that's not valid XML, since it has no single root element.
+
+template <typename T>
+class PDAL_DLL OptionNew
+{
+public:
+    OptionNew(std::string const& name, T value, std::string const& description) 
+        : m_value(value)
+        , m_description(description)
+        , m_name(name)
+    {}
+    
+    std::string const& getName() const { return m_name; }
+    std::string const& getDescription() const { return m_description; }
+    T const& getValue() const { return m_value; }
+    
+    boost::property_tree::ptree getPTree() const 
+    {
+        boost::property_tree::ptree t;
+        t.put("name", getName());
+        t.put("description", getDescription());
+        t.put("value", getValue());
+        return t;
+    }
+         
+private:
+    std::string m_name;
+    std::string m_description;
+    T m_value;
+};
+
+
+
+
+// An Options is just a set of Option items.
+//
+// Dumped as XML, it looks like this:
+//     <?xml...>
+//     <option>
+//       <name>my name</name>
+//       <description>my descr</description>
+//       <value>17</value>
+//     </option>
+//     <option>
+//       <name>my name2</name>
+//       <description>my descr2</description>
+//       <value>13</value>
+//     </option>
+// although of course that's not valid XML, since it has no single root element.
+class PDAL_DLL OptionsNew
+{
+public:
+    OptionsNew();
+
+    // add an option
+    template<class T> void add(OptionNew<T> const& option)
+    {
+       boost::property_tree::ptree fields = option.getPTree();
+       m_tree.add_child("option", fields);
+    }
+
+    // add an option (shortcut version, bypass need for an Option object)
+    template<class T> void add(const std::string& name, T value, const std::string& description)
+    {
+        OptionNew<T> opt(name, value, description);
+        add(opt);
+    }
+
+    // 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>();
+    }
+
+    // get description of an option
+    std::string getDescription(std::string const& name) const;
+    
+    boost::property_tree::ptree const& getPTree() const;
+   
+private:
+    boost::property_tree::ptree OptionsNew::getOptionPTree(std::string const& name) const;
+
+    boost::property_tree::ptree m_tree;
+};
+
+
 PDAL_DLL std::ostream& operator<<(std::ostream& ostr, const Options&);
 
+
 } // namespace pdal
 
 #endif
diff -r d04af5e08d51 -r aba2fce34167 include/pdal/PipelineManager.hpp
--- a/include/pdal/PipelineManager.hpp	Fri Jun 24 09:42:35 2011 -0700
+++ b/include/pdal/PipelineManager.hpp	Fri Jun 24 16:42:57 2011 -0700
@@ -35,16 +35,31 @@
 #ifndef INCLUDED_PIPELINEMANAGER_HPP
 #define INCLUDED_PIPELINEMANAGER_HPP
 
-#include <pdal/pdal.hpp>
+#include <vector>
 
-#include <string>
+#include <pdal/Stage.hpp>
+#include <pdal/Filter.hpp>
+#include <pdal/Writer.hpp>
+
 
 namespace pdal
 {
 
+class OptionsNew;
+
 class PDAL_DLL PipelineManager
 {
 public:
+    PipelineManager();
+
+    boost::uint32_t addReader(const std::string& type, const OptionsNew&);
+    boost::uint32_t addFilter(const std::string& type, boost::uint32_t prevStage, const OptionsNew&);
+    boost::uint32_t addFilter(const std::string& type, std::vector<boost::uint32_t> prevStages, const OptionsNew&);
+    boost::uint32_t addWriter(const std::string& type, boost::uint32_t prevStage, const OptionsNew&);
+    
+    Stage* getStage(boost::uint32_t);
+    Filter* getFilter(boost::uint32_t);
+    Writer* getWriter(boost::uint32_t);
 
 private:
     PipelineManager& operator=(const PipelineManager&); // not implemented
diff -r d04af5e08d51 -r aba2fce34167 src/Options.cpp
--- a/src/Options.cpp	Fri Jun 24 09:42:35 2011 -0700
+++ b/src/Options.cpp	Fri Jun 24 16:42:57 2011 -0700
@@ -34,9 +34,15 @@
 
 #include <pdal/Options.hpp>
 
+#include <boost/property_tree/xml_parser.hpp>
 #include <boost/concept_check.hpp> // ignore_unused_variable_warning
 #include <boost/optional.hpp>
+#include <boost/foreach.hpp>
+
 #include <iostream>
+#include <sstream>
+#include <iostream>
+
 
 #include <pdal/exceptions.hpp>
 
@@ -52,6 +58,47 @@
 
 
 
+OptionsNew::OptionsNew()
+{
+}    
+
+
+boost::property_tree::ptree OptionsNew::getOptionPTree(std::string const& name) const
+{
+    using boost::property_tree::ptree;
+
+    BOOST_FOREACH(ptree::value_type v, m_tree)
+    {
+        if (v.first == "option")
+        {
+            // v.second is <option><name>..</name><value>..</value><desc>..</desc></option>
+            const std::string aname = v.second.get_child("name").get_value<std::string>();
+            if (name == aname)
+            {
+                return v.second;
+            }
+        }
+    }
+
+    throw;
+}
+
+
+std::string OptionsNew::getDescription(std::string const& name) const
+{
+    boost::property_tree::ptree optionTree = getOptionPTree(name);
+    return optionTree.get_child("description").get_value<std::string>();
+}
+
+
+
+boost::property_tree::ptree const& OptionsNew::getPTree() const
+{
+    return m_tree;
+}
+
+
+
 std::ostream& operator<<(std::ostream& ostr, const Options& /*options*/)
 {
 //     ostr << "  Num points: " << stage.getNumPoints() << std::endl;
diff -r d04af5e08d51 -r aba2fce34167 src/PipelineManager.cpp
--- a/src/PipelineManager.cpp	Fri Jun 24 09:42:35 2011 -0700
+++ b/src/PipelineManager.cpp	Fri Jun 24 16:42:57 2011 -0700
@@ -37,5 +37,9 @@
 namespace pdal
 {
 
+PipelineManager::PipelineManager()
+{
+}
+
 
 } // namespace pdal
diff -r d04af5e08d51 -r aba2fce34167 test/unit/CMakeLists.txt
--- a/test/unit/CMakeLists.txt	Fri Jun 24 09:42:35 2011 -0700
+++ b/test/unit/CMakeLists.txt	Fri Jun 24 16:42:57 2011 -0700
@@ -30,6 +30,7 @@
     LiblasReaderTest.cpp
     LiblasWriterTest.cpp
     MosaicFilterTest.cpp
+    OptionsTest.cpp
     PipelineManagerTest.cpp
     PointBufferCacheTest.cpp
     PointBufferTest.cpp
diff -r d04af5e08d51 -r aba2fce34167 test/unit/OptionsTest.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/unit/OptionsTest.cpp	Fri Jun 24 16:42:57 2011 -0700
@@ -0,0 +1,109 @@
+/******************************************************************************
+* 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


More information about the Liblas-commits mailing list