Integer.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-07
  6. * Changed: 2021-04-23
  7. *
  8. * */
  9. #ifndef LS_STD_INTEGER_HPP
  10. #define LS_STD_INTEGER_HPP
  11. #include <memory>
  12. #include <ls_std/base/Class.hpp>
  13. #include "IBoxing.hpp"
  14. #include <ls_std/serialization/ISerializable.hpp>
  15. #include <ls_std/io/IStorable.hpp>
  16. namespace ls_std
  17. {
  18. class Integer : public Class, public IBoxing, public ISerializable, public IStorable
  19. {
  20. public:
  21. explicit Integer(int _value);
  22. Integer();
  23. ~Integer() override = default;
  24. // conversion operator
  25. operator int() const;
  26. // assignment operators
  27. ls_std::Integer &operator=(int _value);
  28. // arithmetic operators
  29. int operator-() const;
  30. int operator+(const ls_std::Integer &_integer) const;
  31. int operator+(int _value) const;
  32. int operator*(const ls_std::Integer &_integer) const;
  33. int operator*(int _value) const;
  34. int operator-(const ls_std::Integer &_integer) const;
  35. int operator-(int _value) const;
  36. int operator/(const ls_std::Integer &_integer) const;
  37. int operator/(int _value) const;
  38. int operator%(const ls_std::Integer &_integer) const;
  39. int operator%(int _value) const;
  40. // compound operators
  41. ls_std::Integer &operator+=(const ls_std::Integer &_integer);
  42. ls_std::Integer &operator+=(int _value);
  43. ls_std::Integer &operator-=(const ls_std::Integer &_integer);
  44. ls_std::Integer &operator-=(int _value);
  45. ls_std::Integer &operator*=(const ls_std::Integer &_integer);
  46. ls_std::Integer &operator*=(int _value);
  47. ls_std::Integer &operator/=(const ls_std::Integer &_integer);
  48. ls_std::Integer &operator/=(int _value);
  49. // comparison operators
  50. bool operator==(const ls_std::Integer &_integer) const;
  51. bool operator==(int _value) const;
  52. bool operator!=(const ls_std::Integer &_integer) const;
  53. bool operator!=(int _value) const;
  54. bool operator>(const ls_std::Integer &_integer) const;
  55. bool operator>(int _value) const;
  56. bool operator>=(const ls_std::Integer &_integer) const;
  57. bool operator>=(int _value) const;
  58. bool operator<(const ls_std::Integer &_integer) const;
  59. bool operator<(int _value) const;
  60. bool operator<=(const ls_std::Integer &_integer) const;
  61. bool operator<=(int _value) const;
  62. // logical operators
  63. friend bool operator!(const ls_std::Integer &_integer)
  64. {
  65. return !_integer.value;
  66. }
  67. bool operator&&(const ls_std::Integer &_integer) const;
  68. bool operator&&(int _value) const;
  69. bool operator&&(bool _expression) const;
  70. bool operator||(const ls_std::Integer &_integer) const;
  71. bool operator||(int _value) const;
  72. bool operator||(bool _expression) const;
  73. // increment / decrement operator
  74. void operator++();
  75. void operator--();
  76. // implementation
  77. ls_std::byte_field load() override;
  78. ls_std::byte_field marshal() override;
  79. void parse(std::string _parseText) override;
  80. void save(const ls_std::byte_field &_data) override;
  81. std::string toString() override;
  82. void unmarshal(const ls_std::byte_field &_data) override;
  83. // additional functionality
  84. int getValue() const;
  85. void setSerializable(std::shared_ptr<ISerializable> _serializable);
  86. void setStorable(std::shared_ptr<IStorable> _storable);
  87. private:
  88. std::shared_ptr<ISerializable> serializable{};
  89. std::shared_ptr<IStorable> storable{};
  90. int value{};
  91. };
  92. }
  93. #endif