Boolean.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-09
  6. * Changed: 2024-09-09
  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. * @doc: class(name: 'Boolean', package: 'boxing')
  18. * @doc: boxing.Boolean.description('This class represents the primitive datatype bool and provides functionalities for boolean expressions and string representation.')
  19. * */
  20. namespace ls::std::boxing
  21. {
  22. class LS_STD_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() noexcept override;
  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(const ::std::string &_parseText) override;
  51. [[nodiscard]] ::std::string toString() override;
  52. // additional functionality
  53. [[nodiscard]] bool getValue() const;
  54. [[nodiscard]] static bool XOR(const ls::std::boxing::Boolean &_leftExpression, const ls::std::boxing::Boolean &_rightExpression);
  55. [[nodiscard]] static bool XOR(const ls::std::boxing::Boolean &_leftExpression, bool _rightExpression);
  56. [[nodiscard]] static bool XOR(bool _leftExpression, const ls::std::boxing::Boolean &_rightExpression);
  57. [[nodiscard]] 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. [[nodiscard]] static ::std::string _fetchClassName();
  63. [[nodiscard]] ::std::string _toString() const;
  64. };
  65. }
  66. #endif