Boolean.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-09
  6. * Changed: 2020-08-13
  7. *
  8. * */
  9. #ifndef BOOLEAN_HPP
  10. #define BOOLEAN_HPP
  11. #include "../base/Class.hpp"
  12. #include "IBoxing.hpp"
  13. namespace ls_std {
  14. class Boolean : public Class, IBoxing {
  15. public:
  16. explicit Boolean(bool _value);
  17. Boolean();
  18. ~Boolean() = default;
  19. // conversion operator
  20. operator bool() const;
  21. // assignment operators
  22. Boolean& operator=(int _value);
  23. Boolean& operator=(bool _value);
  24. // stream operators
  25. friend std::ostream& operator<<(std::ostream& outputStream, const Boolean& _boolean) {
  26. outputStream << _boolean._toString();
  27. return outputStream;
  28. }
  29. // logical operators
  30. friend bool operator!(const Boolean& _boolean) {
  31. return !_boolean.value;
  32. }
  33. bool operator&&(const Boolean& _boolean) const;
  34. bool operator&&(bool _value) const;
  35. bool operator&&(int _value) const;
  36. bool operator||(const Boolean& _boolean) const;
  37. bool operator||(bool _value) const;
  38. bool operator||(int _value) const;
  39. // implementation
  40. void parse(std::string parseText) override;
  41. std::string toString() override;
  42. // additional functionality
  43. static bool XOR(const Boolean& _leftExpression, const Boolean& _rightExpression);
  44. static bool XOR(const Boolean& _leftExpression, bool _rightExpression);
  45. static bool XOR(bool _leftExpression, const Boolean& _rightExpression);
  46. static bool XOR(bool _leftExpression, bool _rightExpression);
  47. private:
  48. bool value {};
  49. const std::string TRUE_STRING = "true";
  50. const std::string FALSE_STRING = "false";
  51. std::string _toString() const;
  52. };
  53. }
  54. #endif