Commit 283daeb7 authored by Dominik Charousset's avatar Dominik Charousset

Make stream_id comparable

parent ef5181c4
......@@ -95,6 +95,7 @@ set (LIBCAF_CORE_SRCS
src/skip.cpp
src/splitter.cpp
src/stream.cpp
src/stream_id.cpp
src/stream_handler.cpp
src/stream_msg_visitor.cpp
src/stream_multiplexer.cpp
......
......@@ -67,6 +67,7 @@ class node_id;
class behavior;
class duration;
class resumable;
class stream_id;
class actor_addr;
class actor_pool;
class message_id;
......@@ -115,7 +116,6 @@ class forwarding_actor_proxy;
struct unit_t;
struct exit_msg;
struct down_msg;
struct stream_id;
struct stream_msg;
struct timeout_msg;
struct group_down_msg;
......
......@@ -25,21 +25,26 @@
#include "caf/meta/type_name.hpp"
#include "caf/actor_control_block.hpp"
#include "caf/detail/comparable.hpp"
namespace caf {
struct stream_id {
class stream_id : detail::comparable<stream_id> {
public:
stream_id() = default;
stream_id(stream_id&&) = default;
stream_id(const stream_id&) = default;
stream_id& operator=(stream_id&&) = default;
stream_id& operator=(const stream_id&) = default;
stream_id(strong_actor_ptr origin_actor, uint64_t origin_nr);
int64_t compare(const stream_id& other) const;
strong_actor_ptr origin;
uint64_t nr;
};
inline bool operator==(const stream_id& x, const stream_id& y) {
return x.origin == y.origin && x.nr == y.nr;
}
inline bool operator<(const stream_id& x, const stream_id& y) {
return x.origin == y.origin ? x.nr < y.nr : x.origin < y.origin;
}
template <class Inspector>
typename Inspector::result_type inspect(Inspector& f, stream_id& x) {
return f(meta::type_name("stream_id"), x.origin, x.nr);
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2017 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* 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. *
******************************************************************************/
#include "caf/stream_id.hpp"
#include <cstddef>
namespace caf {
stream_id::stream_id(strong_actor_ptr origin_actor, uint64_t origin_nr)
: origin(std::move(origin_actor)),
nr(origin_nr) {
// nop
}
int64_t stream_id::compare(const stream_id& other) const {
auto r0 = static_cast<ptrdiff_t>(origin.get() - other.origin.get());
if (r0 != 0)
return static_cast<int64_t>(r0);
return static_cast<int64_t>(nr) - static_cast<int64_t>(other.nr);
}
} // namespace caf
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment