Boolean.hpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-09
  6. * Changed: 2023-05-17
  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(const ::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]] static ::std::string _fetchClassName();
  59. [[nodiscard]] ::std::string _toString() const;
  60. };
  61. }
  62. #endif