method_wrapper_base.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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_METHOD_WRAPPER_BASE_H_
  28. #define RTTR_METHOD_WRAPPER_BASE_H_
  29. #include "rttr/detail/base/core_prerequisites.h"
  30. #include "rttr/detail/metadata/metadata_handler.h"
  31. #include "rttr/type.h"
  32. #include "rttr/variant.h"
  33. #include "rttr/array_range.h"
  34. #include "rttr/parameter_info.h"
  35. #include "rttr/access_levels.h"
  36. #include "rttr/string_view.h"
  37. #include <string>
  38. #include <vector>
  39. namespace rttr
  40. {
  41. class type;
  42. class argument;
  43. class instance;
  44. class method;
  45. class visitor;
  46. namespace detail
  47. {
  48. /*!
  49. * Abstract class for a method.
  50. *
  51. * This is the base class for all methods.
  52. * You can invoke the method via method_wrapper_base::invoke.
  53. */
  54. class RTTR_API method_wrapper_base
  55. {
  56. public:
  57. method_wrapper_base(string_view name, type declaring_type) RTTR_NOEXCEPT;
  58. virtual ~method_wrapper_base();
  59. string_view get_name() const RTTR_NOEXCEPT;
  60. type get_declaring_type() const RTTR_NOEXCEPT;
  61. virtual bool is_valid() const RTTR_NOEXCEPT;
  62. virtual string_view get_signature() const RTTR_NOEXCEPT;
  63. virtual access_levels get_access_level() const RTTR_NOEXCEPT;
  64. virtual type get_return_type() const RTTR_NOEXCEPT;
  65. virtual bool is_static() const RTTR_NOEXCEPT;
  66. virtual std::vector<bool> get_is_reference() const RTTR_NOEXCEPT;
  67. virtual std::vector<bool> get_is_const() const RTTR_NOEXCEPT;
  68. virtual array_range<parameter_info> get_parameter_infos() const RTTR_NOEXCEPT;
  69. virtual variant get_metadata(const variant& key) const;
  70. virtual variant invoke(instance& object) const;
  71. virtual variant invoke(instance& object, argument& arg1) const;
  72. virtual variant invoke(instance& object, argument& arg1, argument& arg2) const;
  73. virtual variant invoke(instance& object, argument& arg1, argument& arg2, argument& arg3) const;
  74. virtual variant invoke(instance& object, argument& arg1, argument& arg2, argument& arg3,
  75. argument& arg4) const;
  76. virtual variant invoke(instance& object, argument& arg1, argument& arg2, argument& arg3,
  77. argument& arg4, argument& arg5) const;
  78. virtual variant invoke(instance& object, argument& arg1, argument& arg2, argument& arg3,
  79. argument& arg4, argument& arg5, argument& arg6) const;
  80. virtual variant invoke_variadic(const instance& object, std::vector<argument>& args) const;
  81. virtual void visit(visitor& visitor, method m) const RTTR_NOEXCEPT;
  82. protected:
  83. void init() RTTR_NOEXCEPT;
  84. private:
  85. void create_signature_string() RTTR_NOEXCEPT;
  86. private:
  87. string_view m_name;
  88. string_view m_signature_view;
  89. type m_declaring_type;
  90. std::string m_signature;
  91. };
  92. } // end namespace detail
  93. } // end namespace rttr
  94. #endif // RTTR_METHOD_WRAPPER_BASE_H_