Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
dynamic-graph
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stack Of Tasks
dynamic-graph
Commits
4b49e534
Commit
4b49e534
authored
5 years ago
by
Joseph Mirabel
Committed by
olivier stasse
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add vector of value as value type.
parent
c42a9f30
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/dynamic-graph/value.h
+8
-0
8 additions, 0 deletions
include/dynamic-graph/value.h
src/command/value.cpp
+35
-0
35 additions, 0 deletions
src/command/value.cpp
tests/value.cpp
+21
-0
21 additions, 0 deletions
tests/value.cpp
with
64 additions
and
0 deletions
include/dynamic-graph/value.h
+
8
−
0
View file @
4b49e534
...
@@ -12,10 +12,13 @@
...
@@ -12,10 +12,13 @@
#include
<dynamic-graph/linear-algebra.h>
#include
<dynamic-graph/linear-algebra.h>
#include
<string>
#include
<string>
#include
<typeinfo>
#include
<typeinfo>
#include
<vector>
namespace
dynamicgraph
{
namespace
dynamicgraph
{
namespace
command
{
namespace
command
{
class
Value
;
class
Value
;
typedef
std
::
vector
<
Value
>
Values
;
class
DYNAMIC_GRAPH_DLLAPI
EitherType
{
class
DYNAMIC_GRAPH_DLLAPI
EitherType
{
public:
public:
EitherType
(
const
Value
&
value
);
EitherType
(
const
Value
&
value
);
...
@@ -29,6 +32,7 @@ public:
...
@@ -29,6 +32,7 @@ public:
operator
Vector
()
const
;
operator
Vector
()
const
;
operator
Eigen
::
MatrixXd
()
const
;
operator
Eigen
::
MatrixXd
()
const
;
operator
Eigen
::
Matrix4d
()
const
;
operator
Eigen
::
Matrix4d
()
const
;
operator
Values
()
const
;
private:
private:
const
Value
*
value_
;
const
Value
*
value_
;
...
@@ -47,6 +51,7 @@ public:
...
@@ -47,6 +51,7 @@ public:
VECTOR
,
VECTOR
,
MATRIX
,
MATRIX
,
MATRIX4D
,
MATRIX4D
,
VALUES
,
NB_TYPES
NB_TYPES
};
};
~
Value
();
~
Value
();
...
@@ -60,6 +65,7 @@ public:
...
@@ -60,6 +65,7 @@ public:
explicit
Value
(
const
Vector
&
value
);
explicit
Value
(
const
Vector
&
value
);
explicit
Value
(
const
Eigen
::
MatrixXd
&
value
);
explicit
Value
(
const
Eigen
::
MatrixXd
&
value
);
explicit
Value
(
const
Eigen
::
Matrix4d
&
value
);
explicit
Value
(
const
Eigen
::
Matrix4d
&
value
);
explicit
Value
(
const
Values
&
value
);
/// Copy constructor
/// Copy constructor
Value
(
const
Value
&
value
);
Value
(
const
Value
&
value
);
// Construct an empty value (None)
// Construct an empty value (None)
...
@@ -99,6 +105,8 @@ public:
...
@@ -99,6 +105,8 @@ public:
Vector
vectorValue
()
const
;
Vector
vectorValue
()
const
;
Eigen
::
MatrixXd
matrixXdValue
()
const
;
Eigen
::
MatrixXd
matrixXdValue
()
const
;
Eigen
::
Matrix4d
matrix4dValue
()
const
;
Eigen
::
Matrix4d
matrix4dValue
()
const
;
Values
valuesValue
()
const
;
const
Values
&
constValuesValue
()
const
;
Type
type_
;
Type
type_
;
const
void
*
const
value_
;
const
void
*
const
value_
;
};
};
...
...
This diff is collapsed.
Click to expand it.
src/command/value.cpp
+
35
−
0
View file @
4b49e534
...
@@ -29,6 +29,7 @@ EitherType::operator Vector() const { return value_->vectorValue(); }
...
@@ -29,6 +29,7 @@ EitherType::operator Vector() const { return value_->vectorValue(); }
EitherType
::
operator
Eigen
::
MatrixXd
()
const
{
return
value_
->
matrixXdValue
();
}
EitherType
::
operator
Eigen
::
MatrixXd
()
const
{
return
value_
->
matrixXdValue
();
}
EitherType
::
operator
Eigen
::
Matrix4d
()
const
{
return
value_
->
matrix4dValue
();
}
EitherType
::
operator
Eigen
::
Matrix4d
()
const
{
return
value_
->
matrix4dValue
();
}
EitherType
::
operator
Values
()
const
{
return
value_
->
valuesValue
();
}
void
Value
::
deleteValue
()
{
void
Value
::
deleteValue
()
{
switch
(
type_
)
{
switch
(
type_
)
{
...
@@ -59,6 +60,9 @@ void Value::deleteValue() {
...
@@ -59,6 +60,9 @@ void Value::deleteValue() {
case
MATRIX4D
:
case
MATRIX4D
:
delete
(
const
Eigen
::
Matrix4d
*
)
value_
;
delete
(
const
Eigen
::
Matrix4d
*
)
value_
;
break
;
break
;
case
VALUES
:
delete
(
const
Values
*
)
value_
;
break
;
default:
;
default:
;
}
}
}
}
...
@@ -78,6 +82,8 @@ Value::Value(const Eigen::MatrixXd &value)
...
@@ -78,6 +82,8 @@ Value::Value(const Eigen::MatrixXd &value)
:
type_
(
MATRIX
),
value_
(
new
Eigen
::
MatrixXd
(
value
))
{}
:
type_
(
MATRIX
),
value_
(
new
Eigen
::
MatrixXd
(
value
))
{}
Value
::
Value
(
const
Eigen
::
Matrix4d
&
value
)
Value
::
Value
(
const
Eigen
::
Matrix4d
&
value
)
:
type_
(
MATRIX4D
),
value_
(
new
Eigen
::
Matrix4d
(
value
))
{}
:
type_
(
MATRIX4D
),
value_
(
new
Eigen
::
Matrix4d
(
value
))
{}
Value
::
Value
(
const
Values
&
value
)
:
type_
(
VALUES
),
value_
(
new
Values
(
value
))
{}
Value
::
Value
(
const
Value
&
value
)
Value
::
Value
(
const
Value
&
value
)
:
type_
(
value
.
type_
),
value_
(
copyValue
(
value
))
{}
:
type_
(
value
.
type_
),
value_
(
copyValue
(
value
))
{}
...
@@ -116,6 +122,9 @@ void *copyValue(const Value &value) {
...
@@ -116,6 +122,9 @@ void *copyValue(const Value &value) {
case
Value
::
MATRIX4D
:
case
Value
::
MATRIX4D
:
copy
=
new
Eigen
::
Matrix4d
(
value
.
matrix4dValue
());
copy
=
new
Eigen
::
Matrix4d
(
value
.
matrix4dValue
());
break
;
break
;
case
Value
::
VALUES
:
copy
=
new
Values
(
value
.
valuesValue
());
break
;
default:
default:
abort
();
abort
();
}
}
...
@@ -200,6 +209,20 @@ Eigen::Matrix4d Value::matrix4dValue() const {
...
@@ -200,6 +209,20 @@ Eigen::Matrix4d Value::matrix4dValue() const {
"value is not a Eigen matrix4d"
);
"value is not a Eigen matrix4d"
);
}
}
Values
Value
::
valuesValue
()
const
{
if
(
type_
==
VALUES
)
return
*
((
const
Values
*
)
value_
);
throw
ExceptionAbstract
(
ExceptionAbstract
::
TOOLS
,
"value is not a vector of Value"
);
}
const
Values
&
Value
::
constValuesValue
()
const
{
if
(
type_
==
VALUES
)
return
*
((
const
Values
*
)
value_
);
throw
ExceptionAbstract
(
ExceptionAbstract
::
TOOLS
,
"value is not a vector of Value"
);
}
std
::
string
Value
::
typeName
(
Type
type
)
{
std
::
string
Value
::
typeName
(
Type
type
)
{
switch
(
type
)
{
switch
(
type
)
{
case
BOOL
:
case
BOOL
:
...
@@ -220,6 +243,8 @@ std::string Value::typeName(Type type) {
...
@@ -220,6 +243,8 @@ std::string Value::typeName(Type type) {
return
std
::
string
(
"matrixXd"
);
return
std
::
string
(
"matrixXd"
);
case
MATRIX4D
:
case
MATRIX4D
:
return
std
::
string
(
"matrix4d"
);
return
std
::
string
(
"matrix4d"
);
case
VALUES
:
return
std
::
string
(
"values"
);
default:
default:
return
std
::
string
(
"unknown"
);
return
std
::
string
(
"unknown"
);
}
}
...
@@ -255,6 +280,15 @@ std::ostream &operator<<(std::ostream &os, const Value &value) {
...
@@ -255,6 +280,15 @@ std::ostream &operator<<(std::ostream &os, const Value &value) {
case
Value
::
MATRIX4D
:
case
Value
::
MATRIX4D
:
os
<<
value
.
matrix4dValue
();
os
<<
value
.
matrix4dValue
();
break
;
break
;
case
Value
::
VALUES
:
{
const
std
::
vector
<
Value
>&
vals
=
value
.
constValuesValue
();
os
<<
"[ "
;
for
(
std
::
size_t
i
=
0
;
i
<
vals
.
size
();
++
i
)
os
<<
"Value("
<<
vals
[
i
]
<<
"), "
;
os
<<
"]"
;
}
break
;
default
:
default
:
return
os
;
return
os
;
}
}
...
@@ -272,6 +306,7 @@ template <>
...
@@ -272,6 +306,7 @@ template <>
const
Value
::
Type
ValueHelper
<
Eigen
::
MatrixXd
>::
TypeID
=
Value
::
MATRIX
;
const
Value
::
Type
ValueHelper
<
Eigen
::
MatrixXd
>::
TypeID
=
Value
::
MATRIX
;
template
<
>
template
<
>
const
Value
::
Type
ValueHelper
<
Eigen
::
Matrix4d
>::
TypeID
=
Value
::
MATRIX4D
;
const
Value
::
Type
ValueHelper
<
Eigen
::
Matrix4d
>::
TypeID
=
Value
::
MATRIX4D
;
template
<
>
const
Value
::
Type
ValueHelper
<
Values
>::
TypeID
=
Value
::
VALUES
;
}
// namespace command
}
// namespace command
}
// namespace dynamicgraph
}
// namespace dynamicgraph
This diff is collapsed.
Click to expand it.
tests/value.cpp
+
21
−
0
View file @
4b49e534
...
@@ -351,3 +351,24 @@ BOOST_AUTO_TEST_CASE(value_matrix4d) {
...
@@ -351,3 +351,24 @@ BOOST_AUTO_TEST_CASE(value_matrix4d) {
" 0 0 0 0"
));
" 0 0 0 0"
));
}
}
}
}
BOOST_AUTO_TEST_CASE
(
value_values
)
{
using
namespace
dynamicgraph
::
command
;
std
::
string
s1
(
"value #1"
);
double
d1
=
0.3
;
Value
vs1
(
s1
);
Value
vd1
(
d1
);
Values
values
;
values
.
push_back
(
vs1
);
values
.
push_back
(
vd1
);
Value
vvalues
(
values
);
BOOST_CHECK_EQUAL
(
vvalues
.
type
(),
Value
::
VALUES
);
const
Values
&
vs
=
vvalues
.
constValuesValue
();
BOOST_CHECK_EQUAL
(
vs
.
size
(),
values
.
size
());
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment