Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
hydra-image-processor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
OpenSource
hydra-image-processor
Commits
a0c285a5
Commit
a0c285a5
authored
6 years ago
by
Mark Winter
Browse files
Options
Downloads
Patches
Plain Diff
Use RuntimeError base type for creating error format messages
parent
fa3291b9
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
src/c/WrapCmds/ArgConverter.h
+6
-3
6 additions, 3 deletions
src/c/WrapCmds/ArgConverter.h
src/c/WrapCmds/ScriptHelpers.h
+34
-31
34 additions, 31 deletions
src/c/WrapCmds/ScriptHelpers.h
with
40 additions
and
34 deletions
src/c/WrapCmds/ArgConverter.h
+
6
−
3
View file @
a0c285a5
...
...
@@ -27,7 +27,7 @@ namespace Script
using
ArgConvertError
=
typename
Script
::
Converter
::
ArgConvertError
;
// General argument error exception
class
ArgError
:
public
std
::
r
untime
_e
rror
class
ArgError
:
public
R
untime
E
rror
{
static
std
::
string
make_convert_msg
(
const
ArgConvertError
&
ace
)
{
...
...
@@ -36,10 +36,13 @@ namespace Script
public
:
ArgError
()
=
delete
;
ArgError
(
const
char
*
msg
)
:
std
::
runtime_error
(
msg
)
template
<
typename
...
Args
>
ArgError
(
const
char
*
fmt
,
Args
&&
...
args
)
:
RuntimeError
(
fmt
,
std
::
forward
<
Args
>
(
args
)...)
{}
ArgError
(
const
ArgConvertError
&
ace
)
:
std
::
runtime_e
rror
(
make_convert_msg
(
ace
))
ArgError
(
const
ArgConvertError
&
ace
)
:
ArgE
rror
(
make_convert_msg
(
ace
)
.
c_str
()
)
{}
};
...
...
This diff is collapsed.
Click to expand it.
src/c/WrapCmds/ScriptHelpers.h
+
34
−
31
View file @
a0c285a5
...
...
@@ -12,15 +12,6 @@
#include
<algorithm>
#undef snprintf
#ifdef _WIN32
#define SNPRINTF std::snprintf
#else
#define SNPRINTF std::snprintf
#endif
#define BEGIN_TYPE_MAP(EnumType,ScriptEngine) \
typedef EnumType IdType; \
template <typename T> struct TypeToIdMap \
...
...
@@ -47,36 +38,48 @@ namespace Script
std
::
vector
<
std
::
size_t
>
dims
;
};
// Generic script conversion errors used by engine-specific converters
class
ConvertErrors
// Helper class for creating format-string runtime errors
class
RuntimeError
:
public
std
::
runtime_error
{
public:
// Conversion exception types
class
ArgConvertError
:
public
std
::
runtime_error
template
<
typename
...
Args
>
static
std
::
unique_ptr
<
char
[]
>
make_msg
(
const
char
*
fmt
,
Args
&&
...
args
)
{
template
<
typename
...
Args
>
static
std
::
unique_ptr
<
char
[]
>
make_msg
(
const
char
*
fmt
,
Args
...
args
)
{
size_t
size
=
SNPRINTF
(
nullptr
,
0
,
fmt
,
args
...);
size_t
size
=
std
::
snprintf
(
nullptr
,
0
,
fmt
,
std
::
forward
<
Args
>
(
args
)...);
std
::
unique_ptr
<
char
[]
>
msgPtr
(
new
char
[
size
+
1
]);
SNPRINTF
(
msgPtr
.
get
(),
size
,
fmt
,
args
...);
return
msgPtr
;
}
std
::
unique_ptr
<
char
[]
>
msgPtr
(
new
char
[
size
+
1
]);
std
::
snprintf
(
msgPtr
.
get
(),
size
,
fmt
,
std
::
forward
<
Args
>
(
args
)
...);
return
msgPtr
;
}
static
std
::
unique_ptr
<
char
[]
>
make_msg
(
const
char
*
fmt
)
{
size_t
size
=
std
::
strlen
(
fmt
);
static
std
::
unique_ptr
<
char
[]
>
make_msg
(
const
char
*
fmt
)
{
size_t
size
=
std
::
strlen
(
fmt
);
std
::
unique_ptr
<
char
[]
>
msgPtr
(
new
char
[
size
+
1
]);
std
::
strncpy
(
msgPtr
.
get
(),
fmt
,
size
);
return
msgPtr
;
}
std
::
unique_ptr
<
char
[]
>
msgPtr
(
new
char
[
size
+
1
]);
std
::
strncpy
(
msgPtr
.
get
(),
fmt
,
size
);
return
msgPtr
;
}
public
:
template
<
typename
...
Args
>
RuntimeError
(
const
char
*
fmt
,
Args
&&
...
args
)
:
std
::
runtime_error
(
make_msg
(
fmt
,
std
::
forward
<
Args
>
(
args
)...).
get
())
{}
};
// Generic script conversion errors used by engine-specific converters
class
ConvertErrors
{
public:
// Conversion exception types
class
ArgConvertError
:
public
RuntimeError
{
public:
template
<
typename
...
Args
>
ArgConvertError
(
const
char
*
argName
,
const
char
*
fmt
,
Args
...
args
)
:
std
::
r
untime
_e
rror
(
make_msg
(
fmt
,
args
...).
get
()
),
argName
(
argName
)
ArgConvertError
(
const
char
*
argName
,
const
char
*
fmt
,
Args
&&
...
args
)
:
R
untime
E
rror
(
fmt
,
std
::
forward
<
Args
>
(
args
)...
),
argName
(
argName
)
{}
const
char
*
getArgName
()
const
{
return
argName
;
}
...
...
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