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
7899929c
Commit
7899929c
authored
Sep 05, 2011
by
neverlord
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
util::duration
parent
2337b22a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
4 deletions
+77
-4
cppa/util/duration.hpp
cppa/util/duration.hpp
+59
-2
src/duration.cpp
src/duration.cpp
+16
-1
unit_testing/test__uniform_type.cpp
unit_testing/test__uniform_type.cpp
+2
-1
No files found.
cppa/util/duration.hpp
View file @
7899929c
#ifndef DURATION_HPP
#define DURATION_HPP
#include <chrono>
#include <cstdint>
namespace
cppa
{
namespace
util
{
enum
class
time_unit
:
std
::
uint32_t
{
none
=
0
,
seconds
=
1
,
milliseconds
=
1000
,
microseconds
=
1000000
};
template
<
typename
Period
>
constexpr
time_unit
get_time_unit_from_period
()
{
return
(
Period
::
num
!=
1
?
time_unit
::
none
:
(
Period
::
den
==
1
?
time_unit
::
seconds
:
(
Period
::
den
==
1000
?
time_unit
::
milliseconds
:
(
Period
::
den
==
1000000
?
time_unit
::
microseconds
:
time_unit
::
none
))));
}
class
duration
{
public:
duration
();
public:
constexpr
duration
()
:
unit
(
time_unit
::
none
),
count
(
0
)
{
}
constexpr
duration
(
time_unit
un
,
std
::
uint32_t
val
)
:
unit
(
un
),
count
(
val
)
{
}
template
<
class
Rep
,
class
Period
>
constexpr
duration
(
std
::
chrono
::
duration
<
Rep
,
Period
>
d
)
:
unit
(
get_time_unit_from_period
<
Period
>
()),
count
(
d
.
count
())
{
static_assert
(
get_time_unit_from_period
<
Period
>
()
!=
time_unit
::
none
,
"only seconds, milliseconds or microseconds allowed"
);
}
time_unit
unit
;
std
::
uint32_t
count
;
};
bool
operator
==
(
const
duration
&
lhs
,
const
duration
&
rhs
);
inline
bool
operator
!=
(
const
duration
&
lhs
,
const
duration
&
rhs
)
{
return
!
(
lhs
==
rhs
);
}
}
}
// namespace cppa::util
#endif // DURATION_HPP
src/duration.cpp
View file @
7899929c
#include "cppa/util/duration.hpp"
duration
::
duration
()
namespace
{
inline
std
::
uint64_t
ui64_val
(
const
cppa
::
util
::
duration
&
d
)
{
return
static_cast
<
std
::
uint64_t
>
(
d
.
unit
)
*
d
.
count
;
}
}
// namespace <anonmyous>
namespace
cppa
{
namespace
util
{
bool
operator
==
(
const
duration
&
lhs
,
const
duration
&
rhs
)
{
return
(
lhs
.
unit
==
rhs
.
unit
?
lhs
.
count
==
rhs
.
count
:
ui64_val
(
lhs
)
==
ui64_val
(
rhs
));
}
}
}
// namespace cppa::util
unit_testing/test__uniform_type.cpp
View file @
7899929c
...
...
@@ -94,7 +94,8 @@ size_t test__uniform_type()
"@msg"
,
// cppa::message
"@actor"
,
// cppa::actor_ptr
"@group"
,
// cppa::group_ptr
"@channel"
// cppa::channel_ptr
"@channel"
,
// cppa::channel_ptr
"cppa::util::duration"
};
if
(
sizeof
(
double
)
!=
sizeof
(
long
double
))
{
...
...
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