-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add possiblitiy to register a function of a base class
during register of a derived class. Internally the base class will be extracted from the member function pointer an added to the base class list of the derived class. Example and use case: --------------------- struct base { void some_method() {} }; struct derived : base { }; registration::class_<derived>("derived") .method("some_method", &derived::some_method); dereived d; type::get(d).get_method("some_method").invoke(d); // now this is possible
- Loading branch information
Showing
6 changed files
with
230 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
src/rttr/detail/registration/register_base_class_from_accessor.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/************************************************************************************ | ||
* * | ||
* Copyright (c) 2014, 2015 - 2017 Axel Menzel <info@rttr.org> * | ||
* * | ||
* 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_BASE_CLASS_FROM_ACCESSOR_H_ | ||
#define RTTR_REGISTER_BASE_CLASS_FROM_ACCESSOR_H_ | ||
|
||
#include "rttr/detail/base/core_prerequisites.h" | ||
|
||
#include "rttr/detail/type/base_classes.h" | ||
#include "rttr/detail/type/type_register.h" | ||
|
||
#include <type_traits> | ||
|
||
namespace rttr | ||
{ | ||
namespace detail | ||
{ | ||
|
||
template<typename ClassType, typename FuncClassType> | ||
enable_if_t<contains<FuncClassType, typename ClassType::base_class_list>::value, void> | ||
register_member_func_class_type_when_needed_3() | ||
{ | ||
} | ||
|
||
template<typename ClassType, typename FuncClassType> | ||
enable_if_t<!contains<FuncClassType, typename ClassType::base_class_list>::value, void> | ||
register_member_func_class_type_when_needed_3() | ||
{ | ||
base_class_info baseClassInfo = { type::get<FuncClassType>(), &rttr_cast_impl<ClassType, FuncClassType> }; | ||
type_register::register_base_class(type::get<ClassType>(), baseClassInfo); | ||
} | ||
|
||
template<typename ClassType, typename FuncClassType> | ||
enable_if_t<has_base_class_list<ClassType>::value, void> | ||
register_member_func_class_type_when_needed_2() | ||
{ | ||
register_member_func_class_type_when_needed_3<ClassType, FuncClassType>(); | ||
} | ||
|
||
template<typename ClassType, typename FuncClassType> | ||
enable_if_t<!has_base_class_list<ClassType>::value, void> | ||
register_member_func_class_type_when_needed_2() | ||
{ | ||
base_class_info baseClassInfo = { type::get<FuncClassType>(), &rttr_cast_impl<ClassType, FuncClassType> }; | ||
type_register::register_base_class(type::get<ClassType>(), baseClassInfo); | ||
|
||
} | ||
|
||
template<typename ClassType, typename FuncClassType> | ||
enable_if_t<std::is_base_of<FuncClassType, ClassType>::value, void> | ||
register_member_func_class_type_when_needed_1() | ||
{ | ||
register_member_func_class_type_when_needed_2<ClassType, FuncClassType>(); | ||
} | ||
|
||
template<typename ClassType, typename FuncClassType> | ||
enable_if_t<!std::is_base_of<FuncClassType, ClassType>::value, void> | ||
register_member_func_class_type_when_needed_1() | ||
{ | ||
} | ||
|
||
template<typename ClassType, typename FuncClassType> | ||
enable_if_t<!std::is_same<ClassType, FuncClassType>::value, void> | ||
register_member_func_class_type_when_needed() | ||
{ | ||
register_member_func_class_type_when_needed_1<ClassType, FuncClassType>(); | ||
} | ||
|
||
template<typename ClassType, typename FuncClassType> | ||
enable_if_t<std::is_same<ClassType, FuncClassType>::value, void> | ||
register_member_func_class_type_when_needed() | ||
{ | ||
} | ||
|
||
template<typename ClassType, typename F> | ||
enable_if_t<std::is_member_function_pointer<F>::value, void> | ||
register_accessor_class_type_when_needed() | ||
{ | ||
register_member_func_class_type_when_needed<ClassType, typename function_traits<F>::class_type>(); | ||
} | ||
|
||
template<typename ClassType, typename F> | ||
enable_if_t<!std::is_member_function_pointer<F>::value, void> | ||
register_accessor_class_type_when_needed() | ||
{ | ||
} | ||
|
||
} // end namespace detail | ||
} // end namespace rttr | ||
|
||
#endif // RTTR_REGISTER_BASE_CLASS_FROM_ACCESSOR_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters