Boolean.hpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Co-Author: Claude Sonnet 4.6 (LLM)
  4. * Company: Lynar Studios
  5. * E-Mail: webmaster@lynarstudios.com
  6. * Created: 2020-08-09
  7. * Changed: 2026-06-23
  8. *
  9. * */
  10. #ifndef LS_STD_BOOLEAN_HPP
  11. #define LS_STD_BOOLEAN_HPP
  12. #include <ls-std/core/Class.hpp>
  13. #include <ls-std/core/interface/IBoxing.hpp>
  14. #include <ls-std/os/dynamic-goal.hpp>
  15. #include <memory>
  16. #include <sstream>
  17. /*
  18. * @doc: class(name: 'Boolean', package: 'boxing')
  19. * @doc: boxing.Boolean.description('This class represents the primitive datatype bool and provides functionalities for boolean expressions and string representation.')
  20. * */
  21. namespace ls::standard::boxing
  22. {
  23. class LS_STD_DYNAMIC_GOAL Boolean : public ls::standard::core::Class, public ls::standard::core::interface_type::IBoxing
  24. {
  25. public:
  26. explicit Boolean(bool _value);
  27. Boolean();
  28. ~Boolean() noexcept override;
  29. // assignment operators
  30. ls::standard::boxing::Boolean &operator=(int _value);
  31. ls::standard::boxing::Boolean &operator=(bool _value);
  32. // stream operators
  33. friend ::std::ostream &operator<<(::std::ostream &_outputStream, const ls::standard::boxing::Boolean &_boolean)
  34. {
  35. _outputStream << _boolean._toString();
  36. return _outputStream;
  37. }
  38. // logical operators
  39. friend bool operator!(const ls::standard::boxing::Boolean &_boolean)
  40. {
  41. return !_boolean.value;
  42. }
  43. bool operator&&(const ls::standard::boxing::Boolean &_boolean) const;
  44. bool operator&&(bool _value) const;
  45. bool operator&&(int _value) const;
  46. bool operator||(const ls::standard::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(const ::std::string &_parseText) override;
  52. [[nodiscard]] ::std::string toString() override;
  53. // additional functionality
  54. [[nodiscard]] bool getValue() const;
  55. [[nodiscard]] static bool XOR(const ls::standard::boxing::Boolean &_leftExpression, const ls::standard::boxing::Boolean &_rightExpression);
  56. [[nodiscard]] static bool XOR(const ls::standard::boxing::Boolean &_leftExpression, bool _rightExpression);
  57. [[nodiscard]] static bool XOR(bool _leftExpression, const ls::standard::boxing::Boolean &_rightExpression);
  58. [[nodiscard]] 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. [[nodiscard]] static ::std::string _fetchClassName();
  64. [[nodiscard]] ::std::string _toString() const;
  65. };
  66. }
  67. #endif