From 4b298e9fae644aa55bca942843e01c398e46e249 Mon Sep 17 00:00:00 2001
From: florent <florent@laas.fr>
Date: Sat, 23 Oct 2010 21:17:24 +0200
Subject: [PATCH] Add template getter command

    * include/CMakeLists.txt,
    * include/dynamic-graph/command-getter.h: new,
    * include/dynamic-graph/command-getter.t.cpp: new,
    * include/dynamic-graph/parameter.h: deleted.
---
 include/CMakeLists.txt                     |  2 +
 include/dynamic-graph/command-getter.h     | 48 ++++++++++++++++++++++
 include/dynamic-graph/command-getter.t.cpp | 44 ++++++++++++++++++++
 include/dynamic-graph/parameter.h          | 18 --------
 4 files changed, 94 insertions(+), 18 deletions(-)
 create mode 100644 include/dynamic-graph/command-getter.h
 create mode 100644 include/dynamic-graph/command-getter.t.cpp
 delete mode 100644 include/dynamic-graph/parameter.h

diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
index e45f6eb..1fbec3a 100644
--- a/include/CMakeLists.txt
+++ b/include/CMakeLists.txt
@@ -70,6 +70,8 @@ command.h
 value.h
 command-setter.h
 command-setter.t.cpp
+command-getter.h
+command-getter.t.cpp
 )
 
 # Recreate correct path for the headers
diff --git a/include/dynamic-graph/command-getter.h b/include/dynamic-graph/command-getter.h
new file mode 100644
index 0000000..1f580ff
--- /dev/null
+++ b/include/dynamic-graph/command-getter.h
@@ -0,0 +1,48 @@
+//
+// Copyright 2010 CNRS
+//
+// Author: Florent Lamiraux
+//
+// This file is part of dynamic-graph.
+// dynamic-graph is free software: you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation, either version 3 of
+// the License, or (at your option) any later version.
+// dynamic-graph is distributed in the hope that it will be
+// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU Lesser General Public License for more details.  You should
+// have received a copy of the GNU Lesser General Public License along
+// with dynamic-graph.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef DYNAMIC_GRAPH_COMMAND_GETTER_H
+#define DYNAMIC_GRAPH_COMMAND_GETTER_H
+
+#include "dynamic-graph/command.h"
+
+namespace dynamicgraph {
+  namespace command {
+
+    ///
+    /// Command that calls a parameter getter function
+    ///
+    template <class E, typename T>
+    class Getter : public Command {
+    public:
+      /// Pointer to method that sets paramter of type T
+      typedef T (E::*GetterMethod) () const;
+      /// Constructor
+      Getter(E& entity, GetterMethod);
+      
+    protected:
+      virtual Value doExecute();
+
+    private:
+      GetterMethod getterMethod_;
+    };
+  } // namespace command
+} // namespace dynamicgraph
+
+#include "dynamic-graph/command-getter.t.cpp"
+#endif //DYNAMIC_GRAPH_COMMAND_GETTER_H
+
diff --git a/include/dynamic-graph/command-getter.t.cpp b/include/dynamic-graph/command-getter.t.cpp
new file mode 100644
index 0000000..98d5522
--- /dev/null
+++ b/include/dynamic-graph/command-getter.t.cpp
@@ -0,0 +1,44 @@
+//
+// Copyright 2010 CNRS
+//
+// Author: Florent Lamiraux
+//
+// This file is part of dynamic-graph.
+// dynamic-graph is free software: you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation, either version 3 of
+// the License, or (at your option) any later version.
+// dynamic-graph is distributed in the hope that it will be
+// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU Lesser General Public License for more details.  You should
+// have received a copy of the GNU Lesser General Public License along
+// with dynamic-graph.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef DYNAMIC_GRAPH_COMMAND_GETTER_T_CPP
+#define DYNAMIC_GRAPH_COMMAND_GETTER_T_CPP
+
+#include <sstream>
+
+namespace dynamicgraph {
+  class Entity;
+  namespace command {
+
+    template <class E, typename T>
+    Getter<E, T>::Getter(E& entity, GetterMethod getterMethod) :
+      Command(entity, std::vector<Value::Type>()),
+      getterMethod_(getterMethod)
+    {
+    }
+
+    template <class E, typename T>
+    Value Getter<E, T>::doExecute()
+    {
+      E& entity = static_cast<E&>(owner());
+      T value = (entity.*getterMethod_)();
+      return Value(value);
+    }
+  } // namespace command
+} // namespace dynamicgraph
+
+#endif // DYNAMIC_GRAPH_COMMAND_GETTER_T_CPP
diff --git a/include/dynamic-graph/parameter.h b/include/dynamic-graph/parameter.h
deleted file mode 100644
index 719aa08..0000000
--- a/include/dynamic-graph/parameter.h
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef DYNAMIC_GRAPH_PARAMETER_H
-#define DYNAMIC_GRAPH_PARAMETER_H
-
-#include <boost/static_assert.hpp>
-#include "dynamicgraph/exception-abstract.h"
-
-namespace dynamicgraph {
-  namespace command {
-    class Parameter {
-    public:
-      Parameter(Value::Type valueType) : valueType_(valueType) {}
-      /// Return value type of parameter
-      Value::Type valueType() { return valueType_;}
-    private:
-      Value::Type valueType_;
-    }; // class Parameter
-  } // namespace command
-} //namespace dynamicgraph
-- 
GitLab