Utility.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * Triangles
  3. * Copyright (C) 2016 POSITIVE MENTAL ATTITUDE
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, version 3 of the License.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <cstdio>
  18. #include "Utility.hpp"
  19. #ifdef TRIANGLES_DEBUG
  20. int Echo::_loglevel = 4;
  21. #else
  22. int Echo::_loglevel = 1;
  23. #endif
  24. bool Echo::printType(int order)
  25. {
  26. switch(order)
  27. {
  28. case Error:
  29. if(_loglevel >= 1)
  30. {
  31. std::cerr << "Error: ";
  32. return true;
  33. }
  34. return false;
  35. case Info:
  36. if(_loglevel >= 2)
  37. {
  38. std::cout << "PSA: ";
  39. return true;
  40. }
  41. return false;
  42. case Load:
  43. if(_loglevel >= 3)
  44. {
  45. std::cout << "Loaded ";
  46. return true;
  47. }
  48. return false;
  49. case Debug:
  50. if(_loglevel >= 4)
  51. {
  52. std::cout << "Debug: ";
  53. return true;
  54. }
  55. return false;
  56. case Empty: default:
  57. if(_loglevel >= 1)
  58. return true;
  59. return false;
  60. }
  61. }
  62. void Echo::helper(bool err, std::wstring out)
  63. {
  64. if(err)
  65. std::wcerr << out;
  66. else
  67. std::wcout << out;
  68. }
  69. void Echo::out(std::string debug)
  70. {
  71. if(!printType(Debug))
  72. std::printf("%s", &debug[0]);
  73. }
  74. void Echo::out(float debug)
  75. {
  76. if(printType(Debug))
  77. std::printf("%f\n", debug);
  78. }