Boolean.hpp 2.4 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: 2023-02-22
  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/interface/IBoxing.hpp>
  13. #include <ls-std/os/dynamic-goal.hpp>
  14. #include <memory>
  15. #include <sstream>
  16. namespace ls::std::boxing
  17. {
  18. class LS_STD_DYNAMIC_GOAL Boolean : public ls::std::core::Class, public ls::std::core::interface_type::IBoxing
  19. {
  20. public:
  21. explicit Boolean(bool _value);
  22. Boolean();
  23. ~Boolean() noexcept override;
  24. // assignment operators
  25. ls::std::boxing::Boolean &operator=(int _value);
  26. ls::std::boxing::Boolean &operator=(bool _value);
  27. // stream operators
  28. friend ::std::ostream &operator<<(::std::ostream &_outputStream, const ls::std::boxing::Boolean &_boolean)
  29. {
  30. _outputStream << _boolean._toString();
  31. return _outputStream;
  32. }
  33. // logical operators
  34. friend bool operator!(const ls::std::boxing::Boolean &_boolean)
  35. {
  36. return !_boolean.value;
  37. }
  38. bool operator&&(const ls::std::boxing::Boolean &_boolean) const;
  39. bool operator&&(bool _value) const;
  40. bool operator&&(int _value) const;
  41. bool operator||(const ls::std::boxing::Boolean &_boolean) const;
  42. bool operator||(bool _value) const;
  43. bool operator||(int _value) const;
  44. // INFO: operator ^ can not be taken for XOR, since it's not possible to implement it respecting commutative law
  45. // implementation
  46. void parse(::std::string _parseText) override;
  47. [[nodiscard]] ::std::string toString() override;
  48. // additional functionality
  49. [[nodiscard]] bool getValue() const;
  50. [[nodiscard]] static bool XOR(const ls::std::boxing::Boolean &_leftExpression, const ls::std::boxing::Boolean &_rightExpression);
  51. [[nodiscard]] static bool XOR(const ls::std::boxing::Boolean &_leftExpression, bool _rightExpression);
  52. [[nodiscard]] static bool XOR(bool _leftExpression, const ls::std::boxing::Boolean &_rightExpression);
  53. [[nodiscard]] static bool XOR(bool _leftExpression, bool _rightExpression);
  54. private:
  55. bool value{};
  56. const ::std::string FALSE_STRING = "false";
  57. const ::std::string TRUE_STRING = "true";
  58. [[nodiscard]] ::std::string _toString() const;
  59. };
  60. }
  61. #endif