GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/command/command.cpp Lines: 24 25 96.0 %
Date: 2023-03-15 12:04:10 Branches: 21 36 58.3 %

Line Branch Exec Source
1
//
2
// Copyright 2010 CNRS
3
//
4
// Author: Florent Lamiraux
5
//
6
7
#include "dynamic-graph/command.h"
8
9
#include <sstream>
10
11
#include "dynamic-graph/exception-abstract.h"
12
13
namespace dynamicgraph {
14
namespace command {
15
16
const std::vector<Value::Type> Command::EMPTY_ARG = std::vector<Value::Type>();
17
18
20
Command::~Command() {}
19
31
Command::Command(Entity &entity, const std::vector<Value::Type> &valueTypes,
20
31
                 const std::string &docstring)
21
31
    : owner_(entity), valueTypeVector_(valueTypes), docstring_(docstring) {}
22
23
9
const std::vector<Value::Type> &Command::valueTypes() const {
24
9
  return valueTypeVector_;
25
}
26
27
9
void Command::setParameterValues(const std::vector<Value> &values) {
28
9
  const std::vector<Value::Type> &paramTypes = valueTypes();
29
  // Check that number of parameters is correct
30
9
  if (values.size() != paramTypes.size()) {
31
    throw ExceptionAbstract(ExceptionAbstract::ABSTRACT,
32

1
                            "wrong number of parameters");
33
  }
34
  // Check that each parameter is of correct type
35
23
  for (unsigned int iParam = 0; iParam < values.size(); iParam++) {
36
16
    if (values[iParam].type() != paramTypes[iParam]) {
37
2
      std::stringstream ss;
38

1
      ss << "argument " << iParam
39
1
         << " is of wrong type: " << Value::typeName(paramTypes[iParam])
40



2
         << " expected, got " << Value::typeName(values[iParam].type());
41

1
      throw ExceptionAbstract(ExceptionAbstract::TOOLS, ss.str());
42
    }
43
  }
44
  // Copy vector of values in private part
45
7
  valueVector_ = values;
46
7
}
47
48
23
const std::vector<Value> &Command::getParameterValues() const {
49
23
  return valueVector_;
50
}
51
52
11
Value Command::execute() { return doExecute(); }
53
54
6
Entity &Command::owner() { return owner_; }
55
6
std::string Command::getDocstring() const { return docstring_; }
56
}  // namespace command
57
}  // namespace dynamicgraph