Boolean.hpp 2.5 KB

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