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
314970e4
Commit
314970e4
authored
Aug 10, 2019
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add parse function for timespans
parent
3836cdc9
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
2 deletions
+45
-2
libcaf_core/caf/detail/parse.hpp
libcaf_core/caf/detail/parse.hpp
+2
-0
libcaf_core/caf/detail/parser/read_timespan.hpp
libcaf_core/caf/detail/parser/read_timespan.hpp
+2
-2
libcaf_core/src/parse.cpp
libcaf_core/src/parse.cpp
+3
-0
libcaf_core/test/parse.cpp
libcaf_core/test/parse.cpp
+38
-0
No files found.
libcaf_core/caf/detail/parse.hpp
View file @
314970e4
...
@@ -62,6 +62,8 @@ void parse(parse_state& ps, double& x);
...
@@ -62,6 +62,8 @@ void parse(parse_state& ps, double& x);
// -- CAF types ----------------------------------------------------------------
// -- CAF types ----------------------------------------------------------------
void
parse
(
parse_state
&
ps
,
timespan
&
x
);
void
parse
(
parse_state
&
ps
,
atom_value
&
x
);
void
parse
(
parse_state
&
ps
,
atom_value
&
x
);
void
parse
(
parse_state
&
ps
,
uri
&
x
);
void
parse
(
parse_state
&
ps
,
uri
&
x
);
...
...
libcaf_core/caf/detail/parser/read_timespan.hpp
View file @
314970e4
...
@@ -40,7 +40,7 @@ namespace parser {
...
@@ -40,7 +40,7 @@ namespace parser {
/// Reads a timespan.
/// Reads a timespan.
template
<
class
Iterator
,
class
Sentinel
,
class
Consumer
>
template
<
class
Iterator
,
class
Sentinel
,
class
Consumer
>
void
read_timespan
(
state
<
Iterator
,
Sentinel
>&
ps
,
Consumer
&
consumer
,
void
read_timespan
(
state
<
Iterator
,
Sentinel
>&
ps
,
Consumer
&
&
consumer
,
optional
<
int64_t
>
num
=
none
)
{
optional
<
int64_t
>
num
=
none
)
{
using
namespace
std
::
chrono
;
using
namespace
std
::
chrono
;
struct
interim_consumer
{
struct
interim_consumer
{
...
@@ -56,7 +56,7 @@ void read_timespan(state<Iterator, Sentinel>& ps, Consumer& consumer,
...
@@ -56,7 +56,7 @@ void read_timespan(state<Iterator, Sentinel>& ps, Consumer& consumer,
timespan
result
;
timespan
result
;
auto
g
=
make_scope_guard
([
&
]
{
auto
g
=
make_scope_guard
([
&
]
{
if
(
ps
.
code
<=
pec
::
trailing_character
)
if
(
ps
.
code
<=
pec
::
trailing_character
)
consumer
.
value
(
result
);
consumer
.
value
(
std
::
move
(
result
)
);
});
});
// clang-format off
// clang-format off
start
();
start
();
...
...
libcaf_core/src/parse.cpp
View file @
314970e4
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
#include "caf/detail/parser/read_floating_point.hpp"
#include "caf/detail/parser/read_floating_point.hpp"
#include "caf/detail/parser/read_signed_integer.hpp"
#include "caf/detail/parser/read_signed_integer.hpp"
#include "caf/detail/parser/read_string.hpp"
#include "caf/detail/parser/read_string.hpp"
#include "caf/detail/parser/read_timespan.hpp"
#include "caf/detail/parser/read_unsigned_integer.hpp"
#include "caf/detail/parser/read_unsigned_integer.hpp"
#include "caf/detail/parser/read_uri.hpp"
#include "caf/detail/parser/read_uri.hpp"
#include "caf/uri_builder.hpp"
#include "caf/uri_builder.hpp"
...
@@ -56,6 +57,8 @@ PARSE_IMPL(float, floating_point)
...
@@ -56,6 +57,8 @@ PARSE_IMPL(float, floating_point)
PARSE_IMPL
(
double
,
floating_point
)
PARSE_IMPL
(
double
,
floating_point
)
PARSE_IMPL
(
timespan
,
timespan
)
void
parse
(
parse_state
&
ps
,
atom_value
&
x
)
{
void
parse
(
parse_state
&
ps
,
atom_value
&
x
)
{
parser
::
read_atom
(
ps
,
make_consumer
(
x
),
true
);
parser
::
read_atom
(
ps
,
make_consumer
(
x
),
true
);
}
}
...
...
libcaf_core/test/parse.cpp
View file @
314970e4
...
@@ -30,6 +30,28 @@ using namespace caf;
...
@@ -30,6 +30,28 @@ using namespace caf;
namespace
{
namespace
{
using
std
::
chrono
::
duration_cast
;
timespan
operator
""
_ns
(
unsigned
long
long
x
)
{
return
duration_cast
<
timespan
>
(
std
::
chrono
::
nanoseconds
(
x
));
}
timespan
operator
""
_us
(
unsigned
long
long
x
)
{
return
duration_cast
<
timespan
>
(
std
::
chrono
::
microseconds
(
x
));
}
timespan
operator
""
_ms
(
unsigned
long
long
x
)
{
return
duration_cast
<
timespan
>
(
std
::
chrono
::
milliseconds
(
x
));
}
timespan
operator
""
_s
(
unsigned
long
long
x
)
{
return
duration_cast
<
timespan
>
(
std
::
chrono
::
seconds
(
x
));
}
timespan
operator
""
_h
(
unsigned
long
long
x
)
{
return
duration_cast
<
timespan
>
(
std
::
chrono
::
hours
(
x
));
}
template
<
class
T
>
template
<
class
T
>
expected
<
T
>
read
(
string_view
str
)
{
expected
<
T
>
read
(
string_view
str
)
{
T
result
;
T
result
;
...
@@ -122,6 +144,22 @@ CAF_TEST(invalid floating point numbers) {
...
@@ -122,6 +144,22 @@ CAF_TEST(invalid floating point numbers) {
CHECK_INVALID
(
double
,
"++10e-10"
,
pec
::
unexpected_character
);
CHECK_INVALID
(
double
,
"++10e-10"
,
pec
::
unexpected_character
);
}
}
CAF_TEST
(
valid
timespans
)
{
CAF_CHECK_EQUAL
(
read
<
timespan
>
(
"12ns"
),
12
_ns
);
CAF_CHECK_EQUAL
(
read
<
timespan
>
(
"34us"
),
34
_us
);
CAF_CHECK_EQUAL
(
read
<
timespan
>
(
"56ms"
),
56
_ms
);
CAF_CHECK_EQUAL
(
read
<
timespan
>
(
"78s"
),
78
_s
);
CAF_CHECK_EQUAL
(
read
<
timespan
>
(
"60min"
),
1
_h
);
CAF_CHECK_EQUAL
(
read
<
timespan
>
(
"90h"
),
90
_h
);
}
CAF_TEST
(
invalid
timespans
)
{
CAF_CHECK_EQUAL
(
read
<
timespan
>
(
"12"
),
pec
::
unexpected_eof
);
CAF_CHECK_EQUAL
(
read
<
timespan
>
(
"12nas"
),
pec
::
unexpected_character
);
CAF_CHECK_EQUAL
(
read
<
timespan
>
(
"34usec"
),
pec
::
trailing_character
);
CAF_CHECK_EQUAL
(
read
<
timespan
>
(
"56m"
),
pec
::
unexpected_eof
);
}
CAF_TEST
(
valid
atom
values
)
{
CAF_TEST
(
valid
atom
values
)
{
CAF_CHECK_EQUAL
(
read
<
atom_value
>
(
"foo"
),
atom
(
"foo"
));
CAF_CHECK_EQUAL
(
read
<
atom_value
>
(
"foo"
),
atom
(
"foo"
));
CAF_CHECK_EQUAL
(
read
<
atom_value
>
(
"'foo'"
),
atom
(
"foo"
));
CAF_CHECK_EQUAL
(
read
<
atom_value
>
(
"'foo'"
),
atom
(
"foo"
));
...
...
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