Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
wolf
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
mobile_robotics
wolf_projects
wolf_lib
wolf
Merge requests
!408
Resolve "int and unsigned int parameters warnings"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "int and unsigned int parameters warnings"
392-int-and-unsigned-int-parameters-warnings
into
devel
Overview
0
Commits
1
Pipelines
2
Changes
5
Merged
Joan Vallvé Navarro
requested to merge
392-int-and-unsigned-int-parameters-warnings
into
devel
4 years ago
Overview
0
Commits
1
Pipelines
2
Changes
5
Expand
Closes
#392 (closed)
Edited
4 years ago
by
Joan Vallvé Navarro
0
0
Merge request reports
Viewing commit
c250ce1c
Show latest version
5 files
+
105
−
22
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
5
Search (e.g. *.vue) (Ctrl+P)
c250ce1c
bad param type in yaml throwing runtime_error
· c250ce1c
Joan Vallvé Navarro
authored
4 years ago
include/core/utils/converter.h
+
13
−
4
Options
@@ -17,6 +17,7 @@
#include
<vector>
#include
<stack>
#include
<list>
#include
<math.h>
/**
@file
@@ -96,13 +97,21 @@ struct converter<utils::list<A>>{
template
<
>
struct
converter
<
int
>
{
static
int
convert
(
std
::
string
val
){
return
stod
(
val
);
double
res
;
if
(
modf
(
stod
(
val
),
&
res
)
>
0
)
throw
std
::
runtime_error
(
"Invalid conversion to int: The number contains decimals: "
+
val
);
return
res
;
}
};
template
<
>
struct
converter
<
unsigned
int
>
{
static
unsigned
int
convert
(
std
::
string
val
){
return
stod
(
val
);
double
res
;
if
(
modf
(
stod
(
val
),
&
res
)
>
0
)
throw
std
::
runtime_error
(
"Invalid conversion to unsigned int: The number contains decimals: "
+
val
);
if
(
res
<
0
)
throw
std
::
runtime_error
(
"Invalid conversion to unsigned int: The number is negative: "
+
val
);
return
res
;
}
};
template
<
>
@@ -114,8 +123,8 @@ struct converter<double>{
template
<
>
struct
converter
<
bool
>
{
static
bool
convert
(
std
::
string
val
){
if
(
val
==
"true"
)
return
true
;
else
if
(
val
==
"false"
)
return
false
;
if
(
val
==
"true"
or
val
==
"True"
or
val
==
"TRUE"
)
return
true
;
else
if
(
val
==
"false"
or
val
==
"False"
or
val
==
"FALSE"
)
return
false
;
else
throw
std
::
runtime_error
(
"Invalid conversion to bool (Must be either
\"
true
\"
or
\"
false
\"
). String provided: "
+
val
);
}
};
Loading