Commit 6c59a33d authored by Dominik Charousset's avatar Dominik Charousset

Streamline type_nr impl, add actor/addr vectors

parent 5ac8f9ab
......@@ -34,105 +34,97 @@
namespace caf {
namespace detail {
#define CAF_DETAIL_TYPE_NR(number, tname) \
template <> \
struct type_nr<tname> { \
static constexpr uint16_t value = number; \
};
template <class T,
bool IntegralConstant = std::is_integral<T>::value,
size_t = sizeof(T)>
struct type_nr_helper {
static constexpr uint16_t value = 0;
using strmap = std::map<std::string, std::string>;
// WARNING: types are sorted by uniform name
using sorted_builtin_types =
type_list<
actor, // @actor
std::vector<actor>, // @actorvec
actor_addr, // @addr
std::vector<actor_addr>, // @addrvec
atom_value, // @atom
channel, // @channel
std::vector<char>, // @charbuf
down_msg, // @down
duration, // @duration
exit_msg, // @exit
group, // @group
group_down_msg, // @group_down
int16_t, // @i16
int32_t, // @i32
int64_t, // @i64
int8_t, // @i8
long double, // @ldouble
message, // @message
message_id, // @message_id
node_id, // @node
std::string, // @str
strmap, // @strmap
std::set<std::string>, // @strset
std::vector<std::string>, // @strvec
sync_exited_msg, // @sync_exited
sync_timeout_msg, // @sync_timeout
timeout_msg, // @timeout
uint16_t, // @u16
std::u16string, // @u16_str
uint32_t, // @u32
std::u32string, // @u32_str
uint64_t, // @u64
uint8_t, // @u8
unit_t, // @unit
bool, // bool
double, // double
float // float
>;
using int_types_by_size =
type_list< // bytes
void, // 0
type_pair<int8_t, uint8_t>, // 1
type_pair<int16_t, uint16_t>, // 2
void, // 3
type_pair<int32_t, uint32_t>, // 4
void, // 5
void, // 6
void, // 7
type_pair<int64_t, uint64_t> // 8
>;
template <class T, bool IsIntegral = std::is_integral<T>::value>
struct type_nr {
static constexpr uint16_t value =
static_cast<uint16_t>(tl_find<sorted_builtin_types, T>::value + 1);
};
template <class T>
struct type_nr {
static constexpr uint16_t value = type_nr_helper<T>::value;
struct type_nr<T, true> {
using tpair = typename tl_at<int_types_by_size, sizeof(T)>::type;
using type =
typename std::conditional<
std::is_signed<T>::value,
typename tpair::first,
typename tpair::second
>::type;
static constexpr uint16_t value =
static_cast<uint16_t>(tl_find<sorted_builtin_types, type>::value + 1);
};
template <>
struct type_nr<void> {
static constexpr uint16_t value = 0;
struct type_nr<bool, true> {
static constexpr uint16_t value =
static_cast<uint16_t>(tl_find<sorted_builtin_types, bool>::value + 1);
};
using strmap = std::map<std::string, std::string>;
// WARNING: types are sorted by uniform name
CAF_DETAIL_TYPE_NR( 1, actor) // @actor
CAF_DETAIL_TYPE_NR( 2, actor_addr) // @addr
CAF_DETAIL_TYPE_NR( 3, atom_value) // @atom
CAF_DETAIL_TYPE_NR( 4, channel) // @channel
CAF_DETAIL_TYPE_NR( 5, std::vector<char>) // @charbuf
CAF_DETAIL_TYPE_NR( 6, down_msg) // @down
CAF_DETAIL_TYPE_NR( 7, duration) // @duration
CAF_DETAIL_TYPE_NR( 8, exit_msg) // @exit
CAF_DETAIL_TYPE_NR( 9, group) // @group
CAF_DETAIL_TYPE_NR(10, group_down_msg) // @group_down
CAF_DETAIL_TYPE_NR(11, int16_t) // @i16
CAF_DETAIL_TYPE_NR(12, int32_t) // @i32
CAF_DETAIL_TYPE_NR(13, int64_t) // @i64
CAF_DETAIL_TYPE_NR(14, int8_t) // @i8
CAF_DETAIL_TYPE_NR(15, long double) // @ldouble
CAF_DETAIL_TYPE_NR(16, message) // @message
CAF_DETAIL_TYPE_NR(17, message_id) // @message_id
CAF_DETAIL_TYPE_NR(18, node_id) // @node
CAF_DETAIL_TYPE_NR(19, std::string) // @str
CAF_DETAIL_TYPE_NR(20, strmap) // @strmap
CAF_DETAIL_TYPE_NR(21, std::set<std::string>) // @strset
CAF_DETAIL_TYPE_NR(22, std::vector<std::string>) // @strvec
CAF_DETAIL_TYPE_NR(23, sync_exited_msg) // @sync_exited
CAF_DETAIL_TYPE_NR(24, sync_timeout_msg) // @sync_timeout
CAF_DETAIL_TYPE_NR(25, timeout_msg) // @timeout
CAF_DETAIL_TYPE_NR(26, uint16_t) // @u16
CAF_DETAIL_TYPE_NR(27, std::u16string) // @u16_str
CAF_DETAIL_TYPE_NR(28, uint32_t) // @u32
CAF_DETAIL_TYPE_NR(29, std::u32string) // @u32_str
CAF_DETAIL_TYPE_NR(30, uint64_t) // @u64
CAF_DETAIL_TYPE_NR(31, uint8_t) // @u8
CAF_DETAIL_TYPE_NR(32, unit_t) // @unit
CAF_DETAIL_TYPE_NR(33, bool) // bool
CAF_DETAIL_TYPE_NR(34, double) // double
CAF_DETAIL_TYPE_NR(35, float) // float
template <atom_value V>
struct type_nr<atom_constant<V>> {
struct type_nr<atom_constant<V>, false> {
static constexpr uint16_t value = type_nr<atom_value>::value;
};
static constexpr size_t type_nrs = 36;
static constexpr size_t type_nrs = tl_size<sorted_builtin_types>::value + 1;
extern const char* numbered_type_names[];
template <class T>
struct type_nr_helper<T, true, 1> {
static constexpr uint16_t value = std::is_signed<T>::value
? type_nr<int8_t>::value
: type_nr<uint8_t>::value;
};
template <class T>
struct type_nr_helper<T, true, 2> {
static constexpr uint16_t value = std::is_signed<T>::value
? type_nr<int16_t>::value
: type_nr<uint16_t>::value;
};
template <class T>
struct type_nr_helper<T, true, 4> {
static constexpr uint16_t value = std::is_signed<T>::value
? type_nr<int32_t>::value
: type_nr<uint32_t>::value;
};
template <class T>
struct type_nr_helper<T, true, 8> {
static constexpr uint16_t value = std::is_signed<T>::value
? type_nr<int64_t>::value
: type_nr<uint64_t>::value;
};
template <uint32_t R, uint16_t... Is>
struct type_token_helper;
......
......@@ -17,8 +17,8 @@
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#ifndef CAF_TYPE_PAIR_HPP
#define CAF_TYPE_PAIR_HPP
#ifndef CAF_DETAIL_TYPE_PAIR_HPP
#define CAF_DETAIL_TYPE_PAIR_HPP
namespace caf {
namespace detail {
......@@ -27,28 +27,24 @@ template <class First, typename Second>
struct type_pair {
using first = First;
using second = Second;
};
template <class First, typename Second>
struct to_type_pair {
using type = type_pair<First, Second>;
};
template <class What>
struct is_type_pair {
static constexpr bool value = false;
};
template <class First, typename Second>
struct is_type_pair<type_pair<First, Second>> {
static constexpr bool value = true;
};
} // namespace detail
} // namespace caf
#endif // CAF_TYPE_PAIR_HPP
#endif // CAF_DETAIL_TYPE_PAIR_HPP
......@@ -55,7 +55,9 @@ namespace detail {
const char* numbered_type_names[] = {
"@actor",
"@actorvec",
"@addr",
"@addrvec",
"@atom",
"@channel",
"@charbuf",
......@@ -444,6 +446,11 @@ class uti_impl : public uniform_type_info {
}
};
template <class T>
struct get_uti_impl {
using type = uti_impl<T>;
};
template <class T>
class int_tinfo : public uniform_type_info {
public:
......@@ -583,36 +590,6 @@ void fill_uti_arr(std::integral_constant<size_t, N>, type_array& arr, const T& t
class utim_impl : public uniform_type_info_map {
public:
void initialize() {
/*
// maps sizeof(integer_type) to {signed_type, unsigned_type}
constexpr auto u8t = tl_find<builtin_types, int_tinfo<uint8_t>>::value;
constexpr auto i8t = tl_find<builtin_types, int_tinfo<int8_t>>::value;
constexpr auto u16t = tl_find<builtin_types, int_tinfo<uint16_t>>::value;
constexpr auto i16t = tl_find<builtin_types, int_tinfo<int16_t>>::value;
constexpr auto u32t = tl_find<builtin_types, int_tinfo<uint32_t>>::value;
constexpr auto i32t = tl_find<builtin_types, int_tinfo<int32_t>>::value;
constexpr auto u64t = tl_find<builtin_types, int_tinfo<uint64_t>>::value;
constexpr auto i64t = tl_find<builtin_types, int_tinfo<int64_t>>::value;
abstract_int_tinfo* mapping[][2] = {
{nullptr, nullptr}, // no integer type for sizeof(T) == 0
{&get<u8t>(m_storage), &get<i8t>(m_storage)},
{&get<u16t>(m_storage), &get<i16t>(m_storage)},
{nullptr, nullptr}, // no integer type for sizeof(T) == 3
{&get<u32t>(m_storage), &get<i32t>(m_storage)},
{nullptr, nullptr}, // no integer type for sizeof(T) == 5
{nullptr, nullptr}, // no integer type for sizeof(T) == 6
{nullptr, nullptr}, // no integer type for sizeof(T) == 7
{&get<u64t>(m_storage), &get<i64t>(m_storage)}
};
push_native_type<char, signed char, unsigned char, short, signed short,
unsigned short, short int, signed short int,
unsigned short int, int, signed int, unsigned int,
long int, signed long int, unsigned long int, long,
signed long, unsigned long, long long, signed long long,
unsigned long long, wchar_t, int8_t, uint8_t, int16_t,
uint16_t, int32_t, uint32_t, int64_t, uint64_t, char16_t,
char32_t, size_t, ptrdiff_t, intptr_t>(mapping);
*/
fill_uti_arr(std::integral_constant<size_t, 0>{},
m_builtin_types, m_storage);
// make sure our builtin types are sorted
......@@ -691,41 +668,14 @@ class utim_impl : public uniform_type_info_map {
using strvec = std::vector<std::string>;
using builtin_types = std::tuple<uti_impl<actor>,
uti_impl<actor_addr>,
uti_impl<atom_value>,
uti_impl<channel>,
uti_impl<charbuf>,
uti_impl<down_msg>,
uti_impl<duration>,
uti_impl<exit_msg>,
uti_impl<group>,
uti_impl<group_down_msg>,
uti_impl<int16_t>,
uti_impl<int32_t>,
uti_impl<int64_t>,
uti_impl<int8_t>,
uti_impl<long double>,
uti_impl<message>,
uti_impl<message_id>,
uti_impl<node_id>,
uti_impl<std::string>,
uti_impl<strmap>,
uti_impl<std::set<std::string>>,
uti_impl<strvec>,
uti_impl<sync_exited_msg>,
uti_impl<sync_timeout_msg>,
uti_impl<timeout_msg>,
uti_impl<uint16_t>,
uti_impl<std::u16string>,
uti_impl<uint32_t>,
uti_impl<std::u32string>,
uti_impl<uint64_t>,
uti_impl<uint8_t>,
uti_impl<unit_t>,
uti_impl<bool>,
uti_impl<double>,
uti_impl<float>>;
using builtin_types =
typename tl_apply<
typename tl_map<
sorted_builtin_types,
get_uti_impl
>::type,
std::tuple
>::type;
builtin_types m_storage;
......@@ -743,7 +693,7 @@ class utim_impl : public uniform_type_info_map {
using pointer_pair = std::pair<uniform_type_info*, std::type_info*>;
// bot containers are sorted by uniform name (m_user_types: second->name())
std::array<pointer, std::tuple_size<builtin_types>::value> m_builtin_types;
std::array<pointer, type_nrs - 1> m_builtin_types;
std::vector<enriched_pointer> m_user_types;
mutable detail::shared_spinlock m_lock;
......
......@@ -163,7 +163,9 @@ int main() {
{"@<>+@atom", 0},
{"@unit", tnr<unit_t>()},
{"@actor", tnr<actor>()},
{"@actorvec", tnr<std::vector<actor>>()},
{"@addr", tnr<actor_addr>()},
{"@addrvec", tnr<std::vector<actor_addr>>()},
{"@atom", tnr<atom_value>()},
{"@channel", tnr<channel>()},
{"@charbuf", tnr<std::vector<char>>()},
......
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