enumeration.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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/enumeration.h"
  28. #include "rttr/detail/enumeration/enumeration_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. enumeration create_item(const enumeration_wrapper_base* wrapper)
  38. {
  39. return enumeration(wrapper);
  40. }
  41. template<>
  42. enumeration create_invalid_item()
  43. {
  44. static const enumeration_wrapper_base invalid_wrapper;
  45. return enumeration(&invalid_wrapper);
  46. }
  47. } // end namespace detail
  48. /////////////////////////////////////////////////////////////////////////////////////////
  49. enumeration::enumeration(const detail::enumeration_wrapper_base* wrapper) RTTR_NOEXCEPT
  50. : m_wrapper(wrapper)
  51. {
  52. }
  53. /////////////////////////////////////////////////////////////////////////////////////////
  54. bool enumeration::is_valid() const RTTR_NOEXCEPT
  55. {
  56. return m_wrapper->is_valid();
  57. }
  58. /////////////////////////////////////////////////////////////////////////////////////////
  59. enumeration::operator bool() const RTTR_NOEXCEPT
  60. {
  61. return m_wrapper->is_valid();
  62. }
  63. /////////////////////////////////////////////////////////////////////////////////////////
  64. string_view enumeration::get_name() const RTTR_NOEXCEPT
  65. {
  66. return m_wrapper->get_type().get_name();
  67. }
  68. /////////////////////////////////////////////////////////////////////////////////////////
  69. type enumeration::get_underlying_type() const RTTR_NOEXCEPT
  70. {
  71. return m_wrapper->get_underlying_type();
  72. }
  73. /////////////////////////////////////////////////////////////////////////////////////////
  74. type enumeration::get_type() const RTTR_NOEXCEPT
  75. {
  76. return m_wrapper->get_type();
  77. }
  78. /////////////////////////////////////////////////////////////////////////////////////////
  79. type enumeration::get_declaring_type() const RTTR_NOEXCEPT
  80. {
  81. return m_wrapper->get_declaring_type();
  82. }
  83. /////////////////////////////////////////////////////////////////////////////////////////
  84. variant enumeration::get_metadata(const variant& key) const
  85. {
  86. return m_wrapper->get_metadata(key);
  87. }
  88. /////////////////////////////////////////////////////////////////////////////////////////
  89. array_range<string_view> enumeration::get_names() const RTTR_NOEXCEPT
  90. {
  91. return m_wrapper->get_names();
  92. }
  93. /////////////////////////////////////////////////////////////////////////////////////////
  94. array_range<variant> enumeration::get_values() const RTTR_NOEXCEPT
  95. {
  96. return m_wrapper->get_values();
  97. }
  98. /////////////////////////////////////////////////////////////////////////////////////////
  99. string_view enumeration::value_to_name(argument value) const
  100. {
  101. return m_wrapper->value_to_name(value);
  102. }
  103. /////////////////////////////////////////////////////////////////////////////////////////
  104. variant enumeration::name_to_value(string_view name) const
  105. {
  106. return m_wrapper->name_to_value(name);
  107. }
  108. /////////////////////////////////////////////////////////////////////////////////////////
  109. bool enumeration::operator==(const enumeration& other) const RTTR_NOEXCEPT
  110. {
  111. return (m_wrapper == other.m_wrapper);
  112. }
  113. /////////////////////////////////////////////////////////////////////////////////////////
  114. bool enumeration::operator!=(const enumeration& other) const RTTR_NOEXCEPT
  115. {
  116. return (m_wrapper != other.m_wrapper);
  117. }
  118. /////////////////////////////////////////////////////////////////////////////////////////
  119. } // end namespace rttr