method.cpp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /************************************************************************************
  2. * *
  3. * Copyright (c) 2014 - 2018 Axel Menzel <info@rttr.org> *
  4. * *
  5. * This file is part of RTTR (Run Time Type Reflection) *
  6. * License: MIT License *
  7. * *
  8. * Permission is hereby granted, free of charge, to any person obtaining *
  9. * a copy of this software and associated documentation files (the "Software"), *
  10. * to deal in the Software without restriction, including without limitation *
  11. * the rights to use, copy, modify, merge, publish, distribute, sublicense, *
  12. * and/or sell copies of the Software, and to permit persons to whom the *
  13. * Software is furnished to do so, subject to the following conditions: *
  14. * *
  15. * The above copyright notice and this permission notice shall be included in *
  16. * all copies or substantial portions of the Software. *
  17. * *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
  24. * SOFTWARE. *
  25. * *
  26. *************************************************************************************/
  27. #include "rttr/method.h"
  28. #include "rttr/detail/method/method_wrapper_base.h"
  29. #include "rttr/argument.h"
  30. #include "rttr/instance.h"
  31. using namespace std;
  32. namespace rttr
  33. {
  34. namespace detail
  35. {
  36. template<>
  37. method create_item(const method_wrapper_base* wrapper)
  38. {
  39. return method(wrapper);
  40. }
  41. template<>
  42. method create_invalid_item()
  43. {
  44. static const method_wrapper_base invalid_wrapper(string_view(), detail::get_invalid_type());
  45. return method(&invalid_wrapper);
  46. }
  47. } // end namespace detail;
  48. /////////////////////////////////////////////////////////////////////////////////////////
  49. method::method(const detail::method_wrapper_base* wrapper) RTTR_NOEXCEPT
  50. : m_wrapper(wrapper)
  51. {
  52. }
  53. /////////////////////////////////////////////////////////////////////////////////////////
  54. bool method::is_valid() const RTTR_NOEXCEPT
  55. {
  56. return m_wrapper->is_valid();
  57. }
  58. /////////////////////////////////////////////////////////////////////////////////////////
  59. method::operator bool() const RTTR_NOEXCEPT
  60. {
  61. return m_wrapper->is_valid();
  62. }
  63. /////////////////////////////////////////////////////////////////////////////////////////
  64. string_view method::get_name() const RTTR_NOEXCEPT
  65. {
  66. return m_wrapper->get_name();
  67. }
  68. /////////////////////////////////////////////////////////////////////////////////////////
  69. access_levels method::get_access_level() const RTTR_NOEXCEPT
  70. {
  71. return m_wrapper->get_access_level();
  72. }
  73. /////////////////////////////////////////////////////////////////////////////////////////
  74. bool method::is_static() const RTTR_NOEXCEPT
  75. {
  76. return m_wrapper->is_static();
  77. }
  78. /////////////////////////////////////////////////////////////////////////////////////////
  79. type method::get_return_type() const RTTR_NOEXCEPT
  80. {
  81. return m_wrapper->get_return_type();
  82. }
  83. /////////////////////////////////////////////////////////////////////////////////////////
  84. type method::get_declaring_type() const RTTR_NOEXCEPT
  85. {
  86. return m_wrapper->get_declaring_type();
  87. }
  88. /////////////////////////////////////////////////////////////////////////////////////////
  89. array_range<parameter_info> method::get_parameter_infos() const RTTR_NOEXCEPT
  90. {
  91. return m_wrapper->get_parameter_infos();
  92. }
  93. /////////////////////////////////////////////////////////////////////////////////////////
  94. string_view method::get_signature() const RTTR_NOEXCEPT
  95. {
  96. return m_wrapper->get_signature();
  97. }
  98. /////////////////////////////////////////////////////////////////////////////////////////
  99. variant method::get_metadata(const variant& key) const
  100. {
  101. return m_wrapper->get_metadata(key);
  102. }
  103. /////////////////////////////////////////////////////////////////////////////////////////
  104. variant method::invoke(instance object) const
  105. {
  106. return m_wrapper->invoke(object);
  107. }
  108. /////////////////////////////////////////////////////////////////////////////////////////
  109. variant method::invoke(instance object, argument arg1) const
  110. {
  111. return m_wrapper->invoke(object, arg1);
  112. }
  113. /////////////////////////////////////////////////////////////////////////////////////////
  114. variant method::invoke(instance object, argument arg1, argument arg2) const
  115. {
  116. return m_wrapper->invoke(object, arg1, arg2);
  117. }
  118. /////////////////////////////////////////////////////////////////////////////////////////
  119. variant method::invoke(instance object, argument arg1, argument arg2, argument arg3) const
  120. {
  121. return m_wrapper->invoke(object, arg1, arg2, arg3);
  122. }
  123. /////////////////////////////////////////////////////////////////////////////////////////
  124. variant method::invoke(instance object, argument arg1, argument arg2, argument arg3, argument arg4) const
  125. {
  126. return m_wrapper->invoke(object, arg1, arg2, arg3, arg4);
  127. }
  128. /////////////////////////////////////////////////////////////////////////////////////////
  129. variant method::invoke(instance object, argument arg1, argument arg2, argument arg3, argument arg4,
  130. argument arg5) const
  131. {
  132. return m_wrapper->invoke(object, arg1, arg2, arg3, arg4, arg5);
  133. }
  134. /////////////////////////////////////////////////////////////////////////////////////////
  135. variant method::invoke(instance object, argument arg1, argument arg2, argument arg3, argument arg4,
  136. argument arg5, argument arg6) const
  137. {
  138. return m_wrapper->invoke(object, arg1, arg2, arg3, arg4, arg5, arg6);
  139. }
  140. /////////////////////////////////////////////////////////////////////////////////////////
  141. variant method::invoke_variadic(instance object, std::vector<argument> args) const
  142. {
  143. return m_wrapper->invoke_variadic(object, args);
  144. }
  145. /////////////////////////////////////////////////////////////////////////////////////////
  146. bool method::operator==(const method& other) const RTTR_NOEXCEPT
  147. {
  148. return (m_wrapper == other.m_wrapper);
  149. }
  150. /////////////////////////////////////////////////////////////////////////////////////////
  151. bool method::operator!=(const method& other) const RTTR_NOEXCEPT
  152. {
  153. return (m_wrapper != other.m_wrapper);
  154. }
  155. /////////////////////////////////////////////////////////////////////////////////////////
  156. void method::visit(visitor& visitor) const RTTR_NOEXCEPT
  157. {
  158. m_wrapper->visit(visitor, method(*this));
  159. }
  160. /////////////////////////////////////////////////////////////////////////////////////////
  161. } // end namespace rttr