Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Simox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Florian Leander Singer
Simox
Commits
838bc724
Commit
838bc724
authored
5 years ago
by
Rainer Kartmann
Browse files
Options
Downloads
Patches
Plain Diff
Fix check macros
parent
44f9bcfa
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
VirtualRobot/VirtualRobotChecks.cpp
+5
-3
5 additions, 3 deletions
VirtualRobot/VirtualRobotChecks.cpp
VirtualRobot/VirtualRobotChecks.h
+45
-31
45 additions, 31 deletions
VirtualRobot/VirtualRobotChecks.h
with
50 additions
and
34 deletions
VirtualRobot/VirtualRobotChecks.cpp
+
5
−
3
View file @
838bc724
...
...
@@ -17,20 +17,22 @@ namespace VirtualRobot
const
std
::
string
&
hint
,
const
std
::
string
&
lhs
,
const
std
::
string
&
rhs
)
{
static
const
std
::
string
newLine
=
"
\n
"
;
std
::
stringstream
ss
;
ss
<<
"Condition '"
<<
condition
<<
"' failed."
;
if
(
!
(
lhs
.
empty
()
&&
rhs
.
empty
()))
{
ss
<<
"
\n
(lhs = "
<<
lhs
<<
", rhs = "
<<
rhs
<<
")"
;
ss
<<
newLine
<<
"
(lhs = "
<<
lhs
<<
", rhs = "
<<
rhs
<<
")"
;
}
if
(
!
hint
.
empty
())
{
ss
<<
"
\n
Hint: "
<<
hint
;
ss
<<
newLine
<<
"
Hint: "
<<
hint
;
}
ss
<<
"
\n
(line "
<<
line
<<
" in "
<<
function
<<
"() in "
<<
file
<<
")"
;
ss
<<
newLine
<<
"
(line "
<<
line
<<
" in "
<<
function
<<
"() in "
<<
file
<<
")"
;
return
ss
.
str
();
}
...
...
This diff is collapsed.
Click to expand it.
VirtualRobot/VirtualRobotChecks.h
+
45
−
31
View file @
838bc724
...
...
@@ -8,28 +8,34 @@
namespace
VirtualRobot
{
/**
* @brief Exception class thrown by VR_CHECK_* macros ("soft" assertions).
*/
class
VIRTUAL_ROBOT_IMPORT_EXPORT
VirtualRobotCheckException
:
public
VirtualRobotException
{
public:
/// Construct with condition and meta information as well as optional hint.
VirtualRobotCheckException
(
const
std
::
string
&
condition
,
const
std
::
string
&
file
name
,
int
line
,
const
std
::
string
&
function
,
const
std
::
string
&
file
,
int
line
,
const
std
::
string
&
function
,
const
std
::
string
&
hint
=
""
);
/// Construct with left- and right-hand-side operators.
template
<
typename
LhsT
,
typename
RhsT
>
VirtualRobotCheckException
(
const
std
::
string
&
condition
,
const
LhsT
&
lhs
,
const
RhsT
&
rhs
,
const
std
::
string
&
file
name
,
int
line
,
const
std
::
string
&
function
,
const
std
::
string
&
file
,
int
line
,
const
std
::
string
&
function
,
const
std
::
string
&
hint
=
""
)
:
VirtualRobotException
(
makeMsg
(
condition
,
file
name
,
line
,
function
,
toString
(
lhs
),
toString
(
rhs
)
,
hint
))
makeMsg
(
condition
,
file
,
line
,
function
,
hint
,
toString
(
lhs
),
toString
(
rhs
)))
{}
private
:
/// Convert `t` to a string using its << operator.
template
<
typename
T
>
static
std
::
string
toString
(
const
T
&
t
)
{
...
...
@@ -38,6 +44,7 @@ namespace VirtualRobot
return
ss
.
str
();
}
/// Make the exception message.
static
std
::
string
makeMsg
(
const
std
::
string
&
condition
,
const
std
::
string
&
file
,
int
line
,
const
std
::
string
&
function
,
...
...
@@ -47,68 +54,75 @@ namespace VirtualRobot
};
/**
* Check the given condition.
* @throw VirtualRobotCheckException If `condition``evaluates to false.
*/
#define VR_CHECK_HINT(condition, hint) \
do { \
if( !(
express
ion) ) { \
if( !(
condit
ion) ) { \
throw ::VirtualRobot::VirtualRobotCheckException( \
#condition, __FILE__, __LINE__, __FUNCTION__, hint); \
} \
} while(0);
/**
* Check the given condition.
* @throw VirtualRobotCheckException If `condition``evaluates to false.
*/
#define VR_CHECK(condition) \
VR_CHECK_HINT(condition, "")
#define VR_CHECK_COMPARISON_HINT(lhs, rhs, cmp, hint) \
do { \
if( !(lhs cmp rhs) ) {\
if( !(
(
lhs
)
cmp
(
rhs)
)
) {
\
throw ::VirtualRobot::VirtualRobotCheckException( \
#lhs " " #cmp " " #rhs, lhs, rhs, __FILE__, __LINE__, __FUNCTION__, hint); \
} \
} while(0)
#define VR_CHECK_COMPARISON
_HINT
(lhs, rhs, cmp) \
VR_CHECK_HINT(lhs, rhs, cmp, "")
#define VR_CHECK_COMPARISON(lhs, rhs, cmp) \
VR_CHECK_
COMPARISON_
HINT(lhs, rhs, cmp, "")
#define VR_CHECK_EQUAL(lhs, rhs) VR_CHECK_COMPARIS
I
ON(lhs, rhs, ==)
#define VR_CHECK_EQUAL_HINT(lhs, rhs, hint) VR_CHECK_COMPARIS
I
ON(lhs, rhs, ==, hint)
#define VR_CHECK_EQUAL(lhs, rhs) VR_CHECK_COMPARISON(lhs, rhs, ==)
#define VR_CHECK_EQUAL_HINT(lhs, rhs, hint) VR_CHECK_COMPARISON
_HINT
(lhs, rhs, ==, hint)
#define VR_CHECK_NOT_EQUAL(lhs, rhs) VR_CHECK_COMPARIS
I
ON(lhs, rhs, !=)
#define VR_CHECK_NOT_EQUAL_HINT(lhs, rhs, hint) VR_CHECK_COMPARIS
I
ON(lhs, rhs, !=, hint)
#define VR_CHECK_NOT_EQUAL(lhs, rhs) VR_CHECK_COMPARISON(lhs, rhs, !=)
#define VR_CHECK_NOT_EQUAL_HINT(lhs, rhs, hint) VR_CHECK_COMPARISON
_HINT
(lhs, rhs, !=, hint)
#define VR_CHECK_LESS(lhs, rhs) VR_CHECK_COMPARISON(lhs, rhs, <)
#define VR_CHECK_LESS_HINT(lhs, rhs, hint) VR_CHECK_COMPARISON_HINT(lhs, rhs, <, hint)
#define VR_CHECK_LESS(lhs, rhs) VR_CHECK_COMPARISION(lhs, rhs, <)
#define VR_CHECK_LESS_HINT(lhs, rhs, hint) VR_CHECK_COMPARISION(lhs, rhs, <, hint)
#define VR_CHECK_LESS_EQUAL(lhs, rhs) VR_CHECK_COMPARISION(lhs, rhs, <=)
#define VR_CHECK_LESS_EQUAL_HINT(lhs, rhs, hint) VR_CHECK_COMPARISION(lhs, rhs, <=, hint)
#define VR_CHECK_LESS_EQUAL(lhs, rhs) VR_CHECK_COMPARISON(lhs, rhs, <=)
#define VR_CHECK_LESS_EQUAL_HINT(lhs, rhs, hint) VR_CHECK_COMPARISON_HINT(lhs, rhs, <=, hint)
#define VR_CHECK_GREATER(lhs, rhs) VR_CHECK_COMPARIS
I
ON(lhs, rhs, >)
#define VR_CHECK_GREATER_HINT(lhs, rhs, hint) VR_CHECK_COMPARIS
I
ON(lhs, rhs, >, hint)
#define VR_CHECK_GREATER(lhs, rhs) VR_CHECK_COMPARISON(lhs, rhs, >)
#define VR_CHECK_GREATER_HINT(lhs, rhs, hint) VR_CHECK_COMPARISON
_HINT
(lhs, rhs, >, hint)
#define VR_CHECK_GREATER_EQUAL(lhs, rhs) VR_CHECK_COMPARIS
I
ON(lhs, rhs, >=)
#define VR_CHECK_GREATER_EQUAL_HINT(lhs, rhs, hint) VR_CHECK_COMPARIS
I
ON(lhs, rhs, >=, hint)
#define VR_CHECK_GREATER_EQUAL(lhs, rhs) VR_CHECK_COMPARISON(lhs, rhs, >=)
#define VR_CHECK_GREATER_EQUAL_HINT(lhs, rhs, hint) VR_CHECK_COMPARISON
_HINT
(lhs, rhs, >=, hint)
#define VR_CHECK_NONNEGATIVE(value) VR_CHECK_GREATER_EQUAL(value, 0)
#define VR_CHECK_NONNEGATIVE_HINT(value, hint) VR_CHECK_GREATER_EQUAL(value, 0, hint)
#define VR_CHECK_NONNEGATIVE_HINT(value, hint) VR_CHECK_GREATER_EQUAL
_HINT
(value, 0, hint)
#define VR_CHECK_POSITIVE(value) VR_CHECK_GREATER(value, 0)
#define VR_CHECK_POSITIVE_HINT(value, hint) VR_CHECK_GREATER(value, 0, hint)
#define VR_CHECK_FITS_SIZE(value, size) \
#define VR_CHECK_POSITIVE_HINT(value, hint) VR_CHECK_GREATER
_HINT
(value, 0, hint)
#define VR_CHECK_FITS_SIZE(value, size) \
VR_CHECK_NONNEGATIVE(value); \
VR_CHECK_LESS(value, size)
#define VR_CHECK_FITS_SIZE_HINT(value, size, hint) \
VR_CHECK_NONNEGATIVE
(
value
,
hint
);
\
VR_CHECK_LESS
(
value
,
size
,
hint
)
#define VR_CHECK_FITS_SIZE_HINT(value, size, hint) \
VR_CHECK_NONNEGATIVE
_HINT
(value, hint); \
VR_CHECK_LESS
_HINT
(value, size, hint)
...
...
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