constructor.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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/constructor.h"
  28. #include "rttr/detail/constructor/constructor_wrapper_base.h"
  29. #include "rttr/argument.h"
  30. #include <utility>
  31. using namespace std;
  32. namespace rttr
  33. {
  34. namespace detail
  35. {
  36. template<>
  37. constructor create_item(const constructor_wrapper_base* wrapper)
  38. {
  39. return constructor(wrapper);
  40. }
  41. template<>
  42. constructor create_invalid_item()
  43. {
  44. static const constructor_wrapper_base invalid_wrapper;
  45. return constructor(&invalid_wrapper);
  46. }
  47. } // end namespace detail
  48. /////////////////////////////////////////////////////////////////////////////////////////
  49. constructor::constructor(const detail::constructor_wrapper_base* wrapper) RTTR_NOEXCEPT
  50. : m_wrapper(wrapper)
  51. {
  52. }
  53. /////////////////////////////////////////////////////////////////////////////////////////
  54. bool constructor::is_valid() const RTTR_NOEXCEPT
  55. {
  56. return m_wrapper->is_valid();
  57. }
  58. /////////////////////////////////////////////////////////////////////////////////////////
  59. constructor::operator bool() const RTTR_NOEXCEPT
  60. {
  61. return m_wrapper->is_valid();
  62. }
  63. /////////////////////////////////////////////////////////////////////////////////////////
  64. access_levels constructor::get_access_level() const RTTR_NOEXCEPT
  65. {
  66. return m_wrapper->get_access_level();
  67. }
  68. /////////////////////////////////////////////////////////////////////////////////////////
  69. type constructor::get_instantiated_type() const RTTR_NOEXCEPT
  70. {
  71. return m_wrapper->get_instantiated_type();
  72. }
  73. /////////////////////////////////////////////////////////////////////////////////////////
  74. type constructor::get_declaring_type() const RTTR_NOEXCEPT
  75. {
  76. return m_wrapper->get_declaring_type();
  77. }
  78. /////////////////////////////////////////////////////////////////////////////////////////
  79. string_view constructor::get_signature() const RTTR_NOEXCEPT
  80. {
  81. return m_wrapper->get_signature();
  82. }
  83. /////////////////////////////////////////////////////////////////////////////////////////
  84. array_range<parameter_info> constructor::get_parameter_infos() const RTTR_NOEXCEPT
  85. {
  86. return m_wrapper->get_parameter_infos();
  87. }
  88. /////////////////////////////////////////////////////////////////////////////////////////
  89. variant constructor::get_metadata(const variant& key) const
  90. {
  91. return m_wrapper->get_metadata(key);
  92. }
  93. /////////////////////////////////////////////////////////////////////////////////////////
  94. variant constructor::invoke() const
  95. {
  96. return m_wrapper->invoke();
  97. }
  98. /////////////////////////////////////////////////////////////////////////////////////////
  99. variant constructor::invoke(argument arg1) const
  100. {
  101. return m_wrapper->invoke(arg1);
  102. }
  103. /////////////////////////////////////////////////////////////////////////////////////////
  104. variant constructor::invoke(argument arg1, argument arg2) const
  105. {
  106. return m_wrapper->invoke(arg1, arg2);
  107. }
  108. /////////////////////////////////////////////////////////////////////////////////////////
  109. variant constructor::invoke(argument arg1, argument arg2, argument arg3) const
  110. {
  111. return m_wrapper->invoke(arg1, arg2, arg3);
  112. }
  113. /////////////////////////////////////////////////////////////////////////////////////////
  114. variant constructor::invoke(argument arg1, argument arg2, argument arg3, argument arg4) const
  115. {
  116. return m_wrapper->invoke(arg1, arg2, arg3, arg4);
  117. }
  118. /////////////////////////////////////////////////////////////////////////////////////////
  119. variant constructor::invoke(argument arg1, argument arg2, argument arg3, argument arg4,
  120. argument arg5) const
  121. {
  122. return m_wrapper->invoke(arg1, arg2, arg3, arg4, arg5);
  123. }
  124. /////////////////////////////////////////////////////////////////////////////////////////
  125. variant constructor::invoke(argument arg1, argument arg2, argument arg3, argument arg4,
  126. argument arg5, argument arg6) const
  127. {
  128. return m_wrapper->invoke(arg1, arg2, arg3, arg4, arg5, arg6);
  129. }
  130. /////////////////////////////////////////////////////////////////////////////////////////
  131. variant constructor::invoke_variadic(std::vector<argument> args) const
  132. {
  133. return m_wrapper->invoke_variadic(args);
  134. }
  135. /////////////////////////////////////////////////////////////////////////////////////////
  136. bool constructor::operator==(const constructor& other) const RTTR_NOEXCEPT
  137. {
  138. return (m_wrapper == other.m_wrapper);
  139. }
  140. /////////////////////////////////////////////////////////////////////////////////////////
  141. bool constructor::operator!=(const constructor& other) const RTTR_NOEXCEPT
  142. {
  143. return (m_wrapper != other.m_wrapper);
  144. }
  145. /////////////////////////////////////////////////////////////////////////////////////////
  146. void constructor::visit(visitor& visitor) const RTTR_NOEXCEPT
  147. {
  148. m_wrapper->visit(visitor, constructor(*this));
  149. }
  150. /////////////////////////////////////////////////////////////////////////////////////////
  151. } // end namespace rttr