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
This class represents an entity, i.e. a generic computational unit that provides input and output sig...
This class implements a variant design pattern to handle basic types in Command.
Definition: value.h:50
Command(Entity &entity, const std::vector< Value::Type > &valueTypes, const std::string &docstring)
Definition: command.cpp:19
void setParameterValues(const std::vector< Value > &values)
Set parameter values.
Definition: command.cpp:27
virtual Value doExecute()=0
Specific action performed by the command.
std::vector< Value::Type > valueTypeVector_
Definition: command.h:63
Value execute()
Execute the command after checking parameters.
Definition: command.cpp:52
Abstract root class for all dynamic-graph exceptions.
static const std::vector< Value::Type > EMPTY_ARG
Definition: command.h:68
std::vector< Value > valueVector_
Definition: command.h:64
Entity & owner()
Get a reference to the Entity owning this command.
Definition: command.cpp:54
std::string getDocstring() const
Get documentation string.
Definition: command.cpp:55
const std::vector< Value > & getParameterValues() const
Get parameter values.
Definition: command.cpp:48
const std::vector< Value::Type > & valueTypes() const
Return the value type of all parameters.
Definition: command.cpp:23
static std::string typeName(Type type)
Return the name of the type.


dynamic-graph
Author(s): Nicolas Mansard, Olivier Stasse
autogenerated on Sun Jun 25 2023 02:06:03