Integer.hpp 3.3 KB

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