error_macros.cpp 5.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*************************************************************************/
  2. /* error_macros.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 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. #include <godot_cpp/core/error_macros.hpp>
  31. #include <godot_cpp/godot.hpp>
  32. #include <string>
  33. namespace godot {
  34. void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, const char *p_message, bool p_is_warning) {
  35. if (p_is_warning) {
  36. internal::gde_interface->print_warning(p_message, p_function, p_file, p_line);
  37. } else {
  38. internal::gde_interface->print_error(p_message, p_function, p_file, p_line);
  39. }
  40. }
  41. void _err_print_error(const char *p_function, const char *p_file, int p_line, const String &p_error, const char *p_message, bool p_is_warning) {
  42. if (p_is_warning) {
  43. internal::gde_interface->print_warning(p_message, p_function, p_file, p_line);
  44. } else {
  45. internal::gde_interface->print_error(p_message, p_function, p_file, p_line);
  46. }
  47. }
  48. void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, const String &p_message, bool p_is_warning) {
  49. if (p_is_warning) {
  50. internal::gde_interface->print_warning(p_message.utf8().get_data(), p_function, p_file, p_line);
  51. } else {
  52. internal::gde_interface->print_error(p_message.utf8().get_data(), p_function, p_file, p_line);
  53. }
  54. }
  55. void _err_print_error(const char *p_function, const char *p_file, int p_line, const String &p_error, const String &p_message, bool p_is_warning) {
  56. if (p_is_warning) {
  57. internal::gde_interface->print_warning(p_message.utf8().get_data(), p_function, p_file, p_line);
  58. } else {
  59. internal::gde_interface->print_error(p_message.utf8().get_data(), p_function, p_file, p_line);
  60. }
  61. }
  62. void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, bool p_is_warning) {
  63. _err_print_error(p_function, p_file, p_line, "", p_error, p_is_warning);
  64. }
  65. void _err_print_error(const char *p_function, const char *p_file, int p_line, const String &p_error, bool p_is_warning) {
  66. _err_print_error(p_function, p_file, p_line, "", p_error, p_is_warning);
  67. }
  68. void _err_print_index_error(const char *p_function, const char *p_file, int p_line, int64_t p_index, int64_t p_size, const char *p_index_str, const char *p_size_str, const char *p_message, bool fatal) {
  69. std::string fstr(fatal ? "FATAL: " : "");
  70. std::string err(fstr + "Index " + p_index_str + " = " + std::to_string(p_index) + " is out of bounds (" + p_size_str + " = " + std::to_string(p_size) + ").");
  71. _err_print_error(p_function, p_file, p_line, err.c_str(), p_message);
  72. }
  73. void _err_print_index_error(const char *p_function, const char *p_file, int p_line, int64_t p_index, int64_t p_size, const char *p_index_str, const char *p_size_str, const String &p_message, bool fatal) {
  74. std::string fstr(fatal ? "FATAL: " : "");
  75. std::string err(fstr + "Index " + p_index_str + " = " + std::to_string(p_index) + " is out of bounds (" + p_size_str + " = " + std::to_string(p_size) + ").");
  76. _err_print_error(p_function, p_file, p_line, err.c_str(), p_message);
  77. }
  78. } // namespace godot