/* * Copyright 2019 by its authors. See AUTHORS. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef ELDBUS_SIGNATURE_TRAITS_HH_ #define ELDBUS_SIGNATURE_TRAITS_HH_ #include #include namespace efl { namespace eldbus { namespace _detail { template struct signature_traits; template <> struct signature_traits { typedef Eina_Bool raw_type; typedef bool value_type; typedef std::integral_constant sig_size; static int const sig = 'b'; static raw_type to_raw(value_type v) { return v ? EINA_TRUE : EINA_FALSE; } }; template <> struct signature_traits { typedef char raw_type; typedef raw_type value_type; typedef std::integral_constant sig_size; static int const sig = 'y'; static raw_type to_raw(value_type v) { return v; } }; template <> struct signature_traits { typedef int16_t raw_type; typedef raw_type value_type; typedef std::integral_constant sig_size; static char const sig = 'n'; static raw_type to_raw(value_type v) { return v; } }; template <> struct signature_traits { typedef uint16_t raw_type; typedef raw_type value_type; typedef std::integral_constant sig_size; static char const sig = 'q'; static raw_type to_raw(value_type i) { return i; } }; template <> struct signature_traits { typedef int32_t raw_type; typedef raw_type value_type; typedef std::integral_constant sig_size; static char const sig = 'i'; static raw_type to_raw(value_type i) { return i; } }; template <> struct signature_traits { typedef uint32_t raw_type; typedef raw_type value_type; typedef std::integral_constant sig_size; static char const sig = 'u'; static raw_type to_raw(value_type i) { return i; } }; template <> struct signature_traits { typedef int64_t raw_type; typedef raw_type value_type; typedef std::integral_constant sig_size; static char const sig = 'x'; static raw_type to_raw(value_type i) { return i; } }; template <> struct signature_traits { typedef uint64_t raw_type; typedef raw_type value_type; typedef std::integral_constant sig_size; static char const sig = 't'; static raw_type to_raw(value_type i) { return i; } }; template <> struct signature_traits { typedef double raw_type; typedef raw_type value_type; typedef std::integral_constant sig_size; static char const sig = 'd'; static raw_type to_raw(value_type i) { return i; } }; template <> struct signature_traits { typedef const char* raw_type; typedef std::string value_type; typedef std::integral_constant sig_size; static char const sig = 's'; static raw_type to_raw(std::string const& s) { return s.c_str(); } }; template struct signature_traits : signature_traits { }; template typename signature_traits::raw_type to_raw(T const& object) { return signature_traits::to_raw(object); } constexpr std::size_t add(std::size_t N) { return N; } constexpr std::size_t add(std::size_t L, std::size_t R) { return L + R; } template constexpr std::size_t add(std::size_t L, std::size_t R, T ... O) { return L + R + add(O...); } template struct signature_size_impl; template struct signature_size_impl > : std::integral_constant ::type>::sig_size::value...)> { }; template struct signature_size : signature_size_impl::value> > { }; template void call_all(T...) {} template ::type> int init_signature(char (&signature)[N]) { signature[I] = signature_traits::type>::sig; return 0; } template int init_signature(char (&signature)[I+1]) { signature[I] = 0; return 0; } template void init_signature_array(char (&signature)[N], eina::index_sequence) { call_all(_detail::init_signature >(signature)...); } } } } #endif