Integer.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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-07
  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. // assignment operators
  20. Integer& operator=(int _value);
  21. // arithmetic operators
  22. int operator-() const;
  23. int operator+(const Integer& _integer) const;
  24. int operator+(int _value) 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. // compound operators
  32. Integer& operator+=(const Integer& _integer);
  33. Integer& operator+=(int _value);
  34. Integer& operator-=(const Integer& _integer);
  35. Integer& operator-=(int _value);
  36. Integer& operator*=(const Integer& _integer);
  37. Integer& operator*=(int _value);
  38. Integer& operator/=(const Integer& _integer);
  39. Integer& operator/=(int _value);
  40. // comparison operators
  41. bool operator==(const Integer& _integer) const;
  42. bool operator==(int _value) const;
  43. bool operator!=(const Integer& _integer) const;
  44. bool operator!=(int _value) const;
  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. // stream operators
  54. friend std::ostream& operator<<(std::ostream& outputStream, const Integer& _integer) {
  55. outputStream << _integer.value;
  56. return outputStream;
  57. }
  58. friend std::istream& operator>>(std::istream& inputStream, Integer& _integer) {
  59. inputStream >> _integer.value;
  60. return inputStream;
  61. }
  62. // logical operators
  63. friend bool operator!(const Integer& _integer) {
  64. return !_integer.value;
  65. }
  66. bool operator&&(const Integer& _integer) const;
  67. bool operator&&(int _value) const;
  68. bool operator||(const Integer& _integer) const;
  69. bool operator||(int _value) const;
  70. // increment / decrement operator
  71. void operator++();
  72. void operator--();
  73. // implementation
  74. void parse(std::string parseText) override;
  75. int value {};
  76. };
  77. }
  78. #endif