parameter_info_wrapper.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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_PARAMETER_INFO_WRAPPER_H_
  28. #define RTTR_PARAMETER_INFO_WRAPPER_H_
  29. #include "rttr/detail/base/core_prerequisites.h"
  30. #include "rttr/detail/parameter_info/parameter_info_wrapper_base.h"
  31. #include "rttr/parameter_info.h"
  32. namespace rttr
  33. {
  34. namespace detail
  35. {
  36. struct has_param_name {};
  37. struct no_param_name {};
  38. template<typename Param_Type, std::size_t Param_Index, typename Has_Name, typename Default_Type>
  39. class parameter_info_wrapper;
  40. /////////////////////////////////////////////////////////////////////////////////////////
  41. template<typename Param_Type, std::size_t Param_Index, typename Default_Type>
  42. class parameter_info_wrapper<Param_Type, Param_Index, has_param_name, Default_Type>: public parameter_info_wrapper_base
  43. {
  44. public:
  45. parameter_info_wrapper(string_view name) RTTR_NOEXCEPT
  46. : m_default_value(nullptr), m_name(name)
  47. {
  48. }
  49. string_view get_name() const RTTR_NOEXCEPT { return m_name; }
  50. type get_type() const RTTR_NOEXCEPT { return type::get<Param_Type>(); }
  51. bool has_default_value() const RTTR_NOEXCEPT { return true; }
  52. variant get_default_value() const { return variant(*m_default_value); }
  53. void set_default_value(const Default_Type* default_value) RTTR_NOEXCEPT { m_default_value = default_value; }
  54. uint32_t get_index() const RTTR_NOEXCEPT { return static_cast<uint32_t>(Param_Index); }
  55. private:
  56. const Default_Type* m_default_value;
  57. string_view m_name;
  58. };
  59. /////////////////////////////////////////////////////////////////////////////////////////
  60. template<typename Param_Type, std::size_t Param_Index, typename Default_Type>
  61. class parameter_info_wrapper<Param_Type, Param_Index, no_param_name, Default_Type>: public parameter_info_wrapper_base
  62. {
  63. public:
  64. parameter_info_wrapper() RTTR_NOEXCEPT
  65. : m_default_value(nullptr)
  66. {
  67. }
  68. string_view get_name() const RTTR_NOEXCEPT { return string_view(); }
  69. type get_type() const RTTR_NOEXCEPT { return type::get<Param_Type>(); }
  70. bool has_default_value() const RTTR_NOEXCEPT { return true; }
  71. variant get_default_value() const { return variant(*m_default_value); }
  72. void set_default_value(const Default_Type* default_value) RTTR_NOEXCEPT { m_default_value = default_value; }
  73. uint32_t get_index() const RTTR_NOEXCEPT { return static_cast<uint32_t>(Param_Index); }
  74. private:
  75. const Default_Type* m_default_value;
  76. };
  77. /////////////////////////////////////////////////////////////////////////////////////////
  78. /////////////////////////////////////////////////////////////////////////////////////////
  79. /////////////////////////////////////////////////////////////////////////////////////////
  80. // Specialization which has NO default value
  81. template<typename Param_Type, std::size_t Param_Index>
  82. class parameter_info_wrapper<Param_Type, Param_Index, has_param_name, void> : public parameter_info_wrapper_base
  83. {
  84. public:
  85. parameter_info_wrapper(string_view name) RTTR_NOEXCEPT
  86. : m_name(name)
  87. {
  88. }
  89. string_view get_name() const RTTR_NOEXCEPT { return m_name; }
  90. type get_type() const RTTR_NOEXCEPT { return type::get<Param_Type>(); }
  91. bool has_default_value() const RTTR_NOEXCEPT { return false; }
  92. variant get_default_value() const { return variant(); }
  93. uint32_t get_index() const RTTR_NOEXCEPT { return static_cast<uint32_t>(Param_Index); }
  94. private:
  95. string_view m_name;
  96. };
  97. /////////////////////////////////////////////////////////////////////////////////////////
  98. // Specialization which has NO default value
  99. template<typename Param_Type, std::size_t Param_Index>
  100. class parameter_info_wrapper<Param_Type, Param_Index, no_param_name, void> : public parameter_info_wrapper_base
  101. {
  102. public:
  103. parameter_info_wrapper() RTTR_NOEXCEPT {}
  104. string_view get_name() const RTTR_NOEXCEPT { return string_view(); }
  105. type get_type() const RTTR_NOEXCEPT { return type::get<Param_Type>(); }
  106. bool has_default_value() const RTTR_NOEXCEPT { return false; }
  107. variant get_default_value() const { return variant(); }
  108. uint32_t get_index() const RTTR_NOEXCEPT { return static_cast<uint32_t>(Param_Index); }
  109. };
  110. /////////////////////////////////////////////////////////////////////////////////////////
  111. } // end namespace detail
  112. } // end namespace rttr
  113. #endif // RTTR_PARAMETER_INFO_WRAPPER_H_