Skip to content
Snippets Groups Projects
Commit 4b298e9f authored by Florent Lamiraux's avatar Florent Lamiraux
Browse files

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.
parent 42228a1f
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
//
// 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
//
// 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
#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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment