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
06cd2836
Commit
06cd2836
authored
Dec 11, 2020
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow users to override the default type name
parent
b57ead03
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
36 deletions
+58
-36
CHANGELOG.md
CHANGELOG.md
+2
-0
libcaf_core/caf/type_id.hpp
libcaf_core/caf/type_id.hpp
+54
-34
libcaf_core/test/type_id_list.cpp
libcaf_core/test/type_id_list.cpp
+2
-2
No files found.
CHANGELOG.md
View file @
06cd2836
...
@@ -14,6 +14,8 @@ is based on [Keep a Changelog](https://keepachangelog.com).
...
@@ -14,6 +14,8 @@ is based on [Keep a Changelog](https://keepachangelog.com).
module:
`caf.middleman.inbound-messages-size`
,
module:
`caf.middleman.inbound-messages-size`
,
`caf.middleman.outbound-messages-size`
,
`caf.middleman.deserialization-time`
`caf.middleman.outbound-messages-size`
,
`caf.middleman.deserialization-time`
and
`caf.middleman.serialization-time`
.
and
`caf.middleman.serialization-time`
.
-
The macro
`CAF_ADD_TYPE_ID`
now accepts an optional third parameter for
allowing users to override the default type name.
### Changed
### Changed
...
...
libcaf_core/caf/type_id.hpp
View file @
06cd2836
...
@@ -134,16 +134,27 @@ CAF_CORE_EXPORT type_id_t query_type_id(string_view name);
...
@@ -134,16 +134,27 @@ CAF_CORE_EXPORT type_id_t query_type_id(string_view name);
}
}
#ifdef CAF_MSVC
#ifdef CAF_MSVC
/// Assigns the next free type ID to `fully_qualified_name`.
# define CAF_DETAIL_NEXT_TYPE_ID(project_name, fully_qualified_name) \
# define CAF_ADD_TYPE_ID(project_name, fully_qualified_name) \
namespace caf { \
template <> \
template <> \
struct type_id<CAF_PP_EXPAND fully_qualified_name> { \
struct type_id<CAF_PP_EXPAND fully_qualified_name> { \
static constexpr type_id_t value \
static constexpr type_id_t value \
= id_block::project_name##_first_type_id \
= id_block::project_name##_first_type_id \
+ (CAF_PP_CAT(CAF_PP_COUNTER, ()) \
+ (CAF_PP_CAT(CAF_PP_COUNTER, ()) \
- id_block::project_name##_type_id_counter_init - 1); \
- id_block::project_name##_type_id_counter_init - 1); \
}; \
};
#else
# define CAF_DETAIL_NEXT_TYPE_ID(project_name, fully_qualified_name) \
template <> \
struct type_id<CAF_PP_EXPAND fully_qualified_name> { \
static constexpr type_id_t value \
= id_block::project_name##_first_type_id \
+ (__COUNTER__ - id_block::project_name##_type_id_counter_init - 1); \
};
#endif
#define CAF_ADD_TYPE_ID_2(project_name, fully_qualified_name) \
namespace caf { \
CAF_DETAIL_NEXT_TYPE_ID(project_name, fully_qualified_name) \
template <> \
template <> \
struct type_by_id<type_id<CAF_PP_EXPAND fully_qualified_name>::value> { \
struct type_by_id<type_id<CAF_PP_EXPAND fully_qualified_name>::value> { \
using type = CAF_PP_EXPAND fully_qualified_name; \
using type = CAF_PP_EXPAND fully_qualified_name; \
...
@@ -157,28 +168,37 @@ CAF_CORE_EXPORT type_id_t query_type_id(string_view name);
...
@@ -157,28 +168,37 @@ CAF_CORE_EXPORT type_id_t query_type_id(string_view name);
struct type_name_by_id<type_id<CAF_PP_EXPAND fully_qualified_name>::value> \
struct type_name_by_id<type_id<CAF_PP_EXPAND fully_qualified_name>::value> \
: type_name<CAF_PP_EXPAND fully_qualified_name> {}; \
: type_name<CAF_PP_EXPAND fully_qualified_name> {}; \
}
}
#else
#
define CAF_ADD_TYPE_ID(project_name, fully_qualified_name)
\
#
define CAF_ADD_TYPE_ID_3(project_name, fully_qualified_name, user_type_name)
\
namespace caf { \
namespace caf { \
template <> \
CAF_DETAIL_NEXT_TYPE_ID(project_name, fully_qualified_name) \
struct type_id<CAF_PP_EXPAND fully_qualified_name> { \
static constexpr type_id_t value \
= id_block::project_name##_first_type_id \
+ (__COUNTER__ - id_block::project_name##_type_id_counter_init - 1); \
}; \
template <> \
template <> \
struct type_by_id<type_id<CAF_PP_EXPAND fully_qualified_name>::value> { \
struct type_by_id<type_id<CAF_PP_EXPAND fully_qualified_name>::value> { \
using type = CAF_PP_EXPAND fully_qualified_name; \
using type = CAF_PP_EXPAND fully_qualified_name; \
}; \
}; \
template <> \
template <> \
struct type_name<CAF_PP_EXPAND fully_qualified_name> { \
struct type_name<CAF_PP_EXPAND fully_qualified_name> { \
static constexpr string_view value \
static constexpr string_view value = user_type_name; \
= CAF_PP_STR(CAF_PP_EXPAND fully_qualified_name); \
}; \
}; \
template <> \
template <> \
struct type_name_by_id<type_id<CAF_PP_EXPAND fully_qualified_name>::value> \
struct type_name_by_id<type_id<CAF_PP_EXPAND fully_qualified_name>::value> \
: type_name<CAF_PP_EXPAND fully_qualified_name> {}; \
: type_name<CAF_PP_EXPAND fully_qualified_name> {}; \
}
}
/// @def CAF_ADD_TYPE_ID(project_name, fully_qualified_name, user_type_name)
/// Assigns the next free type ID to `fully_qualified_name`.
/// @param project_name User-defined name for type ID block.
/// @param fully_qualified_name Name of the type enclosed in parens and
/// including namespaces, e.g., `(std::string)`.
/// @param user_type_name Optional parameter. If present, defines the content of
/// `caf::type_name`. Defaults to `fully_qualified_name`.
#ifdef CAF_MSVC
# define CAF_ADD_TYPE_ID(...) \
CAF_PP_CAT(CAF_PP_OVERLOAD(CAF_ADD_TYPE_ID_, __VA_ARGS__)(__VA_ARGS__), \
CAF_PP_EMPTY())
#else
# define CAF_ADD_TYPE_ID(...) \
CAF_PP_OVERLOAD(CAF_ADD_TYPE_ID_, __VA_ARGS__)(__VA_ARGS__)
#endif
#endif
/// Creates a new tag type (atom) in the global namespace and assigns the next
/// Creates a new tag type (atom) in the global namespace and assigns the next
...
@@ -272,7 +292,7 @@ CAF_BEGIN_TYPE_ID_BLOCK(core_module, 0)
...
@@ -272,7 +292,7 @@ CAF_BEGIN_TYPE_ID_BLOCK(core_module, 0)
CAF_ADD_TYPE_ID
(
core_module
,
(
int32_t
))
CAF_ADD_TYPE_ID
(
core_module
,
(
int32_t
))
CAF_ADD_TYPE_ID
(
core_module
,
(
int64_t
))
CAF_ADD_TYPE_ID
(
core_module
,
(
int64_t
))
CAF_ADD_TYPE_ID
(
core_module
,
(
int8_t
))
CAF_ADD_TYPE_ID
(
core_module
,
(
int8_t
))
CAF_ADD_TYPE_ID
(
core_module
,
(
long
double
)
)
CAF_ADD_TYPE_ID
(
core_module
,
(
long
double
)
,
"ldouble"
)
CAF_ADD_TYPE_ID
(
core_module
,
(
uint16_t
))
CAF_ADD_TYPE_ID
(
core_module
,
(
uint16_t
))
CAF_ADD_TYPE_ID
(
core_module
,
(
uint32_t
))
CAF_ADD_TYPE_ID
(
core_module
,
(
uint32_t
))
CAF_ADD_TYPE_ID
(
core_module
,
(
uint64_t
))
CAF_ADD_TYPE_ID
(
core_module
,
(
uint64_t
))
...
...
libcaf_core/test/type_id_list.cpp
View file @
06cd2836
...
@@ -56,6 +56,6 @@ CAF_TEST(make_type_id_list constructs a list from types) {
...
@@ -56,6 +56,6 @@ CAF_TEST(make_type_id_list constructs a list from types) {
}
}
CAF_TEST
(
type
ID
lists
are
convertible
to
strings
)
{
CAF_TEST
(
type
ID
lists
are
convertible
to
strings
)
{
auto
xs
=
make_type_id_list
<
uint16_t
,
bool
,
float
>
();
auto
xs
=
make_type_id_list
<
uint16_t
,
bool
,
float
,
long
double
>
();
CAF_CHECK_EQUAL
(
to_string
(
xs
),
"[uint16_t, bool, float]"
);
CAF_CHECK_EQUAL
(
to_string
(
xs
),
"[uint16_t, bool, float
, ldouble
]"
);
}
}
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