Boolean.hpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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-06
  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() override;
  24. // conversion operator
  25. operator bool() const;
  26. // assignment operators
  27. ls::std::boxing::Boolean &operator=(int _value);
  28. ls::std::boxing::Boolean &operator=(bool _value);
  29. // stream operators
  30. friend ::std::ostream &operator<<(::std::ostream &_outputStream, const ls::std::boxing::Boolean &_boolean)
  31. {
  32. _outputStream << _boolean._toString();
  33. return _outputStream;
  34. }
  35. // logical operators
  36. friend bool operator!(const ls::std::boxing::Boolean &_boolean)
  37. {
  38. return !_boolean.value;
  39. }
  40. bool operator&&(const ls::std::boxing::Boolean &_boolean) const;
  41. bool operator&&(bool _value) const;
  42. bool operator&&(int _value) const;
  43. bool operator||(const ls::std::boxing::Boolean &_boolean) const;
  44. bool operator||(bool _value) const;
  45. bool operator||(int _value) const;
  46. // INFO: operator ^ can not be taken for XOR, since it's not possible to implement it respecting commutative law
  47. // implementation
  48. void parse(::std::string _parseText) override;
  49. [[nodiscard]] ::std::string toString() override;
  50. // additional functionality
  51. [[nodiscard]] bool getValue() const;
  52. [[nodiscard]] static bool XOR(const ls::std::boxing::Boolean &_leftExpression, const ls::std::boxing::Boolean &_rightExpression);
  53. [[nodiscard]] static bool XOR(const ls::std::boxing::Boolean &_leftExpression, bool _rightExpression);
  54. [[nodiscard]] static bool XOR(bool _leftExpression, const ls::std::boxing::Boolean &_rightExpression);
  55. [[nodiscard]] static bool XOR(bool _leftExpression, bool _rightExpression);
  56. private:
  57. bool value{};
  58. const ::std::string FALSE_STRING = "false";
  59. const ::std::string TRUE_STRING = "true";
  60. [[nodiscard]] ::std::string _toString() const;
  61. };
  62. }
  63. #endif