dynamic-graph  4.4.3
Dynamic graph library
value.h
1 //
2 // Copyright 2010 CNRS
3 //
4 // Author: Florent Lamiraux
5 //
6 
7 #ifndef DYNAMIC_GRAPH_VALUE_H
8 #define DYNAMIC_GRAPH_VALUE_H
9 
10 #include <dynamic-graph/linear-algebra.h>
11 
12 #include <cassert>
13 #include <string>
14 #include <typeinfo>
15 #include <vector>
16 
17 #include "dynamic-graph/dynamic-graph-api.h"
18 
19 namespace dynamicgraph {
20 namespace command {
21 class Value;
22 typedef std::vector<Value> Values;
23 
24 class DYNAMIC_GRAPH_DLLAPI EitherType {
25  public:
26  EitherType(const Value &value);
27  ~EitherType();
28  operator bool() const;
29  operator unsigned() const;
30  operator unsigned long int() const;
31  operator int() const;
32  operator long int() const;
33  operator float() const;
34  operator double() const;
35  operator std::string() const;
36  operator Vector() const;
37  operator Eigen::MatrixXd() const;
38  operator Eigen::Matrix4d() const;
39  operator Values() const;
40 
41  private:
42  const Value *value_;
43 };
44 
50 class DYNAMIC_GRAPH_DLLAPI Value {
51  public:
52  enum Type {
53  NONE,
54  BOOL,
55  UNSIGNED,
56  UNSIGNEDLONGINT,
57  INT,
58  LONGINT,
59  FLOAT,
60  DOUBLE,
61  STRING,
62  VECTOR,
63  MATRIX,
64  MATRIX4D,
65  VALUES,
66  NB_TYPES
67  };
68  ~Value();
69  void deleteValue();
70  explicit Value(const bool &value);
71  explicit Value(const unsigned &value);
72  explicit Value(const unsigned long int &value);
73  explicit Value(const int &value);
74  explicit Value(const long int &value);
75  explicit Value(const float &value);
76  explicit Value(const double &value);
77  explicit Value(const std::string &value);
78  explicit Value(const Vector &value);
79  explicit Value(const Eigen::MatrixXd &value);
80  explicit Value(const Eigen::Matrix4d &value);
81  explicit Value(const Values &value);
83  Value(const Value &value);
84  // Construct an empty value (None)
85  explicit Value();
86  // operator assignement
87  Value operator=(const Value &value);
88  // Equality operator
89  bool operator==(const Value &other) const;
91  Type type() const;
92 
104  const EitherType value() const;
106  static std::string typeName(Type type);
107 
109  DYNAMIC_GRAPH_DLLAPI friend std::ostream &operator<<(std::ostream &os,
110  const Value &value);
111 
112  public:
113  friend class EitherType;
114  bool boolValue() const;
115  unsigned unsignedValue() const;
116  unsigned long int unsignedlongintValue() const;
117  int intValue() const;
118  long int longintValue() const;
119  float floatValue() const;
120  double doubleValue() const;
121  std::string stringValue() const;
122  Vector vectorValue() const;
123  Eigen::MatrixXd matrixXdValue() const;
124  Eigen::Matrix4d matrix4dValue() const;
125  Values valuesValue() const;
126  const Values &constValuesValue() const;
127  Type type_;
128  const void *const value_;
129 };
130 
131 /* ---- HELPER ---------------------------------------------------------- */
132 // Note: to ensure the WIN32 compatibility, it is necessary to export
133 // the template specialization. Also, it is forbidden to do the template
134 // specialization declaration in the header file, for the same reason.
135 template <typename T>
136 struct DYNAMIC_GRAPH_DLLAPI ValueHelper {
137  static const Value::Type TypeID;
138 };
139 } // namespace command
140 } // namespace dynamicgraph
141 
142 #endif // DYNAMIC_GRAPH_VALUE_H
dynamicgraph::command::ValueHelper
Definition: value.h:136
dynamicgraph
Definition: command-bind.h:30
dynamicgraph::command::EitherType
Definition: value.h:24
dynamicgraph::command::Value
This class implements a variant design pattern to handle basic types in Command.
Definition: value.h:50