Boolean.hpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-09
  6. * Changed: 2020-09-04
  7. *
  8. * */
  9. #ifndef LS_STD_BOOLEAN_HPP
  10. #define LS_STD_BOOLEAN_HPP
  11. #include <memory>
  12. #include "../base/Class.hpp"
  13. #include "IBoxing.hpp"
  14. #include "../serialization/ISerializable.hpp"
  15. namespace ls_std {
  16. class Boolean : public Class, public IBoxing, public ISerializable {
  17. public:
  18. explicit Boolean(bool _value);
  19. Boolean();
  20. ~Boolean() = default;
  21. // conversion operator
  22. operator bool() const;
  23. // assignment operators
  24. Boolean& operator=(int _value);
  25. Boolean& operator=(bool _value);
  26. // stream operators
  27. friend std::ostream& operator<<(std::ostream& _outputStream, const Boolean& _boolean) {
  28. _outputStream << _boolean._toString();
  29. return _outputStream;
  30. }
  31. // logical operators
  32. friend bool operator!(const Boolean& _boolean) {
  33. return !_boolean.value;
  34. }
  35. bool operator&&(const Boolean& _boolean) const;
  36. bool operator&&(bool _value) const;
  37. bool operator&&(int _value) const;
  38. bool operator||(const Boolean& _boolean) const;
  39. bool operator||(bool _value) const;
  40. bool operator||(int _value) const;
  41. // INFO: operator ^ can not be taken for XOR, since it's not possible to implement it respecting commutative law
  42. // implementation
  43. ls_std::byte_field marshal() override;
  44. void parse(std::string _parseText) override;
  45. std::string toString() override;
  46. void unmarshal(const ls_std::byte_field& _data) override;
  47. // additional functionality
  48. bool getValue();
  49. void setSerializable(std::shared_ptr<ISerializable> _serializable);
  50. static bool XOR(const Boolean& _leftExpression, const Boolean& _rightExpression);
  51. static bool XOR(const Boolean& _leftExpression, bool _rightExpression);
  52. static bool XOR(bool _leftExpression, const Boolean& _rightExpression);
  53. static bool XOR(bool _leftExpression, bool _rightExpression);
  54. private:
  55. std::shared_ptr<ISerializable> serializable {};
  56. bool value {};
  57. const std::string TRUE_STRING = "true";
  58. const std::string FALSE_STRING = "false";
  59. std::string _toString() const;
  60. };
  61. }
  62. #endif