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
3640a0d9
Commit
3640a0d9
authored
Jan 29, 2020
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Integrate review feedback
parent
9a5dbc12
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
38 additions
and
31 deletions
+38
-31
libcaf_core/caf/detail/meta_object.hpp
libcaf_core/caf/detail/meta_object.hpp
+3
-3
libcaf_core/caf/fwd.hpp
libcaf_core/caf/fwd.hpp
+1
-0
libcaf_core/caf/type_id.hpp
libcaf_core/caf/type_id.hpp
+22
-16
libcaf_core/caf/type_id_list.hpp
libcaf_core/caf/type_id_list.hpp
+7
-7
libcaf_core/src/detail/meta_object.cpp
libcaf_core/src/detail/meta_object.cpp
+2
-2
libcaf_core/test/type_id_list.cpp
libcaf_core/test/type_id_list.cpp
+3
-3
No files found.
libcaf_core/caf/detail/meta_object.hpp
View file @
3640a0d9
...
...
@@ -57,7 +57,7 @@ struct meta_object {
CAF_CORE_EXPORT
span
<
const
meta_object
>
global_meta_objects
();
/// Returns the global meta object for given type ID.
CAF_CORE_EXPORT
meta_object
&
global_meta_object
(
uint16
_t
id
);
CAF_CORE_EXPORT
meta_object
&
global_meta_object
(
type_id
_t
id
);
/// Clears the array for storing global meta objects.
/// @warning intended for unit testing only!
...
...
@@ -70,12 +70,12 @@ CAF_CORE_EXPORT void clear_global_meta_objects();
/// causes undefined behavior.
CAF_CORE_EXPORT
span
<
meta_object
>
resize_global_meta_objects
(
size_t
size
);
/// Sets the meta objects in range `
(first_id, first_id + xs.size]
` to `xs`.
/// Sets the meta objects in range `
[first_id, first_id + xs.size)
` to `xs`.
/// Resizes the global meta object if needed. Aborts the program if the range
/// already contains meta objects.
/// @warning calling this after constructing any ::actor_system is unsafe and
/// causes undefined behavior.
CAF_CORE_EXPORT
void
set_global_meta_objects
(
uint16
_t
first_id
,
CAF_CORE_EXPORT
void
set_global_meta_objects
(
type_id
_t
first_id
,
span
<
const
meta_object
>
xs
);
}
// namespace caf::detail
libcaf_core/caf/fwd.hpp
View file @
3640a0d9
...
...
@@ -191,6 +191,7 @@ using ip_endpoint = ipv6_endpoint;
using
ip_subnet
=
ipv6_subnet
;
using
settings
=
dictionary
<
config_value
>
;
using
stream_slot
=
uint16_t
;
using
type_id_t
=
uint16_t
;
// -- functions ----------------------------------------------------------------
...
...
libcaf_core/caf/type_id.hpp
View file @
3640a0d9
...
...
@@ -27,47 +27,53 @@
namespace
caf
{
/// Maps the type `T` to a globally unique 16-bit ID.
/// Internal representation of a type ID.
using
type_id_t
=
uint16_t
;
/// Maps the type `T` to a globally unique ID.
template
<
class
T
>
struct
type_id
;
/// Convenience alias for `type_id<T>::value`.
/// @relates type_id
template
<
class
T
>
constexpr
uint16
_t
type_id_v
=
type_id
<
T
>::
value
;
constexpr
type_id
_t
type_id_v
=
type_id
<
T
>::
value
;
/// Maps the globally unique ID `V` to a type (inverse to ::type_id).
/// @relates type_id
template
<
uint16
_t
V
>
template
<
type_id
_t
V
>
struct
type_by_id
;
/// Convenience alias for `type_by_id<I>::type`.
/// @relates type_by_id
template
<
uint16
_t
I
>
template
<
type_id
_t
I
>
using
type_by_id_t
=
typename
type_by_id
<
I
>::
type
;
/// Maps the globally unique ID `V` to a type name.
template
<
uint16
_t
V
>
template
<
type_id
_t
V
>
struct
type_name_by_id
;
/// Convenience alias for `type_name_by_id<I>::value`.
/// @relates type_name_by_id
template
<
uint16
_t
I
>
template
<
type_id
_t
I
>
constexpr
const
char
*
type_name_by_id_v
=
type_name_by_id
<
I
>::
value
;
/// The first type ID not reserved by CAF and its modules.
constexpr
uint16
_t
first_custom_type_id
=
200
;
constexpr
type_id
_t
first_custom_type_id
=
200
;
}
// namespace caf
/// Starts a code block for registering custom types to CAF. Stores the first ID
/// for the project as `caf::${project_name}_first_type_id`. Unless the project
/// appends to an ID block of another project, users should use
/// `caf::first_custom_type_id` as `first_id`.
/// for the project as `caf::${project_name}_first_type_id`. Usually, users
/// should use `caf::first_custom_type_id` as `first_id`. However, this
/// mechanism also enables modules to append IDs to a block of another module or
/// module. If two modules are developed separately to avoid dependencies, they
/// only need to define sufficiently large offsets to guarantee collision-free
/// IDs (CAF supports gaps in the ID space).
#define CAF_BEGIN_TYPE_ID_BLOCK(project_name, first_id) \
namespace caf { \
constexpr
uint16_t project_name##_type_id_counter_init = __COUNTER__;
\
constexpr
uint16_t project_name##_first_type_id = first_id;
\
constexpr
type_id_t project_name##_type_id_counter_init = __COUNTER__;
\
constexpr
type_id_t project_name##_first_type_id = first_id;
\
}
/// Assigns the next free type ID to `fully_qualified_name`.
...
...
@@ -75,7 +81,7 @@ constexpr uint16_t first_custom_type_id = 200;
namespace caf { \
template <> \
struct type_id<fully_qualified_name> { \
static constexpr
uint16_t value
\
static constexpr
type_id_t value
\
= project_name##_first_type_id \
+ (__COUNTER__ - project_name##_type_id_counter_init - 1); \
}; \
...
...
@@ -105,12 +111,12 @@ constexpr uint16_t first_custom_type_id = 200;
/// type ID used by the project as `caf::${project_name}_last_type_id`.
#define CAF_END_TYPE_ID_BLOCK(project_name) \
namespace caf { \
constexpr
uint16_t project_name##_last_type_id
\
constexpr
type_id_t project_name##_last_type_id
\
= project_name##_first_type_id \
+ (__COUNTER__ - project_name##_type_id_counter_init - 2); \
struct project_name##_type_ids { \
static constexpr
uint16_t first = project_name##_first_type_id;
\
static constexpr
uint16_t last = project_name##_last_type_id;
\
static constexpr
type_id_t first = project_name##_first_type_id;
\
static constexpr
type_id_t last = project_name##_last_type_id;
\
}; \
}
...
...
libcaf_core/caf/type_id_list.hpp
View file @
3640a0d9
...
...
@@ -29,10 +29,10 @@
namespace
caf
{
/// A list of
16-bit
type IDs, stored in a size-prefix, contiguous memory block.
/// A list of type IDs, stored in a size-prefix, contiguous memory block.
class
type_id_list
:
detail
::
comparable
<
type_id_list
>
{
public:
using
pointer
=
const
uint16
_t
*
;
using
pointer
=
const
type_id
_t
*
;
constexpr
explicit
type_id_list
(
pointer
data
)
noexcept
:
data_
(
data
)
{
// nop
...
...
@@ -42,7 +42,7 @@ public:
type_id_list
&
operator
=
(
const
type_id_list
&
)
noexcept
=
default
;
/// Queries whether this type list contains data, i
,
e, `data() != nullptr`.
/// Queries whether this type list contains data, i
.
e, `data() != nullptr`.
constexpr
operator
bool
()
const
noexcept
{
return
data_
!=
nullptr
;
}
...
...
@@ -60,13 +60,13 @@ public:
/// Returns the type ID at `index`.
/// @pre `data() != nullptr`
constexpr
uint16
_t
operator
[](
size_t
index
)
const
noexcept
{
constexpr
type_id
_t
operator
[](
size_t
index
)
const
noexcept
{
return
data_
[
index
+
1
];
}
/// Compares this list to `other`.
int
compare
(
type_id_list
other
)
const
noexcept
{
return
memcmp
(
data_
,
other
.
data_
,
size
()
*
sizeof
(
uint16
_t
));
return
memcmp
(
data_
,
other
.
data_
,
size
()
*
sizeof
(
type_id
_t
));
}
private:
...
...
@@ -76,8 +76,8 @@ private:
/// @private
template
<
class
...
Ts
>
struct
make_type_id_list_helper
{
static
constexpr
inline
uint16
_t
data
[]
=
{
static_cast
<
uint16
_t
>
(
sizeof
...(
Ts
)),
type_id_v
<
Ts
>
...};
static
constexpr
inline
type_id
_t
data
[]
=
{
static_cast
<
type_id
_t
>
(
sizeof
...(
Ts
)),
type_id_v
<
Ts
>
...};
};
/// Constructs a ::type_id_list from the template parameter pack `Ts`.
...
...
libcaf_core/src/detail/meta_object.cpp
View file @
3640a0d9
...
...
@@ -55,7 +55,7 @@ span<const meta_object> global_meta_objects() {
return
{
meta_objects
,
meta_objects_size
};
}
meta_object
&
global_meta_object
(
uint16
_t
id
)
{
meta_object
&
global_meta_object
(
type_id
_t
id
)
{
CAF_ASSERT
(
id
<
meta_objects_size
);
return
meta_objects
[
id
];
}
...
...
@@ -80,7 +80,7 @@ span<meta_object> resize_global_meta_objects(size_t size) {
return
{
new_storage
,
size
};
}
void
set_global_meta_objects
(
uint16
_t
first_id
,
span
<
const
meta_object
>
xs
)
{
void
set_global_meta_objects
(
type_id
_t
first_id
,
span
<
const
meta_object
>
xs
)
{
auto
new_size
=
first_id
+
xs
.
size
();
if
(
first_id
<
meta_objects_size
)
{
if
(
new_size
>
meta_objects_size
)
...
...
libcaf_core/test/type_id_list.cpp
View file @
3640a0d9
...
...
@@ -27,7 +27,7 @@
using
namespace
caf
;
CAF_TEST
(
lists
store
the
size
at
index
0
)
{
uint16
_t
data
[]
=
{
3
,
1
,
2
,
4
};
type_id
_t
data
[]
=
{
3
,
1
,
2
,
4
};
type_id_list
xs
{
data
};
CAF_CHECK_EQUAL
(
xs
.
size
(),
3u
);
CAF_CHECK_EQUAL
(
xs
[
0
],
1u
);
...
...
@@ -36,9 +36,9 @@ CAF_TEST(lists store the size at index 0) {
}
CAF_TEST
(
lists
are
comparable
)
{
uint16
_t
data
[]
=
{
3
,
1
,
2
,
4
};
type_id
_t
data
[]
=
{
3
,
1
,
2
,
4
};
type_id_list
xs
{
data
};
uint16
_t
data_copy
[]
=
{
3
,
1
,
2
,
4
};
type_id
_t
data_copy
[]
=
{
3
,
1
,
2
,
4
};
type_id_list
ys
{
data_copy
};
CAF_CHECK_EQUAL
(
xs
,
ys
);
data_copy
[
1
]
=
10
;
...
...
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