/************************************************************************************ * * * Copyright (c) 2014, 2015 - 2017 Axel Menzel * * * * This file is part of RTTR (Run Time Type Reflection) * * License: MIT License * * * * Permission is hereby granted, free of charge, to any person obtaining * * a copy of this software and associated documentation files (the "Software"), * * to deal in the Software without restriction, including without limitation * * the rights to use, copy, modify, merge, publish, distribute, sublicense, * * and/or sell copies of the Software, and to permit persons to whom the * * Software is furnished to do so, subject to the following conditions: * * * * The above copyright notice and this permission notice shall be included in * * all copies or substantial portions of the Software. * * * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * * SOFTWARE. * * * *************************************************************************************/ #ifndef RTTR_REGISTER_WRAPPER_MAPPER_CONVERSION_H_ #define RTTR_REGISTER_WRAPPER_MAPPER_CONVERSION_H_ #include "rttr/detail/base/core_prerequisites.h" #include "rttr/detail/misc/misc_type_traits.h" #include namespace rttr { template struct type_list; namespace detail { /*! * Determine if the given type \a T has a wrapper_mapper method called `convert`. */ template class has_conversion_function_impl { typedef char YesType[1]; typedef char NoType[2]; template static YesType& check(decltype(&wrapper_mapper::convert)); template static NoType& check(...); public: static RTTR_CONSTEXPR_OR_CONST bool value = (sizeof(check>(0)) != sizeof(YesType)); }; /*! * If \a T has a wrapper_mapper function `convert` then is the same like `std::true_type`, otherwise inherits from `std::false_type`. */ template using has_wrapper_conv_func = std::integral_constant::value>; ///////////////////////////////////////////////////////////////////////////////////// /*! * Registers for the given type \p DerivedClass a conversion function * from \ref wrapper_mapper from and to the types in the list `T...`. */ template struct create_wrapper_conversion; template struct create_wrapper_conversion { static RTTR_INLINE void perform() { } }; template struct create_wrapper_conversion { static RTTR_INLINE void perform() { static_assert(has_base_class_list::value, "The parent class has no base class list defined - please use the macro RTTR_ENABLE"); type::register_converter_func(wrapper_mapper::template convert); using return_type = typename function_traits::template convert)>::return_type; // TO DO: remove raw_type_t, std::shared_ptr should also be converted, when necessary using wrapped_derived_t = raw_type_t>; type::register_converter_func(wrapper_mapper::template convert); create_wrapper_conversion::perform(); // continue with the rest create_wrapper_conversion::perform(); } }; template struct create_wrapper_conversion> : create_wrapper_conversion { }; ///////////////////////////////////////////////////////////////////////////////////// template struct reg_wrapper_converter_for_base_classes { reg_wrapper_converter_for_base_classes() { } }; template struct reg_wrapper_converter_for_base_classes::value && has_base_class_list>>::value>::type> { reg_wrapper_converter_for_base_classes() { create_wrapper_conversion>::base_class_list>::perform(); } }; ///////////////////////////////////////////////////////////////////////////////////// } // end namespace detail } // end namespace rttr #endif // RTTR_REGISTER_WRAPPER_MAPPER_CONVERSION_H_