Integer.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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-23
  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. // stream operators
  61. // TODO: not compilable
  62. // friend std::ostream& operator<<(std::ostream& outputStream, const Integer& _integer) {
  63. // outputStream << _integer.value;
  64. // return outputStream;
  65. // }
  66. //
  67. // friend std::istream& operator>>(std::istream& inputStream, Integer& _integer) {
  68. // inputStream >> _integer.value;
  69. // return inputStream;
  70. // }
  71. // logical operators
  72. friend bool operator!(const Integer& _integer) {
  73. return !_integer.value;
  74. }
  75. bool operator&&(const Integer& _integer) const;
  76. bool operator&&(int _value) const;
  77. bool operator&&(bool _expression) const;
  78. bool operator||(const Integer& _integer) const;
  79. bool operator||(int _value) const;
  80. bool operator||(bool _expression) const;
  81. // increment / decrement operator
  82. void operator++();
  83. void operator--();
  84. // implementation
  85. ls_std::byte_field load() override;
  86. ls_std::byte_field marshal() override;
  87. void parse(std::string _parseText) override;
  88. void save(const ls_std::byte_field& _data) override;
  89. std::string toString() override;
  90. void unmarshal(const ls_std::byte_field& _data) override;
  91. // additional functionality
  92. int getValue() const;
  93. void setSerializable(std::shared_ptr<ISerializable> _serializable);
  94. void setStorable(std::shared_ptr<IStorable> _storable);
  95. private:
  96. int value {};
  97. std::shared_ptr<ISerializable> serializable {};
  98. std::shared_ptr<IStorable> storable {};
  99. };
  100. }
  101. #endif