From 6893d3d19a886dc944ddcb635bf5c3ee9de76134 Mon Sep 17 00:00:00 2001
From: Mansard <nmansard@laas.fr>
Date: Thu, 20 Jan 2011 11:22:48 +0100
Subject: [PATCH] IVIGIT.

---
 include/CMakeLists.txt                        |  3 +
 include/dynamic-graph/command-direct-getter.h | 72 ++++++++++++++++++
 include/dynamic-graph/command-direct-setter.h | 75 +++++++++++++++++++
 3 files changed, 150 insertions(+)
 create mode 100644 include/dynamic-graph/command-direct-getter.h
 create mode 100644 include/dynamic-graph/command-direct-setter.h

diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
index 4a20d45..c27a187 100644
--- a/include/CMakeLists.txt
+++ b/include/CMakeLists.txt
@@ -76,6 +76,9 @@ command-setter.h
 command-setter.t.cpp
 command-getter.h
 command-getter.t.cpp
+
+command-direct-getter.h
+command-direct-setter.h
 )
 
 # Recreate correct path for the headers
diff --git a/include/dynamic-graph/command-direct-getter.h b/include/dynamic-graph/command-direct-getter.h
new file mode 100644
index 0000000..6ea26ba
--- /dev/null
+++ b/include/dynamic-graph/command-direct-getter.h
@@ -0,0 +1,72 @@
+//
+// Copyright 2010 CNRS
+//
+// Author: Nicolas Mansard
+//
+// 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 __dg_command_direct_getter_h__
+#define __dg_command_direct_getter_h__
+
+/* Define a getter command directly on the attribute (no need to pass by
+ * an explicit function). A typical use is given here:
+ *     addCommand("getSize",
+ *                makeDirectGetter(*this,&_dimension,
+ *                                 docDirectGetter("dimension","int")));
+ *
+ */
+
+#include "dynamic-graph/command.h"
+#include <boost/assign/list_of.hpp>
+
+/* --- GETTER --------------------------------------------------------- */
+namespace dynamicgraph {
+  namespace command {
+
+    template <class E, typename T>
+      class DirectGetter
+      : public Command
+    {
+    public:
+      /// Pointer to method that sets paramter of type T
+      typedef T (E::*GetterMethod) () const;
+
+      /// Constructor
+    DirectGetter(E& entity,T* ptr,
+		 const std::string& docString)
+      : Command(entity, std::vector<Value::Type>(), docString),
+	T_ptr(ptr) {}
+
+    protected:
+      virtual Value doExecute() { return Value(*T_ptr); }
+    private:
+      T* T_ptr;
+    };
+
+    template <class E, typename T>
+      DirectGetter<E,T>*
+      makeDirectGetter( E& entity,T* ptr,
+			const std::string& docString)
+      { return  new DirectGetter<E,T>(entity,ptr,docString); }
+
+    std::string docDirectGetter( const std::string& name,
+				 const std::string& type )
+      {
+	return std::string("\nGet the ")+name+".\n\nNo input.\nReturn an "+type+".\n\n";
+      }
+
+  } // namespace command
+} // namespace dynamicgraph
+
+
+#endif // __dg_command_direct_getter_h__
diff --git a/include/dynamic-graph/command-direct-setter.h b/include/dynamic-graph/command-direct-setter.h
new file mode 100644
index 0000000..56a492c
--- /dev/null
+++ b/include/dynamic-graph/command-direct-setter.h
@@ -0,0 +1,75 @@
+//
+// Copyright 2010 CNRS
+//
+// Author: Nicolas Mansard
+//
+// 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 __dg_command_direct_setter_h__
+#define __dg_command_direct_setter_h__
+
+/* Define a setter command directly on the attribute (no need to pass by
+ * an explicit function). A typical use is given here:
+ *     addCommand("setSize",
+ *                makeDirectSetter(*this,&_dimension,
+ *                                 docDirectSetter("dimension","int")));
+ *
+ */
+
+#include "dynamic-graph/command.h"
+#include <boost/assign/list_of.hpp>
+
+/* --- SETTER --------------------------------------------------------- */
+namespace dynamicgraph {
+  namespace command {
+
+   template <class E, typename T>
+      class DirectSetter
+      : public Command
+    {
+    public:
+    DirectSetter(E& entity,T* ptr,const std::string& docString)
+      :Command(entity, boost::assign::list_of(ValueHelper<T>::TypeID), docString)
+	,T_ptr(ptr)
+      {}
+
+    protected:
+      virtual Value doExecute()
+      {
+	const std::vector<Value>& values = getParameterValues();
+	T val = values[0].value();
+	(*T_ptr) = val;
+	return Value(); // void
+      }
+    private:
+      T* T_ptr;
+    };
+
+    template <class E, typename T>
+      DirectSetter<E,T>*
+      makeDirectSetter( E& entity,T* ptr,
+			const std::string& docString)
+      { return  new DirectSetter<E,T>(entity,ptr,docString); }
+
+    std::string docDirectSetter( const std::string& name,
+				 const std::string& type )
+      {
+	return std::string("\nSet the ")+name+".\n\nInput:\n - a "
+	  +type+".\nVoid return.\n\n";
+      }
+
+  } // namespace command
+} // namespace dynamicgraph
+
+
+#endif // __dg_command_direct_setter_h__
-- 
GitLab