Boolean.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-09
  6. * Changed: 2024-05-31
  7. *
  8. * */
  9. #ifndef LS_STD_BOOLEAN_HPP
  10. #define LS_STD_BOOLEAN_HPP
  11. #include <ls-std/core/Class.hpp>
  12. #include <ls-std/core/definition.hpp>
  13. #include <ls-std/core/interface/IBoxing.hpp>
  14. #include <sstream>
  15. namespace ls::std::boxing
  16. {
  17. ls_std_class Boolean final : public core::Class, public core::interface_type::IBoxing
  18. {
  19. public:
  20. explicit Boolean(bool _value);
  21. Boolean();
  22. ~Boolean() noexcept override;
  23. // assignment operators
  24. Boolean &operator=(int _value);
  25. Boolean &operator=(bool _value);
  26. // stream operators
  27. friend ::std::ostream &operator<<(::std::ostream &_outputStream, const Boolean &_boolean)
  28. {
  29. _outputStream << _boolean._toString();
  30. return _outputStream;
  31. }
  32. // logical operators
  33. friend bool operator!(const Boolean &_boolean)
  34. {
  35. return !_boolean.value;
  36. }
  37. bool operator&&(const Boolean &_boolean) const;
  38. bool operator&&(bool _value) const;
  39. bool operator&&(int _value) const;
  40. bool operator||(const Boolean &_boolean) const;
  41. bool operator||(bool _value) const;
  42. bool operator||(int _value) const;
  43. // INFO: operator ^ can not be taken for XOR, since it's not possible to implement it respecting commutative law
  44. // implementation
  45. void parse(const ::std::string &_parseText) override;
  46. [[nodiscard]] ::std::string toString() override;
  47. // additional functionality
  48. [[nodiscard]] bool getValue() const;
  49. [[nodiscard]] static bool XOR(const Boolean &_leftExpression, const Boolean &_rightExpression);
  50. [[nodiscard]] static bool XOR(const Boolean &_leftExpression, bool _rightExpression);
  51. [[nodiscard]] static bool XOR(bool _leftExpression, const Boolean &_rightExpression);
  52. [[nodiscard]] static bool XOR(bool _leftExpression, bool _rightExpression);
  53. private:
  54. bool value{};
  55. const ::std::string FALSE_STRING = "false";
  56. const ::std::string TRUE_STRING = "true";
  57. [[nodiscard]] static ::std::string _fetchClassName();
  58. [[nodiscard]] ::std::string _toString() const;
  59. };
  60. }
  61. #endif