command.cpp
Go to the documentation of this file.
1 //
2 // Copyright 2010 CNRS
3 //
4 // Author: Florent Lamiraux
5 //
6 
8 
9 #include <sstream>
10 
12 
13 namespace dynamicgraph {
14 namespace command {
15 
16 const std::vector<Value::Type> Command::EMPTY_ARG = std::vector<Value::Type>();
17 
19 Command::Command(Entity &entity, const std::vector<Value::Type> &valueTypes,
20  const std::string &docstring)
21  : owner_(entity), valueTypeVector_(valueTypes), docstring_(docstring) {}
22 
23 const std::vector<Value::Type> &Command::valueTypes() const {
24  return valueTypeVector_;
25 }
26 
27 void Command::setParameterValues(const std::vector<Value> &values) {
28  const std::vector<Value::Type> &paramTypes = valueTypes();
29  // Check that number of parameters is correct
30  if (values.size() != paramTypes.size()) {
32  "wrong number of parameters");
33  }
34  // Check that each parameter is of correct type
35  for (unsigned int iParam = 0; iParam < values.size(); iParam++) {
36  if (values[iParam].type() != paramTypes[iParam]) {
37  std::stringstream ss;
38  ss << "argument " << iParam
39  << " is of wrong type: " << Value::typeName(paramTypes[iParam])
40  << " expected, got " << Value::typeName(values[iParam].type());
42  }
43  }
44  // Copy vector of values in private part
45  valueVector_ = values;
46 }
47 
48 const std::vector<Value> &Command::getParameterValues() const {
49  return valueVector_;
50 }
51 
53 
55 std::string Command::getDocstring() const { return docstring_; }
56 } // namespace command
57 } // namespace dynamicgraph
dynamicgraph::command::Command::doExecute
virtual Value doExecute()=0
Specific action performed by the command.
dynamicgraph
dynamicgraph::command::Command::Command
Command(Entity &entity, const std::vector< Value::Type > &valueTypes, const std::string &docstring)
Definition: command.cpp:19
dynamicgraph::Entity
This class represents an entity, i.e. a generic computational unit that provides input and output sig...
Definition: include/dynamic-graph/entity.h:52
dynamicgraph::command::Command::getParameterValues
const std::vector< Value > & getParameterValues() const
Get parameter values.
Definition: command.cpp:48
dynamicgraph::command::Command::EMPTY_ARG
static const std::vector< Value::Type > EMPTY_ARG
Definition: command.h:68
dynamicgraph::command::Command::setParameterValues
void setParameterValues(const std::vector< Value > &values)
Set parameter values.
Definition: command.cpp:27
command.h
dynamicgraph::command::Command::valueTypeVector_
std::vector< Value::Type > valueTypeVector_
Definition: command.h:63
dynamicgraph::command::Command::getDocstring
std::string getDocstring() const
Get documentation string.
Definition: command.cpp:55
dynamicgraph::command::Command::valueTypes
const std::vector< Value::Type > & valueTypes() const
Return the value type of all parameters.
Definition: command.cpp:23
dynamicgraph::ExceptionAbstract::TOOLS
@ TOOLS
Definition: exception-abstract.h:72
dynamicgraph::ExceptionAbstract
Abstract root class for all dynamic-graph exceptions.
Definition: exception-abstract.h:31
dynamicgraph::command::Command::~Command
virtual ~Command()
Definition: command.cpp:18
dynamicgraph::command::Command::docstring_
std::string docstring_
Definition: command.h:65
dynamicgraph::command::Command::valueVector_
std::vector< Value > valueVector_
Definition: command.h:64
dynamicgraph::ExceptionAbstract::ABSTRACT
@ ABSTRACT
Definition: exception-abstract.h:68
dynamicgraph::command::Command::owner_
Entity & owner_
Definition: command.h:62
dynamicgraph::command::Command::execute
Value execute()
Execute the command after checking parameters.
Definition: command.cpp:52
dynamicgraph::command::Value::typeName
static std::string typeName(Type type)
Return the name of the type.
Definition: src/command/value.cpp:284
dynamicgraph::command::Value
This class implements a variant design pattern to handle basic types in Command.
Definition: value.h:51
dynamicgraph::command::Command::owner
Entity & owner()
Get a reference to the Entity owning this command.
Definition: command.cpp:54
exception-abstract.h


dynamic-graph
Author(s): Nicolas Mansard, Olivier Stasse
autogenerated on Fri Aug 2 2024 08:36:38