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
526f4cab
Commit
526f4cab
authored
14 years ago
by
Florent Lamiraux
Browse files
Options
Downloads
Patches
Plain Diff
Fix memory issue and changed class name AnyType -> EitherType.
* include/dynamic-graph/value.h, * src/command/value.cpp.
parent
4b298e9f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/dynamic-graph/value.h
+6
-5
6 additions, 5 deletions
include/dynamic-graph/value.h
src/command/value.cpp
+18
-10
18 additions, 10 deletions
src/command/value.cpp
with
24 additions
and
15 deletions
include/dynamic-graph/value.h
+
6
−
5
View file @
526f4cab
...
...
@@ -27,14 +27,15 @@
namespace
dynamicgraph
{
namespace
command
{
class
Value
;
class
Any
Type
{
class
Either
Type
{
public:
AnyType
(
const
Value
&
value
);
EitherType
(
const
Value
&
value
);
~
EitherType
();
operator
int
()
const
;
operator
double
()
const
;
operator
std
::
string
()
const
;
private:
const
Value
&
value_
;
const
Value
*
value_
;
};
class
DYNAMICGRAPH_EXPORT
Value
{
...
...
@@ -68,14 +69,14 @@ namespace dynamicgraph {
/// \endcode
/// The first assignment will succeed, while the second one will throw
/// an exception.
const
Any
Type
value
()
const
;
const
Either
Type
value
()
const
;
/// Return the name of the type
static
std
::
string
typeName
(
Type
type
);
/// Output in a stream
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
Value
&
value
);
private
:
friend
class
Any
Type
;
friend
class
Either
Type
;
const
double
doubleValue
()
const
;
const
int
intValue
()
const
;
const
std
::
string
stringValue
()
const
;
...
...
This diff is collapsed.
Click to expand it.
src/command/value.cpp
+
18
−
10
View file @
526f4cab
...
...
@@ -21,20 +21,26 @@
namespace
dynamicgraph
{
namespace
command
{
AnyType
::
Any
Type
(
const
Value
&
value
)
:
value_
(
value
)
EitherType
::
Either
Type
(
const
Value
&
value
)
:
value_
(
new
Value
(
value
)
)
{
}
AnyType
::
operator
int
()
const
EitherType
::~
EitherType
()
{
delete
value_
;
}
EitherType
::
operator
int
()
const
{
return
value_
.
intValue
();
return
value_
->
intValue
();
}
Any
Type
::
operator
double
()
const
Either
Type
::
operator
double
()
const
{
return
value_
.
doubleValue
();
return
value_
->
doubleValue
();
}
Any
Type
::
operator
std
::
string
()
const
Either
Type
::
operator
std
::
string
()
const
{
return
value_
.
stringValue
();
return
value_
->
stringValue
();
}
Value
::~
Value
()
...
...
@@ -87,6 +93,9 @@ namespace dynamicgraph {
std
::
cout
<<
"Value copy constructor: string"
<<
std
::
endl
;
value_
=
new
std
::
string
(
value
.
stringValue
());
break
;
default:
type_
=
NONE
;
value_
=
NULL
;
}
}
...
...
@@ -95,9 +104,9 @@ namespace dynamicgraph {
std
::
cout
<<
"Value empty constructor"
<<
std
::
endl
;
}
const
Any
Type
Value
::
value
()
const
const
Either
Type
Value
::
value
()
const
{
return
Any
Type
(
*
this
);
return
Either
Type
(
*
this
);
}
Value
::
Type
Value
::
type
()
const
...
...
@@ -110,7 +119,6 @@ namespace dynamicgraph {
double
result
;
if
(
type_
==
DOUBLE
)
result
=
*
((
double
*
)
value_
);
std
::
cout
<<
"Value::doubleValue = "
<<
result
<<
std
::
endl
;
return
result
;
throw
ExceptionAbstract
(
ExceptionAbstract
::
TOOLS
,
"value is not a double"
);
...
...
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