Commit 69f75141 authored by Dominik Charousset's avatar Dominik Charousset

Fix type mismatches in data processor

parent 084ec5f9
...@@ -32,9 +32,11 @@ ...@@ -32,9 +32,11 @@
#include "caf/detail/type_list.hpp" #include "caf/detail/type_list.hpp"
#include "caf/detail/apply_args.hpp" #include "caf/detail/apply_args.hpp"
#include "caf/detail/delegate_serialize.hpp" #include "caf/detail/delegate_serialize.hpp"
#include "caf/detail/select_integer_type.hpp"
namespace caf { namespace caf {
/// A data processor translates an object into a format that can be /// A data processor translates an object into a format that can be
/// stored or vice versa. A data processor can be either in saving /// stored or vice versa. A data processor can be either in saving
/// or loading mode. /// or loading mode.
...@@ -111,10 +113,26 @@ public: ...@@ -111,10 +113,26 @@ public:
/// Applies this processor to an arithmetic type. /// Applies this processor to an arithmetic type.
template <class T> template <class T>
typename std::enable_if<std::is_arithmetic<T>::value>::type typename std::enable_if<std::is_floating_point<T>::value>::type
apply(T& x) {
static constexpr auto tlindex = detail::tl_index_of<builtin_t, T>::value;
static_assert(tlindex >= 0, "T not recognized as builtiln type");
apply_builtin(static_cast<builtin>(tlindex), &x);
}
template <class T>
typename std::enable_if<
std::is_integral<T>::value
&& ! std::is_same<bool, T>::value
>::type
apply(T& x) { apply(T& x) {
apply_builtin(static_cast<builtin>(detail::tl_index_of<builtin_t, T>::value), using type =
&x); typename detail::select_integer_type<
static_cast<int>(sizeof(T)) * (std::is_signed<T>::value ? -1 : 1)
>::type;
static constexpr auto tlindex = detail::tl_index_of<builtin_t, type>::value;
static_assert(tlindex >= 0, "T not recognized as builtiln type");
apply_builtin(static_cast<builtin>(tlindex), &x);
} }
void apply(std::string& x) { void apply(std::string& x) {
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2015 *
* 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. *
******************************************************************************/
#ifndef CAF_DETAIL_SELECT_INTEGER_TYPE_HPP
#define CAF_DETAIL_SELECT_INTEGER_TYPE_HPP
#include <cstdint>
namespace caf {
namespace detail {
template <int>
struct select_integer_type;
template <>
struct select_integer_type<-1> {
using type = int8_t;
};
template <>
struct select_integer_type<1> {
using type = uint8_t;
};
template <>
struct select_integer_type<-2> {
using type = int16_t;
};
template <>
struct select_integer_type<2> {
using type = uint16_t;
};
template <>
struct select_integer_type<-4> {
using type = int32_t;
};
template <>
struct select_integer_type<4> {
using type = uint32_t;
};
template <>
struct select_integer_type<-8> {
using type = int64_t;
};
template <>
struct select_integer_type<8> {
using type = uint64_t;
};
} // namespace detail
} // namespace caf
#endif // CAF_DETAIL_SELECT_INTEGER_TYPE_HPP
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