Boolean.hpp 2.5 KB

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