Boolean.hpp 2.6 KB

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