Commit 537de9e6 authored by Dominik Charousset's avatar Dominik Charousset

Move rtti_pair to its own header

parent 2aad39d0
...@@ -43,11 +43,7 @@ behavior. ...@@ -43,11 +43,7 @@ behavior.
\begin{center} \begin{center}
\begin{tabular}{ll} \begin{tabular}{ll}
\textbf{Types} & ~ \\ \textbf{Observers} & ~ \\
\hline
\lstinline^rtti_pair^ & \lstinline^std::pair<uint16_t, const std::type_info*>^ \\
\hline
~ & ~ \\ \textbf{Observers} & ~ \\
\hline \hline
\lstinline^bool empty()^ & Returns whether this message is empty. \\ \lstinline^bool empty()^ & Returns whether this message is empty. \\
\hline \hline
......
...@@ -91,6 +91,7 @@ set(LIBCAF_CORE_SRCS ...@@ -91,6 +91,7 @@ set(LIBCAF_CORE_SRCS
src/response_promise.cpp src/response_promise.cpp
src/resumable.cpp src/resumable.cpp
src/ripemd_160.cpp src/ripemd_160.cpp
src/rtti_pair.cpp
src/runtime_settings_map.cpp src/runtime_settings_map.cpp
src/scheduled_actor.cpp src/scheduled_actor.cpp
src/scoped_actor.cpp src/scoped_actor.cpp
......
...@@ -53,14 +53,6 @@ ...@@ -53,14 +53,6 @@
namespace caf { namespace caf {
using rtti_pair = std::pair<uint16_t, const std::type_info*>;
using rtti_pair_vec = std::vector<rtti_pair>;
using rtti_pair_vec_triple = std::tuple<rtti_pair_vec,
rtti_pair_vec,
rtti_pair_vec>;
template <class T> template <class T>
struct mpi_field_access { struct mpi_field_access {
std::string operator()(const uniform_type_info_map& types) { std::string operator()(const uniform_type_info_map& types) {
......
...@@ -21,11 +21,12 @@ ...@@ -21,11 +21,12 @@
#include <tuple> #include <tuple>
#include <stdexcept> #include <stdexcept>
#include "caf/type_nr.hpp"
#include "caf/serializer.hpp"
#include "caf/deserializer.hpp"
#include "caf/deep_to_string.hpp" #include "caf/deep_to_string.hpp"
#include "caf/deserializer.hpp"
#include "caf/make_type_erased_value.hpp" #include "caf/make_type_erased_value.hpp"
#include "caf/rtti_pair.hpp"
#include "caf/serializer.hpp"
#include "caf/type_nr.hpp"
#include "caf/detail/type_list.hpp" #include "caf/detail/type_list.hpp"
#include "caf/detail/safe_equal.hpp" #include "caf/detail/safe_equal.hpp"
...@@ -65,20 +66,6 @@ struct void_ptr_access { ...@@ -65,20 +66,6 @@ struct void_ptr_access {
} }
}; };
template <class T, uint16_t N = type_nr<T>::value>
struct tuple_vals_type_helper {
static typename message_data::rtti_pair get() noexcept {
return {N, nullptr};
}
};
template <class T>
struct tuple_vals_type_helper<T, 0> {
static typename message_data::rtti_pair get() noexcept {
return {0, &typeid(T)};
}
};
template <class Base, class... Ts> template <class Base, class... Ts>
class tuple_vals_impl : public Base { class tuple_vals_impl : public Base {
public: public:
...@@ -90,8 +77,6 @@ public: ...@@ -90,8 +77,6 @@ public:
using super = message_data; using super = message_data;
using rtti_pair = typename message_data::rtti_pair;
using data_type = std::tuple<Ts...>; using data_type = std::tuple<Ts...>;
// -- friend functions ------------------------------------------------------- // -- friend functions -------------------------------------------------------
...@@ -107,7 +92,7 @@ public: ...@@ -107,7 +92,7 @@ public:
template <class... Us> template <class... Us>
tuple_vals_impl(Us&&... xs) tuple_vals_impl(Us&&... xs)
: data_(std::forward<Us>(xs)...), : data_(std::forward<Us>(xs)...),
types_{{tuple_vals_type_helper<Ts>::get()...}} { types_{{make_rtti_pair<Ts>()...}} {
// nop // nop
} }
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| 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 <cstdint>
#include <type_traits>
#include <typeinfo>
#include <utility>
#include "caf/type_nr.hpp"
namespace caf {
/// Bundles the type number with its C++ `type_info` object. The type number is
/// non-zero for builtin types and the pointer to the `type_info` object is
/// non-null for custom types.
using rtti_pair = std::pair<uint16_t, const std::type_info*>;
/// @relates rtti_pair
template <class T>
typename std::enable_if<type_nr<T>::value == 0, rtti_pair>::type
make_rtti_pair() {
return {0, &typeid(T)};
}
/// @relates rtti_pair
template <class T>
typename std::enable_if<type_nr<T>::value != 0, rtti_pair>::type
make_rtti_pair() {
auto n = type_nr<T>::value;
return {n, nullptr};
}
/// @relates rtti_pair
std::string to_string(rtti_pair x);
} // namespace caf
...@@ -23,24 +23,20 @@ ...@@ -23,24 +23,20 @@
#include <cstdint> #include <cstdint>
#include <typeinfo> #include <typeinfo>
#include "caf/detail/apply_args.hpp"
#include "caf/detail/pseudo_tuple.hpp"
#include "caf/detail/try_match.hpp"
#include "caf/fwd.hpp" #include "caf/fwd.hpp"
#include "caf/type_nr.hpp"
#include "caf/optional.hpp" #include "caf/optional.hpp"
#include "caf/rtti_pair.hpp"
#include "caf/type_erased_value.hpp" #include "caf/type_erased_value.hpp"
#include "caf/type_nr.hpp"
#include "caf/detail/try_match.hpp"
#include "caf/detail/apply_args.hpp"
#include "caf/detail/pseudo_tuple.hpp"
namespace caf { namespace caf {
/// Represents a tuple of type-erased values. /// Represents a tuple of type-erased values.
class type_erased_tuple { class type_erased_tuple {
public: public:
// -- member types -----------------------------------------------------------
using rtti_pair = std::pair<uint16_t, const std::type_info*>;
// -- constructors, destructors, and assignment operators -------------------- // -- constructors, destructors, and assignment operators --------------------
type_erased_tuple() = default; type_erased_tuple() = default;
......
...@@ -22,8 +22,9 @@ ...@@ -22,8 +22,9 @@
#include <typeinfo> #include <typeinfo>
#include <functional> #include <functional>
#include "caf/fwd.hpp"
#include "caf/error.hpp" #include "caf/error.hpp"
#include "caf/fwd.hpp"
#include "caf/rtti_pair.hpp"
#include "caf/type_nr.hpp" #include "caf/type_nr.hpp"
namespace caf { namespace caf {
...@@ -31,10 +32,6 @@ namespace caf { ...@@ -31,10 +32,6 @@ namespace caf {
/// Represents a single type-erased value. /// Represents a single type-erased value.
class type_erased_value { class type_erased_value {
public: public:
// -- member types -----------------------------------------------------------
using rtti_pair = std::pair<uint16_t, const std::type_info*>;
// -- constructors, destructors, and assignment operators -------------------- // -- constructors, destructors, and assignment operators --------------------
virtual ~type_erased_value(); virtual ~type_erased_value();
......
...@@ -77,7 +77,7 @@ uint32_t concatenated_tuple::type_token() const noexcept { ...@@ -77,7 +77,7 @@ uint32_t concatenated_tuple::type_token() const noexcept {
return type_token_; return type_token_;
} }
message_data::rtti_pair concatenated_tuple::type(size_t pos) const noexcept { rtti_pair concatenated_tuple::type(size_t pos) const noexcept {
CAF_ASSERT(pos < size()); CAF_ASSERT(pos < size());
auto selected = select(pos); auto selected = select(pos);
return selected.first->type(selected.second); return selected.first->type(selected.second);
......
...@@ -71,7 +71,7 @@ uint32_t decorated_tuple::type_token() const noexcept { ...@@ -71,7 +71,7 @@ uint32_t decorated_tuple::type_token() const noexcept {
return type_token_; return type_token_;
} }
message_data::rtti_pair decorated_tuple::type(size_t pos) const noexcept { rtti_pair decorated_tuple::type(size_t pos) const noexcept {
CAF_ASSERT(pos < size()); CAF_ASSERT(pos < size());
return decorated_->type(mapping_[pos]); return decorated_->type(mapping_[pos]);
} }
......
...@@ -77,7 +77,7 @@ uint32_t merged_tuple::type_token() const noexcept { ...@@ -77,7 +77,7 @@ uint32_t merged_tuple::type_token() const noexcept {
return type_token_; return type_token_;
} }
merged_tuple::rtti_pair merged_tuple::type(size_t pos) const noexcept { rtti_pair merged_tuple::type(size_t pos) const noexcept {
CAF_ASSERT(pos < mapping_.size()); CAF_ASSERT(pos < mapping_.size());
auto& p = mapping_[pos]; auto& p = mapping_[pos];
return data_[p.first]->type(p.second); return data_[p.first]->type(p.second);
......
...@@ -77,7 +77,7 @@ uint32_t message::type_token() const noexcept { ...@@ -77,7 +77,7 @@ uint32_t message::type_token() const noexcept {
return vals_ != nullptr ? vals_->type_token() : 0xFFFFFFFF; return vals_ != nullptr ? vals_->type_token() : 0xFFFFFFFF;
} }
message::rtti_pair message::type(size_t pos) const noexcept { rtti_pair message::type(size_t pos) const noexcept {
CAF_ASSERT(vals_ != nullptr); CAF_ASSERT(vals_ != nullptr);
return vals_->type(pos); return vals_->type(pos);
} }
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| 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. *
******************************************************************************/
#include "caf/rtti_pair.hpp"
namespace caf {
std::string to_string(rtti_pair x) {
std::string result = "(";
result += std::to_string(x.first);
result += ", ";
result += x.second != nullptr ? x.second->name() : "<null>";
result += ")";
return result;
}
} // namespace caf
...@@ -16,16 +16,18 @@ ...@@ -16,16 +16,18 @@
* http://www.boost.org/LICENSE_1_0.txt. * * http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/ ******************************************************************************/
#include "caf/config.hpp" #include "caf/message.hpp"
#define CAF_SUITE match #define CAF_SUITE match
#include "caf/test/unit_test.hpp" #include "caf/test/unit_test.hpp"
#include <functional> #include <functional>
#include "caf/make_type_erased_tuple_view.hpp"
#include "caf/message_builder.hpp" #include "caf/message_builder.hpp"
#include "caf/message_handler.hpp" #include "caf/message_handler.hpp"
#include "caf/make_type_erased_tuple_view.hpp" #include "caf/rtti_pair.hpp"
using namespace caf; using namespace caf;
using namespace std; using namespace std;
...@@ -35,17 +37,6 @@ using ho_atom = atom_constant<atom("ho")>; ...@@ -35,17 +37,6 @@ using ho_atom = atom_constant<atom("ho")>;
namespace { namespace {
using rtti_pair = std::pair<uint16_t, const std::type_info*>;
std::string to_string(const rtti_pair& x) {
std::string result = "(";
result += std::to_string(x.first);
result += ", ";
result += x.second != nullptr ? x.second->name() : "<null>";
result += ")";
return result;
}
struct fixture { struct fixture {
using array_type = std::array<bool, 4>; using array_type = std::array<bool, 4>;
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| 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 rtti_pair
#include "caf/rtti_pair.hpp"
#include "caf/test/dsl.hpp"
using namespace caf;
namespace {
struct foo {
int x;
int y;
};
} // namespace <anonymous>
CAF_TEST(make_rtti_pair) {
auto n = type_nr<int32_t>::value;
CAF_REQUIRE_NOT_EQUAL(n, 0u);
auto x1 = make_rtti_pair<int32_t>();
CAF_CHECK_EQUAL(x1.first, n);
CAF_CHECK_EQUAL(x1.second, nullptr);
auto x2 = make_rtti_pair<foo>();
CAF_CHECK_EQUAL(x2.first, 0);
CAF_CHECK_EQUAL(x2.second, &typeid(foo));
}
CAF_TEST(to_string) {
auto n = type_nr<int32_t>::value;
CAF_CHECK_EQUAL(to_string(make_rtti_pair<int32_t>()),
"(" + std::to_string(n) + ", <null>)");
}
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