property.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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/property.h"
  28. #include "rttr/detail/property/property_wrapper_base.h"
  29. #include "rttr/variant.h"
  30. #include "rttr/argument.h"
  31. #include "rttr/instance.h"
  32. #include "rttr/enumeration.h"
  33. using namespace std;
  34. namespace rttr
  35. {
  36. namespace detail
  37. {
  38. template<>
  39. property create_item(const property_wrapper_base* wrapper)
  40. {
  41. return property(wrapper);
  42. }
  43. template<>
  44. property create_invalid_item()
  45. {
  46. static const detail::property_wrapper_base invalid_wrapper(string_view(), detail::get_invalid_type());
  47. return property(&invalid_wrapper);
  48. }
  49. } // end namespace detail;
  50. /////////////////////////////////////////////////////////////////////////////////////////
  51. property::property(const detail::property_wrapper_base* wrapper) RTTR_NOEXCEPT
  52. : m_wrapper(wrapper)
  53. {
  54. }
  55. /////////////////////////////////////////////////////////////////////////////////////////
  56. bool property::is_valid() const RTTR_NOEXCEPT
  57. {
  58. return m_wrapper->is_valid();
  59. }
  60. /////////////////////////////////////////////////////////////////////////////////////////
  61. property::operator bool() const RTTR_NOEXCEPT
  62. {
  63. return m_wrapper->is_valid();
  64. }
  65. /////////////////////////////////////////////////////////////////////////////////////////
  66. access_levels property::get_access_level() const RTTR_NOEXCEPT
  67. {
  68. return m_wrapper->get_access_level();
  69. }
  70. /////////////////////////////////////////////////////////////////////////////////////////
  71. bool property::is_readonly() const RTTR_NOEXCEPT
  72. {
  73. return m_wrapper->is_readonly();
  74. }
  75. /////////////////////////////////////////////////////////////////////////////////////////
  76. bool property::is_static() const RTTR_NOEXCEPT
  77. {
  78. return m_wrapper->is_static();
  79. }
  80. /////////////////////////////////////////////////////////////////////////////////////////
  81. bool property::is_enumeration() const RTTR_NOEXCEPT
  82. {
  83. return m_wrapper->get_type().is_enumeration();
  84. }
  85. /////////////////////////////////////////////////////////////////////////////////////////
  86. enumeration property::get_enumeration() const RTTR_NOEXCEPT
  87. {
  88. return m_wrapper->get_type().get_enumeration();
  89. }
  90. /////////////////////////////////////////////////////////////////////////////////////////
  91. string_view property::get_name() const RTTR_NOEXCEPT
  92. {
  93. return m_wrapper->get_name();
  94. }
  95. /////////////////////////////////////////////////////////////////////////////////////////
  96. type property::get_type() const RTTR_NOEXCEPT
  97. {
  98. return m_wrapper->get_type();
  99. }
  100. /////////////////////////////////////////////////////////////////////////////////////////
  101. type property::get_declaring_type() const RTTR_NOEXCEPT
  102. {
  103. return m_wrapper->get_declaring_type();
  104. }
  105. /////////////////////////////////////////////////////////////////////////////////////////
  106. bool property::set_value(instance object, argument arg) const
  107. {
  108. return m_wrapper->set_value(object, arg);
  109. }
  110. /////////////////////////////////////////////////////////////////////////////////////////
  111. variant property::get_value(instance object) const
  112. {
  113. return m_wrapper->get_value(object);
  114. }
  115. /////////////////////////////////////////////////////////////////////////////////////////
  116. variant property::get_metadata(const variant& key) const
  117. {
  118. return m_wrapper->get_metadata(key);
  119. }
  120. /////////////////////////////////////////////////////////////////////////////////////////
  121. bool property::operator==(const property& other) const RTTR_NOEXCEPT
  122. {
  123. return (m_wrapper == other.m_wrapper);
  124. }
  125. /////////////////////////////////////////////////////////////////////////////////////////
  126. bool property::operator!=(const property& other) const RTTR_NOEXCEPT
  127. {
  128. return (m_wrapper != other.m_wrapper);
  129. }
  130. /////////////////////////////////////////////////////////////////////////////////////////
  131. void property::visit(visitor& visitor) const RTTR_NOEXCEPT
  132. {
  133. m_wrapper->visit(visitor, property(*this));
  134. }
  135. /////////////////////////////////////////////////////////////////////////////////////////
  136. } // end namespace rttr