Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cbmroot
Manage
Activity
Members
Labels
Plan
Wiki
Redmine
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
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
Computing
cbmroot
Commits
f1bd05aa
Commit
f1bd05aa
authored
1 year ago
by
Felix Weiglhofer
Browse files
Options
Downloads
Patches
Plain Diff
algo: Add case-senstive flag to FromString for enum conversion.
parent
1cbd92dc
No related branches found
No related tags found
1 merge request
!1175
algo: Allow reading enums as strings from YAML.
Pipeline
#22523
passed
1 year ago
Stage: checkRepository
Stage: checkFormat
Stage: build
Stage: finalise
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
algo/CMakeLists.txt
+2
-0
2 additions, 0 deletions
algo/CMakeLists.txt
algo/base/util/SerializableEnum.h
+8
-2
8 additions, 2 deletions
algo/base/util/SerializableEnum.h
with
10 additions
and
2 deletions
algo/CMakeLists.txt
+
2
−
0
View file @
f1bd05aa
...
...
@@ -77,6 +77,7 @@ target_link_libraries(Algo
fmt::fmt
Boost::program_options
Boost::filesystem
Boost::headers
xpu
external::yaml-cpp
external::fles_logging
...
...
@@ -88,6 +89,7 @@ xpu_attach(Algo ${DEVICE_SRCS})
install
(
TARGETS Algo DESTINATION lib
)
install
(
DIRECTORY base/compat TYPE INCLUDE FILES_MATCHING PATTERN
"*.h"
)
install
(
DIRECTORY base/config TYPE INCLUDE FILES_MATCHING PATTERN
"*.h"
)
install
(
DIRECTORY base/util TYPE INCLUDE FILES_MATCHING PATTERN
"*.h"
)
install
(
DIRECTORY base/gpu TYPE INCLUDE FILES_MATCHING PATTERN
"*.h"
)
install
(
DIRECTORY data/sts TYPE INCLUDE FILES_MATCHING PATTERN
"*.h"
)
...
...
This diff is collapsed.
Click to expand it.
algo/base/util/SerializableEnum.h
+
8
−
2
View file @
f1bd05aa
...
...
@@ -4,6 +4,8 @@
#ifndef CBM_ALGO_BASE_UTIL_SERIALIZABLEENUM_H
#define CBM_ALGO_BASE_UTIL_SERIALIZABLEENUM_H
#include
<boost/algorithm/string/predicate.hpp>
#include
<algorithm>
#include
<iostream>
#include
<optional>
...
...
@@ -59,10 +61,14 @@ namespace cbm::algo
inline
const
EnumDict_t
<
T
>
EnumDict
;
template
<
typename
T
,
typename
=
std
::
enable_if_t
<
EnumIsSerializable
<
T
>
::
value
>>
std
::
optional
<
T
>
FromString
(
std
::
string_view
str
)
std
::
optional
<
T
>
FromString
(
std
::
string_view
str
,
bool
caseSensitive
=
false
)
{
const
auto
&
set
=
EnumDict
<
T
>
;
auto
it
=
std
::
find_if
(
set
.
begin
(),
set
.
end
(),
[
str
](
const
auto
&
pair
)
{
return
pair
.
first
==
str
;
});
auto
it
=
std
::
find_if
(
set
.
begin
(),
set
.
end
(),
[
&
](
const
auto
&
pair
)
{
if
(
caseSensitive
)
return
pair
.
first
==
str
;
else
return
boost
::
iequals
(
pair
.
first
,
str
);
});
if
(
it
==
set
.
end
())
return
std
::
nullopt
;
return
it
->
second
;
}
...
...
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