Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
777d33bc
Commit
777d33bc
authored
May 28, 2019
by
Joseph Noir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add function to find option by long name
parent
53977143
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
0 deletions
+32
-0
libcaf_core/caf/config_option.hpp
libcaf_core/caf/config_option.hpp
+32
-0
No files found.
libcaf_core/caf/config_option.hpp
View file @
777d33bc
...
@@ -23,6 +23,7 @@
...
@@ -23,6 +23,7 @@
#include "caf/fwd.hpp"
#include "caf/fwd.hpp"
#include "caf/string_view.hpp"
#include "caf/string_view.hpp"
#include "caf/string_algorithms.hpp"
namespace
caf
{
namespace
caf
{
...
@@ -123,4 +124,35 @@ private:
...
@@ -123,4 +124,35 @@ private:
mutable
void
*
value_
;
mutable
void
*
value_
;
};
};
/// Finds `config_option` string with a matching long name in (`first`, `last`],
/// where each entry is a pointer to a string. Returns a `ForwardIterator` to
/// the match and a `caf::string_view` of the option value if the entry is found
/// and a `ForwardIterator` to `last` with an empty `string_view` otherwise.
template
<
class
ForwardIterator
,
class
Sentinel
>
std
::
pair
<
ForwardIterator
,
string_view
>
find_by_long_name
(
const
config_option
&
x
,
ForwardIterator
first
,
Sentinel
last
)
{
auto
long_name
=
x
.
long_name
();
for
(;
first
!=
last
;
++
first
)
{
string_view
str
{
*
first
};
// Make sure this is a long option starting with "--".
if
(
!
starts_with
(
str
,
"--"
))
continue
;
str
.
remove_prefix
(
2
);
// Skip optional "caf#" prefix.
if
(
starts_with
(
str
,
"caf#"
))
str
.
remove_prefix
(
4
);
// Make sure we are dealing with the right key.
if
(
!
starts_with
(
str
,
long_name
))
continue
;
// Make sure the key is followed by an assignment.
str
.
remove_prefix
(
long_name
.
size
());
if
(
!
starts_with
(
str
,
"="
))
continue
;
// Remove leading '=' and return the value.
str
.
remove_prefix
(
1
);
return
{
first
,
str
};
}
return
{
first
,
string_view
{}};
}
}
// namespace caf
}
// namespace caf
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment