Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-xt
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
ag-ohlberger
dune-community
dune-xt
Commits
09baef44
Unverified
Commit
09baef44
authored
7 years ago
by
René Fritze
Browse files
Options
Downloads
Patches
Plain Diff
[fixed_map] make usable with non-printable keys
parent
d925e65c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dune/xt/common/fixed_map.hh
+26
-2
26 additions, 2 deletions
dune/xt/common/fixed_map.hh
dune/xt/common/test/fixed_map.cc
+11
-0
11 additions, 0 deletions
dune/xt/common/test/fixed_map.cc
with
37 additions
and
2 deletions
dune/xt/common/fixed_map.hh
+
26
−
2
View file @
09baef44
...
...
@@ -129,6 +129,30 @@ private:
typedef
FixedMap
<
key_imp
,
T
,
nin
>
ThisType
;
template
<
class
K
>
// for sfinae to work this needs to be a template although the type is already fixed
typename
std
::
enable_if
<
std
::
is_convertible
<
K
,
std
::
string
>::
value
,
std
::
string
>::
type
range_error_message
(
K
key
)
const
{
std
::
stringstream
ss
;
ss
<<
"missing key '"
<<
key
<<
"' in FixedMap!"
;
return
ss
.
str
();
}
template
<
class
K
>
typename
std
::
enable_if
<
std
::
is_convertible
<
K
,
int
>::
value
,
std
::
string
>::
type
range_error_message
(
K
key
)
const
{
std
::
stringstream
ss
;
ss
<<
"missing key (converted to int)'"
<<
int
(
key
)
<<
"' in FixedMap!"
;
return
ss
.
str
();
}
template
<
class
K
>
typename
std
::
enable_if
<!
(
std
::
is_convertible
<
K
,
int
>::
value
||
std
::
is_convertible
<
K
,
std
::
string
>::
value
),
std
::
string
>::
type
range_error_message
(
K
/*key*/
)
const
{
return
"missing key is not printable"
;
}
public
:
typedef
key_imp
key_type
;
typedef
T
mapped_type
;
...
...
@@ -166,7 +190,7 @@ public:
{
const
auto
it
=
get_idx
(
key
);
if
(
it
==
N
)
DUNE_THROW
(
RangeError
,
"missing key '"
<<
key
<<
"' in FixedMap!"
);
DUNE_THROW
(
RangeError
,
range_error_message
(
key
)
);
return
map_
[
it
].
second
;
}
...
...
@@ -174,7 +198,7 @@ public:
{
const
auto
it
=
get_idx
(
key
);
if
(
it
==
N
)
DUNE_THROW
(
RangeError
,
"missing key '"
<<
key
<<
"' in FixedMap!"
);
DUNE_THROW
(
RangeError
,
range_error_message
(
key
)
);
return
map_
[
it
].
second
;
}
...
...
This diff is collapsed.
Click to expand it.
dune/xt/common/test/fixed_map.cc
+
11
−
0
View file @
09baef44
...
...
@@ -21,6 +21,14 @@
using
namespace
Dune
::
XT
::
Common
;
enum
class
TestEnum
{
one
,
two
,
three
};
GTEST_TEST
(
FixedMapTest
,
All
)
{
const
std
::
initializer_list
<
std
::
pair
<
std
::
string
,
int
>>
values
{{
"0"
,
0
},
{
"1"
,
1
},
{
"2"
,
2
}};
...
...
@@ -55,4 +63,7 @@ GTEST_TEST(FixedMapTest, All)
EXPECT_EQ
(
std
::
make_pair
(
std
::
string
(
"0"
),
0
),
*
too_big
.
begin
());
// EXPECT_DEATH(*too_big.end(), ".*");
FixedMap
<
TestEnum
,
std
::
string
,
1
>
enum_names
=
{{
TestEnum
::
one
,
"one"
}};
EXPECT_EQ
(
std
::
string
(
"one"
),
enum_names
[
TestEnum
::
one
]);
}
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