method_bind.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*************************************************************************/
  2. /* method_bind.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #include "object.h"
  30. #include "method_bind.h"
  31. #ifdef DEBUG_METHODS_ENABLED
  32. PropertyInfo MethodBind::get_argument_info(int p_argument) const {
  33. if (p_argument>=0) {
  34. String name = (p_argument<arg_names.size())?String(arg_names[p_argument]):String("arg"+itos(p_argument));
  35. PropertyInfo pi( get_argument_type(p_argument), name );
  36. if ((pi.type==Variant::OBJECT) && name.find(":")!=-1) {
  37. pi.hint=PROPERTY_HINT_RESOURCE_TYPE;
  38. pi.hint_string=name.get_slice(":",1);
  39. pi.name=name.get_slice(":",0);
  40. }
  41. return pi;
  42. } else {
  43. Variant::Type at = get_argument_type(-1);
  44. if (at==Variant::OBJECT && ret_type)
  45. return PropertyInfo( at, "ret", PROPERTY_HINT_RESOURCE_TYPE, ret_type );
  46. else
  47. return PropertyInfo( at, "ret" );
  48. }
  49. return PropertyInfo();
  50. }
  51. #endif
  52. void MethodBind::_set_const(bool p_const) {
  53. _const=p_const;
  54. }
  55. StringName MethodBind::get_name() const {
  56. return name;
  57. }
  58. void MethodBind::set_name(const StringName& p_name) {
  59. name=p_name;
  60. }
  61. #ifdef DEBUG_METHODS_ENABLED
  62. void MethodBind::set_argument_names(const Vector<StringName>& p_names) {
  63. arg_names=p_names;
  64. }
  65. Vector<StringName> MethodBind::get_argument_names() const {
  66. return arg_names;
  67. }
  68. #endif
  69. void MethodBind::set_default_arguments(const Vector<Variant>& p_defargs) {
  70. default_arguments=p_defargs;
  71. default_argument_count=default_arguments.size();
  72. }
  73. #ifdef DEBUG_METHODS_ENABLED
  74. void MethodBind::_generate_argument_types(int p_count) {
  75. set_argument_count(p_count);
  76. Variant::Type *argt = memnew_arr(Variant::Type,p_count+1);
  77. argt[0]=_gen_argument_type(-1);
  78. for(int i=0;i<p_count;i++) {
  79. argt[i+1]=_gen_argument_type(i);
  80. }
  81. set_argument_types(argt);
  82. }
  83. #endif
  84. MethodBind::MethodBind() {
  85. static int last_id=0;
  86. method_id=last_id++;
  87. hint_flags=METHOD_FLAGS_DEFAULT;
  88. argument_count=0;
  89. default_argument_count=0;
  90. #ifdef DEBUG_METHODS_ENABLED
  91. argument_types=NULL;
  92. #endif
  93. _const=false;
  94. }
  95. MethodBind::~MethodBind() {
  96. #ifdef DEBUG_METHODS_ENABLED
  97. if (argument_types)
  98. memdelete_arr(argument_types);
  99. #endif
  100. }