Integer.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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-16
  7. *
  8. * */
  9. #ifndef INTEGER_HPP
  10. #define INTEGER_HPP
  11. #include "../base/Class.hpp"
  12. #include "IBoxing.hpp"
  13. namespace ls_std {
  14. class Integer : public Class, IBoxing {
  15. public:
  16. explicit Integer(int _value);
  17. Integer();
  18. ~Integer() = default;
  19. // conversion operator
  20. operator int() const;
  21. // assignment operators
  22. Integer& operator=(int _value);
  23. // arithmetic operators
  24. int operator-() const;
  25. int operator+(const Integer& _integer) const;
  26. int operator+(int _value) const;
  27. int operator*(const Integer& _integer) const;
  28. int operator*(int _value) const;
  29. int operator-(const Integer& _integer) const;
  30. int operator-(int _value) const;
  31. int operator/(const Integer& _integer) const;
  32. int operator/(int _value) const;
  33. int operator%(const Integer& _integer) const;
  34. int operator%(int _value) const;
  35. // compound operators
  36. Integer& operator+=(const Integer& _integer);
  37. Integer& operator+=(int _value);
  38. Integer& operator-=(const Integer& _integer);
  39. Integer& operator-=(int _value);
  40. Integer& operator*=(const Integer& _integer);
  41. Integer& operator*=(int _value);
  42. Integer& operator/=(const Integer& _integer);
  43. Integer& operator/=(int _value);
  44. // comparison operators
  45. bool operator==(const Integer& _integer) const;
  46. bool operator==(int _value) const;
  47. bool operator!=(const Integer& _integer) const;
  48. bool operator!=(int _value) const;
  49. bool operator>(const Integer& _integer) const;
  50. bool operator>(int _value) const;
  51. bool operator>=(const Integer& _integer) const;
  52. bool operator>=(int _value) const;
  53. bool operator<(const Integer& _integer) const;
  54. bool operator<(int _value) const;
  55. bool operator<=(const Integer& _integer) const;
  56. bool operator<=(int _value) const;
  57. // stream operators
  58. // TODO: not compilable
  59. // friend std::ostream& operator<<(std::ostream& outputStream, const Integer& _integer) {
  60. // outputStream << _integer.value;
  61. // return outputStream;
  62. // }
  63. //
  64. // friend std::istream& operator>>(std::istream& inputStream, Integer& _integer) {
  65. // inputStream >> _integer.value;
  66. // return inputStream;
  67. // }
  68. // logical operators
  69. friend bool operator!(const Integer& _integer) {
  70. return !_integer.value;
  71. }
  72. bool operator&&(const Integer& _integer) const;
  73. bool operator&&(int _value) const;
  74. bool operator&&(bool _expression) const;
  75. bool operator||(const Integer& _integer) const;
  76. bool operator||(int _value) const;
  77. bool operator||(bool _expression) const;
  78. // increment / decrement operator
  79. void operator++();
  80. void operator--();
  81. // implementation
  82. void parse(std::string _parseText) override;
  83. std::string toString() override;
  84. // additional functionality
  85. int getValue() const;
  86. private:
  87. int value {};
  88. };
  89. }
  90. #endif