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
d1aaf702
Commit
d1aaf702
authored
May 09, 2020
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Integrate CAF_ERROR_CODE_ENUM macro
parent
a7752756
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
50 additions
and
29 deletions
+50
-29
libcaf_core/caf/duration.hpp
libcaf_core/caf/duration.hpp
+1
-9
libcaf_core/caf/error.hpp
libcaf_core/caf/error.hpp
+15
-3
libcaf_core/caf/expected.hpp
libcaf_core/caf/expected.hpp
+11
-8
libcaf_core/caf/make_message.hpp
libcaf_core/caf/make_message.hpp
+0
-8
libcaf_core/caf/timespan.hpp
libcaf_core/caf/timespan.hpp
+10
-1
libcaf_core/caf/type_id.hpp
libcaf_core/caf/type_id.hpp
+13
-0
No files found.
libcaf_core/caf/duration.hpp
View file @
d1aaf702
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
#include <stdexcept>
#include <stdexcept>
#include "caf/error.hpp"
#include "caf/error.hpp"
#include "caf/timespan.hpp"
namespace
caf
{
namespace
caf
{
...
@@ -75,15 +76,6 @@ constexpr time_unit get_time_unit_from_period() {
...
@@ -75,15 +76,6 @@ constexpr time_unit get_time_unit_from_period() {
return
ratio_to_time_unit_helper
<
Period
::
num
,
Period
::
den
>::
value
;
return
ratio_to_time_unit_helper
<
Period
::
num
,
Period
::
den
>::
value
;
}
}
/// Represents an infinite amount of timeout for specifying "invalid" timeouts.
struct
infinite_t
{
constexpr
infinite_t
()
{
// nop
}
};
static
constexpr
infinite_t
infinite
=
infinite_t
{};
/// Time duration consisting of a `time_unit` and a 64 bit unsigned integer.
/// Time duration consisting of a `time_unit` and a 64 bit unsigned integer.
class
duration
{
class
duration
{
public:
public:
...
...
libcaf_core/caf/error.hpp
View file @
d1aaf702
...
@@ -71,6 +71,12 @@ template <class T, class U = void>
...
@@ -71,6 +71,12 @@ template <class T, class U = void>
using
enable_if_has_error_factory_t
=
using
enable_if_has_error_factory_t
=
typename
std
::
enable_if
<
detail
::
error_factory
<
T
>::
specialized
,
U
>::
type
;
typename
std
::
enable_if
<
detail
::
error_factory
<
T
>::
specialized
,
U
>::
type
;
/// @private
template
<
class
T
,
class
U
=
void
>
using
enable_if_can_construct_error_t
=
typename
std
::
enable_if
<
detail
::
error_factory
<
T
>::
specialized
||
has_make_error
<
T
>::
value
,
U
>::
type
;
/// A serializable type for storing error codes with category and optional,
/// A serializable type for storing error codes with category and optional,
/// human-readable context information. Unlike error handling classes from
/// human-readable context information. Unlike error handling classes from
/// the C++ standard library, this type is serializable. It consists of an
/// the C++ standard library, this type is serializable. It consists of an
...
@@ -276,15 +282,21 @@ bool operator!=(E x, const error& y) {
...
@@ -276,15 +282,21 @@ bool operator!=(E x, const error& y) {
return
!
(
x
==
y
);
return
!
(
x
==
y
);
}
}
/// @relates error
template
<
class
Code
,
class
...
Ts
>
enable_if_has_error_factory_t
<
Code
,
error
>
make_error
(
Code
code
,
Ts
&&
...
xs
)
{
return
error
{
code
,
std
::
forward
<
Ts
>
(
xs
)...};
}
}
// namespace caf
}
// namespace caf
#define CAF_ERROR_CODE_ENUM(enum_
name)
\
#define CAF_ERROR_CODE_ENUM(enum_
type, category_name)
\
namespace caf { \
namespace caf { \
namespace detail { \
namespace detail { \
template <> \
template <> \
struct error_factory<enum_
nam
e> { \
struct error_factory<enum_
typ
e> { \
static constexpr bool specialized = true; \
static constexpr bool specialized = true; \
static constexpr atom_value category = atom(
#enum_name);
\
static constexpr atom_value category = atom(
category_name);
\
template <class... Ts> \
template <class... Ts> \
static message context(Ts&&... xs) { \
static message context(Ts&&... xs) { \
return make_message(std::forward<Ts>(xs)...); \
return make_message(std::forward<Ts>(xs)...); \
...
...
libcaf_core/caf/expected.hpp
View file @
d1aaf702
...
@@ -91,9 +91,9 @@ public:
...
@@ -91,9 +91,9 @@ public:
construct
(
other
);
construct
(
other
);
}
}
template
<
class
Code
,
class
E
=
enable_if_has_make
_error_t
<
Code
>
>
template
<
class
Code
,
class
=
enable_if_can_construct
_error_t
<
Code
>
>
expected
(
Code
code
)
:
engaged_
(
false
)
{
expected
(
Code
code
)
:
engaged_
(
false
)
{
new
(
std
::
addressof
(
error_
))
caf
::
error
(
make_error
(
code
)
);
new
(
std
::
addressof
(
error_
))
caf
::
error
(
code
);
}
}
expected
(
expected
&&
other
)
noexcept
(
nothrow_move
)
{
expected
(
expected
&&
other
)
noexcept
(
nothrow_move
)
{
...
@@ -139,7 +139,6 @@ public:
...
@@ -139,7 +139,6 @@ public:
return
*
this
;
return
*
this
;
}
}
expected
&
operator
=
(
T
&&
x
)
noexcept
(
nothrow_move
)
{
expected
&
operator
=
(
T
&&
x
)
noexcept
(
nothrow_move
)
{
if
(
engaged_
)
{
if
(
engaged_
)
{
value_
=
std
::
move
(
x
);
value_
=
std
::
move
(
x
);
...
@@ -169,8 +168,8 @@ public:
...
@@ -169,8 +168,8 @@ public:
}
}
template
<
class
Code
>
template
<
class
Code
>
enable_if_
has_make
_error_t
<
Code
,
expected
&>
operator
=
(
Code
code
)
{
enable_if_
can_construct
_error_t
<
Code
,
expected
&>
operator
=
(
Code
code
)
{
return
*
this
=
make_error
(
code
)
;
return
*
this
=
caf
::
error
{
code
}
;
}
}
// -- modifiers --------------------------------------------------------------
// -- modifiers --------------------------------------------------------------
...
@@ -390,8 +389,8 @@ public:
...
@@ -390,8 +389,8 @@ public:
// nop
// nop
}
}
template
<
class
Code
,
class
E
=
enable_if_has_make
_error_t
<
Code
>
>
template
<
class
Code
,
class
=
enable_if_can_construct
_error_t
<
Code
>
>
expected
(
Code
code
)
:
error_
(
make_error
(
code
)
)
{
expected
(
Code
code
)
:
error_
(
code
)
{
// nop
// nop
}
}
...
@@ -402,6 +401,11 @@ public:
...
@@ -402,6 +401,11 @@ public:
return
*
this
;
return
*
this
;
}
}
template
<
class
Code
>
enable_if_can_construct_error_t
<
Code
,
expected
&>
operator
=
(
Code
code
)
{
error_
=
caf
::
error
{
code
};
}
explicit
operator
bool
()
const
{
explicit
operator
bool
()
const
{
return
!
error_
;
return
!
error_
;
}
}
...
@@ -458,4 +462,3 @@ auto operator<<(ostream& oss, const caf::expected<T>& x)
...
@@ -458,4 +462,3 @@ auto operator<<(ostream& oss, const caf::expected<T>& x)
}
}
}
// namespace std
}
// namespace std
libcaf_core/caf/make_message.hpp
View file @
d1aaf702
...
@@ -61,14 +61,6 @@ struct is_serializable_or_whitelisted {
...
@@ -61,14 +61,6 @@ struct is_serializable_or_whitelisted {
||
allowed_unsafe_message_type
<
T
>::
value
;
||
allowed_unsafe_message_type
<
T
>::
value
;
};
};
/// @private
template
<
class
T
>
struct
has_type_id
{
static
constexpr
bool
value
=
detail
::
is_complete
<
type_id
<
T
>>::
value
||
is_atom_constant
<
T
>::
value
||
allowed_unsafe_message_type
<
T
>::
value
;
};
/// Returns a new `message` containing the values `(x, xs...)`.
/// Returns a new `message` containing the values `(x, xs...)`.
/// @relates message
/// @relates message
template
<
class
T
,
class
...
Ts
>
template
<
class
T
,
class
...
Ts
>
...
...
libcaf_core/caf/timespan.hpp
View file @
d1aaf702
...
@@ -26,5 +26,14 @@ namespace caf {
...
@@ -26,5 +26,14 @@ namespace caf {
/// A portable timespan type with nanosecond resolution.
/// A portable timespan type with nanosecond resolution.
using
timespan
=
std
::
chrono
::
duration
<
int64_t
,
std
::
nano
>
;
using
timespan
=
std
::
chrono
::
duration
<
int64_t
,
std
::
nano
>
;
}
// namespace caf
/// Represents an infinite amount of timeout for specifying "invalid" timeouts.
struct
infinite_t
{
constexpr
infinite_t
()
{
// nop
}
};
/// Constant for passing "no timeout" to functions such as `request`.
static
constexpr
infinite_t
infinite
=
infinite_t
{};
}
// namespace caf
libcaf_core/caf/type_id.hpp
View file @
d1aaf702
...
@@ -23,7 +23,9 @@
...
@@ -23,7 +23,9 @@
#include <string>
#include <string>
#include <utility>
#include <utility>
#include "caf/allowed_unsafe_message_type.hpp"
#include "caf/atom.hpp"
#include "caf/atom.hpp"
#include "caf/detail/is_complete.hpp"
#include "caf/detail/pp.hpp"
#include "caf/detail/pp.hpp"
#include "caf/detail/squashed_int.hpp"
#include "caf/detail/squashed_int.hpp"
#include "caf/fwd.hpp"
#include "caf/fwd.hpp"
...
@@ -63,6 +65,17 @@ struct type_name_by_id;
...
@@ -63,6 +65,17 @@ struct type_name_by_id;
/// The first type ID not reserved by CAF and its modules.
/// The first type ID not reserved by CAF and its modules.
constexpr
type_id_t
first_custom_type_id
=
200
;
constexpr
type_id_t
first_custom_type_id
=
200
;
/// Evaluates to `true` if any of these statements holds true:
/// - `type_id<T>` is specialized
/// - `T` is an atom constant
/// - `allowed_unsafe_message_type<T>` is specialized
template
<
class
T
>
struct
has_type_id
{
static
constexpr
bool
value
=
detail
::
is_complete
<
type_id
<
T
>>::
value
||
is_atom_constant
<
T
>::
value
||
allowed_unsafe_message_type
<
T
>::
value
;
};
}
// namespace caf
}
// namespace caf
/// Starts a code block for registering custom types to CAF. Stores the first ID
/// Starts a code block for registering custom types to CAF. Stores the first ID
...
...
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