callable_bind.h 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*************************************************************************/
  2. /* callable_bind.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef CALLABLE_BIND_H
  31. #define CALLABLE_BIND_H
  32. #include "core/variant/callable.h"
  33. #include "core/variant/variant.h"
  34. class CallableCustomBind : public CallableCustom {
  35. Callable callable;
  36. Vector<Variant> binds;
  37. static bool _equal_func(const CallableCustom *p_a, const CallableCustom *p_b);
  38. static bool _less_func(const CallableCustom *p_a, const CallableCustom *p_b);
  39. public:
  40. //for every type that inherits, these must always be the same for this type
  41. virtual uint32_t hash() const;
  42. virtual String get_as_text() const;
  43. virtual CompareEqualFunc get_compare_equal_func() const;
  44. virtual CompareLessFunc get_compare_less_func() const;
  45. virtual ObjectID get_object() const; //must always be able to provide an object
  46. virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const;
  47. virtual const Callable *get_base_comparator() const;
  48. CallableCustomBind(const Callable &p_callable, const Vector<Variant> &p_binds);
  49. virtual ~CallableCustomBind();
  50. };
  51. class CallableCustomUnbind : public CallableCustom {
  52. Callable callable;
  53. int argcount;
  54. static bool _equal_func(const CallableCustom *p_a, const CallableCustom *p_b);
  55. static bool _less_func(const CallableCustom *p_a, const CallableCustom *p_b);
  56. public:
  57. //for every type that inherits, these must always be the same for this type
  58. virtual uint32_t hash() const;
  59. virtual String get_as_text() const;
  60. virtual CompareEqualFunc get_compare_equal_func() const;
  61. virtual CompareLessFunc get_compare_less_func() const;
  62. virtual ObjectID get_object() const; //must always be able to provide an object
  63. virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const;
  64. virtual const Callable *get_base_comparator() const;
  65. CallableCustomUnbind(const Callable &p_callable, int p_argcount);
  66. virtual ~CallableCustomUnbind();
  67. };
  68. Callable callable_bind(const Callable &p_callable, const Variant &p_arg1);
  69. Callable callable_bind(const Callable &p_callable, const Variant &p_arg1, const Variant &p_arg2);
  70. Callable callable_bind(const Callable &p_callable, const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3);
  71. Callable callable_bind(const Callable &p_callable, const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3, const Variant &p_arg4);
  72. Callable callable_bind(const Callable &p_callable, const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3, const Variant &p_arg4, const Variant &p_arg5);
  73. #endif // CALLABLE_BIND_H