harl.class.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* harl.class.cpp :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: bchanot <bchanot@gmail.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2025/07/15 19:49:59 by bchanot #+# #+# */
  9. /* Updated: 2025/07/16 13:18:36 by bchanot ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include "harl.class.hpp"
  13. void Harl::debug(void) {
  14. std::cout << "[DEBUG] I love having extra bacon for my 7XL-double-cheese-triple-pickle-special-ketchup burger. I really do!" << std::endl;
  15. }
  16. void Harl::info(void) {
  17. std::cout << "[INFO] I cannot believe adding extra bacon costs more money. You didn’t put enough bacon in my burger! If you did, I wouldn’t be asking for more!" << std::endl;
  18. }
  19. void Harl::warning(void) {
  20. std::cout << "[WARNING] I think I deserve to have some extra bacon for free. I’ve been coming for years, whereas you started working here just last month." << std::endl;
  21. }
  22. void Harl::error(void) {
  23. std::cout << "[ERROR] This is unacceptable! I want to speak to the manager now." << std::endl;
  24. }
  25. std::array<std::string, 4> Harl::getLevels(void) {
  26. return {"DEBUG", "INFO", "WARNING", "ERROR"};
  27. }
  28. void Harl::complain(std::string level) {
  29. void (Harl::*fn[])(void) = {&Harl::debug, &Harl::info, &Harl::warning, &Harl::error};
  30. std::array<std::string, 4> complain = Harl::getLevels();
  31. int i;
  32. bool print = false;
  33. i = 0;
  34. while (i < 4) {
  35. if (complain[i].compare(level) == 0 || print) {
  36. print = true;
  37. (this->*fn[i])();
  38. }
  39. i++;
  40. }
  41. }