argument.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. #ifndef RTTR_ARGUMENT_H_
  28. #define RTTR_ARGUMENT_H_
  29. #include "rttr/detail/base/core_prerequisites.h"
  30. #include "rttr/detail/misc/misc_type_traits.h"
  31. #include "rttr/detail/misc/std_type_traits.h"
  32. #include <type_traits>
  33. #include <utility>
  34. namespace rttr
  35. {
  36. class type;
  37. class variant;
  38. class variant_array;
  39. class instance;
  40. /*!
  41. * The \ref argument class is used for forwarding arguments to \ref property "properties" or \ref method "methods".
  42. *
  43. * \remark This class should never be explicitly instantiated.
  44. */
  45. class RTTR_API argument
  46. {
  47. template<typename T>
  48. using decay_arg_t = detail::enable_if_t<!std::is_same<argument, T>::value, T>;
  49. template<typename T>
  50. using is_variant = std::is_same<detail::remove_cv_t<detail::remove_reference_t<T>>, variant>;
  51. template<typename T>
  52. using arg_value_t = detail::enable_if_t<!std::is_rvalue_reference<T>::value && !is_variant<T>::value, T>;
  53. template<typename T>
  54. using arg_rvalue_t = detail::enable_if_t<std::is_rvalue_reference<T>::value && !is_variant<T>::value, detail::remove_reference_t<T> >;
  55. template<typename T>
  56. using ptr_type = detail::enable_if_t<std::is_pointer<T>::value, bool>;
  57. template<typename T>
  58. using non_ptr_type = detail::enable_if_t<!std::is_pointer<T>::value, bool>;
  59. template<typename T>
  60. using is_variant_t = detail::enable_if_t<is_variant<T>::value && !std::is_rvalue_reference<T>::value, T>;
  61. template<typename T>
  62. using is_variant_ref_t = detail::enable_if_t<is_variant<T>::value && std::is_rvalue_reference<T>::value, detail::remove_reference_t<T>>;
  63. public:
  64. RTTR_INLINE argument() RTTR_NOEXCEPT;
  65. RTTR_INLINE argument(argument&& arg) RTTR_NOEXCEPT;
  66. RTTR_INLINE argument(const argument& other) RTTR_NOEXCEPT;
  67. RTTR_INLINE argument(variant& var) RTTR_NOEXCEPT;
  68. RTTR_INLINE argument(const variant& var) RTTR_NOEXCEPT;
  69. template<typename T, typename Tp = decay_arg_t<T>>
  70. RTTR_INLINE argument(const T& data) RTTR_NOEXCEPT;
  71. template<typename T, typename Tp = decay_arg_t<T>>
  72. RTTR_INLINE argument(T& data) RTTR_NOEXCEPT;
  73. RTTR_INLINE argument& operator=(const argument& other) RTTR_NOEXCEPT;
  74. RTTR_INLINE type get_type() const RTTR_NOEXCEPT;
  75. #ifdef DOXYGEN
  76. template<typename T>
  77. RTTR_INLINE bool is_type() const RTTR_NOEXCEPT;
  78. template<typename T>
  79. RTTR_INLINE T& get_value() const RTTR_NOEXCEPT;
  80. #else
  81. template<typename T>
  82. RTTR_INLINE ptr_type<T> is_type() const RTTR_NOEXCEPT;
  83. template<typename T>
  84. RTTR_INLINE non_ptr_type<T> is_type() const RTTR_NOEXCEPT;
  85. template<typename T>
  86. RTTR_INLINE arg_value_t<T>& get_value() const RTTR_NOEXCEPT;
  87. template<typename T>
  88. RTTR_INLINE arg_rvalue_t<T> && get_value() const RTTR_NOEXCEPT;
  89. template<typename T>
  90. RTTR_INLINE is_variant_t<T>& get_value() const RTTR_NOEXCEPT;
  91. template<typename T>
  92. RTTR_INLINE is_variant_ref_t<T> && get_value() const RTTR_NOEXCEPT;
  93. #endif
  94. private:
  95. const void* m_data;
  96. const variant* m_variant;
  97. const rttr::type m_type;
  98. };
  99. } // end namespace rttr
  100. #include "rttr/detail/impl/argument_impl.h"
  101. #endif // RTTR_ARGUMENT_H_