Boolean.hpp 2.5 KB

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