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
ff2ad077
Commit
ff2ad077
authored
Dec 07, 2019
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add typed view types for messages
parent
3d7851f8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
219 additions
and
0 deletions
+219
-0
libcaf_core/CMakeLists.txt
libcaf_core/CMakeLists.txt
+2
-0
libcaf_core/caf/const_typed_message_view.hpp
libcaf_core/caf/const_typed_message_view.hpp
+57
-0
libcaf_core/caf/typed_message_view.hpp
libcaf_core/caf/typed_message_view.hpp
+56
-0
libcaf_core/test/const_typed_message_view.cpp
libcaf_core/test/const_typed_message_view.cpp
+47
-0
libcaf_core/test/typed_message_view.cpp
libcaf_core/test/typed_message_view.cpp
+57
-0
No files found.
libcaf_core/CMakeLists.txt
View file @
ff2ad077
...
...
@@ -185,6 +185,7 @@ set(CAF_CORE_TEST_SOURCES
test/config_option_set.cpp
test/config_value.cpp
test/config_value_adaptor.cpp
test/const_typed_message_view.cpp
test/constructor_attach.cpp
test/continuous_streaming.cpp
test/cow_tuple.cpp
...
...
@@ -272,6 +273,7 @@ set(CAF_CORE_TEST_SOURCES
test/tracing_data.cpp
test/type_erased_tuple.cpp
test/type_id_list.cpp
test/typed_message_view.cpp
test/typed_response_promise.cpp
test/typed_spawn.cpp
test/unit.cpp
...
...
libcaf_core/caf/const_typed_message_view.hpp
0 → 100644
View file @
ff2ad077
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2019 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#pragma once
#include "caf/detail/type_list.hpp"
#include "caf/message.hpp"
namespace
caf
{
template
<
class
...
Ts
>
class
const_typed_message_view
{
public:
explicit
const_typed_message_view
(
const
message
&
msg
)
noexcept
:
ptr_
(
msg
.
cvals
().
get
())
{
// nop
}
const_typed_message_view
()
=
delete
;
const_typed_message_view
(
const
const_typed_message_view
&
)
noexcept
=
default
;
const_typed_message_view
&
operator
=
(
const
const_typed_message_view
&
)
noexcept
=
default
;
const
detail
::
message_data
*
operator
->
()
const
noexcept
{
return
ptr_
;
}
private:
const
detail
::
message_data
*
ptr_
;
};
template
<
size_t
Position
,
class
...
Ts
>
const
auto
&
get
(
const
const_typed_message_view
<
Ts
...
>&
x
)
{
static_assert
(
Position
<
sizeof
...(
Ts
));
using
types
=
detail
::
type_list
<
Ts
...
>
;
using
type
=
detail
::
tl_at_t
<
types
,
Position
>
;
return
*
reinterpret_cast
<
const
type
*>
(
x
->
get
(
Position
));
}
}
// namespace caf
libcaf_core/caf/typed_message_view.hpp
0 → 100644
View file @
ff2ad077
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2019 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#pragma once
#include "caf/detail/type_list.hpp"
#include "caf/message.hpp"
namespace
caf
{
template
<
class
...
Ts
>
class
typed_message_view
{
public:
explicit
typed_message_view
(
message
&
msg
)
noexcept
:
ptr_
(
msg
.
vals
().
unshared_ptr
())
{
// nop
}
typed_message_view
()
=
delete
;
typed_message_view
(
const
typed_message_view
&
)
noexcept
=
default
;
typed_message_view
&
operator
=
(
const
typed_message_view
&
)
noexcept
=
default
;
detail
::
message_data
*
operator
->
()
noexcept
{
return
ptr_
;
}
private:
detail
::
message_data
*
ptr_
;
};
template
<
size_t
Position
,
class
...
Ts
>
auto
&
get
(
typed_message_view
<
Ts
...
>&
x
)
{
static_assert
(
Position
<
sizeof
...(
Ts
));
using
types
=
detail
::
type_list
<
Ts
...
>
;
using
type
=
detail
::
tl_at_t
<
types
,
Position
>
;
return
*
reinterpret_cast
<
type
*>
(
x
->
get_mutable
(
Position
));
}
}
// namespace caf
libcaf_core/test/const_typed_message_view.cpp
0 → 100644
View file @
ff2ad077
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2019 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#define CAF_SUITE const_typed_message_view
#include "caf/const_typed_message_view.hpp"
#include "caf/test/dsl.hpp"
#include "caf/make_message.hpp"
#include "caf/message.hpp"
using
namespace
caf
;
CAF_TEST
(
const
message
views
never
detach
their
content
)
{
auto
msg1
=
make_message
(
1
,
2
,
3
,
"four"
);
auto
msg2
=
msg1
;
CAF_REQUIRE
(
msg1
.
cvals
().
get
()
==
msg2
.
cvals
().
get
());
CAF_REQUIRE
(
msg1
.
match_elements
<
int
,
int
,
int
,
std
::
string
>
());
const_typed_message_view
<
int
,
int
,
int
,
std
::
string
>
view
{
msg1
};
CAF_REQUIRE
(
msg1
.
cvals
().
get
()
==
msg2
.
cvals
().
get
());
}
CAF_TEST
(
const
message
views
allow
access
via
get
)
{
auto
msg
=
make_message
(
1
,
2
,
3
,
"four"
);
CAF_REQUIRE
(
msg
.
match_elements
<
int
,
int
,
int
,
std
::
string
>
());
const_typed_message_view
<
int
,
int
,
int
,
std
::
string
>
view
{
msg
};
CAF_CHECK_EQUAL
(
get
<
0
>
(
view
),
1
);
CAF_CHECK_EQUAL
(
get
<
1
>
(
view
),
2
);
CAF_CHECK_EQUAL
(
get
<
2
>
(
view
),
3
);
CAF_CHECK_EQUAL
(
get
<
3
>
(
view
),
"four"
);
}
libcaf_core/test/typed_message_view.cpp
0 → 100644
View file @
ff2ad077
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2019 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#define CAF_SUITE typed_message_view
#include "caf/typed_message_view.hpp"
#include "caf/test/dsl.hpp"
#include "caf/make_message.hpp"
#include "caf/message.hpp"
using
namespace
caf
;
CAF_TEST
(
message
views
detach
their
content
)
{
auto
msg1
=
make_message
(
1
,
2
,
3
,
"four"
);
auto
msg2
=
msg1
;
CAF_REQUIRE
(
msg1
.
cvals
().
get
()
==
msg2
.
cvals
().
get
());
CAF_REQUIRE
(
msg1
.
match_elements
<
int
,
int
,
int
,
std
::
string
>
());
typed_message_view
<
int
,
int
,
int
,
std
::
string
>
view
{
msg1
};
CAF_REQUIRE
(
msg1
.
cvals
().
get
()
!=
msg2
.
cvals
().
get
());
}
CAF_TEST
(
message
views
allow
access
via
get
)
{
auto
msg
=
make_message
(
1
,
2
,
3
,
"four"
);
CAF_REQUIRE
(
msg
.
match_elements
<
int
,
int
,
int
,
std
::
string
>
());
typed_message_view
<
int
,
int
,
int
,
std
::
string
>
view
{
msg
};
CAF_CHECK_EQUAL
(
get
<
0
>
(
view
),
1
);
CAF_CHECK_EQUAL
(
get
<
1
>
(
view
),
2
);
CAF_CHECK_EQUAL
(
get
<
2
>
(
view
),
3
);
CAF_CHECK_EQUAL
(
get
<
3
>
(
view
),
"four"
);
}
CAF_TEST
(
message
views
allow
mutating
elements
)
{
auto
msg1
=
make_message
(
1
,
2
,
3
,
"four"
);
auto
msg2
=
msg1
;
CAF_REQUIRE
(
msg1
.
match_elements
<
int
,
int
,
int
,
std
::
string
>
());
typed_message_view
<
int
,
int
,
int
,
std
::
string
>
view
{
msg1
};
get
<
0
>
(
view
)
=
10
;
CAF_CHECK_EQUAL
(
msg1
.
get_as
<
int
>
(
0
),
10
);
CAF_CHECK_EQUAL
(
msg2
.
get_as
<
int
>
(
0
),
1
);
}
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