Utility.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. int Echo::_loglevel = 4;
  20. bool Echo::printType(int order)
  21. {
  22. switch(order)
  23. {
  24. case Error:
  25. if(_loglevel >= 1)
  26. {
  27. std::cerr << "Error: ";
  28. return true;
  29. }
  30. return false;
  31. case Info:
  32. if(_loglevel >= 2)
  33. {
  34. std::cout << "PSA: ";
  35. return true;
  36. }
  37. return false;
  38. case Load:
  39. if(_loglevel >= 3)
  40. {
  41. std::cout << "Loaded ";
  42. return true;
  43. }
  44. return false;
  45. case Debug:
  46. if(_loglevel >= 4)
  47. {
  48. std::cout << "Debug: ";
  49. return true;
  50. }
  51. return false;
  52. case Empty: default:
  53. if(_loglevel >= 1)
  54. return true;
  55. return false;
  56. }
  57. }
  58. void Echo::helper(bool err, std::wstring out)
  59. {
  60. if(err)
  61. std::wcerr << out;
  62. else
  63. std::wcout << out;
  64. }
  65. void Echo::out(std::string debug)
  66. {
  67. if(!printType(Debug))
  68. std::printf("%s", &debug[0]);
  69. }
  70. void Echo::out(float debug)
  71. {
  72. if(printType(Debug))
  73. std::printf("%f\n", debug);
  74. }