Integer.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-07
  6. * Changed: 2023-02-22
  7. *
  8. * */
  9. #include <ls-std/boxing/Integer.hpp>
  10. #include <ls-std/core/exception/IllegalArithmeticOperationException.hpp>
  11. ls::std::boxing::Integer::Integer(int _value) : ls::std::core::Class("Integer"), value(_value)
  12. {}
  13. ls::std::boxing::Integer::Integer() : ls::std::core::Class("Integer")
  14. {}
  15. ls::std::boxing::Integer::~Integer() noexcept = default;
  16. ls::std::boxing::Integer &ls::std::boxing::Integer::operator=(int _value)
  17. {
  18. this->value = _value;
  19. return *this;
  20. }
  21. int ls::std::boxing::Integer::operator-() const
  22. {
  23. return -this->value;
  24. }
  25. int ls::std::boxing::Integer::operator+(const ls::std::boxing::Integer &_integer) const
  26. {
  27. return this->value + _integer.getValue();
  28. }
  29. int ls::std::boxing::Integer::operator+(int _value) const
  30. {
  31. return this->value + _value;
  32. }
  33. int ls::std::boxing::Integer::operator*(const ls::std::boxing::Integer &_integer) const
  34. {
  35. return this->value * _integer.getValue();
  36. }
  37. int ls::std::boxing::Integer::operator*(int _value) const
  38. {
  39. return this->value * _value;
  40. }
  41. int ls::std::boxing::Integer::operator-(const ls::std::boxing::Integer &_integer) const
  42. {
  43. return this->value - _integer.getValue();
  44. }
  45. int ls::std::boxing::Integer::operator-(int _value) const
  46. {
  47. return this->value - _value;
  48. }
  49. int ls::std::boxing::Integer::operator/(const ls::std::boxing::Integer &_integer) const
  50. {
  51. if (_integer == 0)
  52. {
  53. throw ls::std::core::IllegalArithmeticOperationException{"division by zero is not allowed"};
  54. }
  55. return this->value / _integer.getValue();
  56. }
  57. int ls::std::boxing::Integer::operator/(int _value) const
  58. {
  59. if (_value == 0)
  60. {
  61. throw ls::std::core::IllegalArithmeticOperationException{"division by zero is not allowed"};
  62. }
  63. return this->value / _value;
  64. }
  65. int ls::std::boxing::Integer::operator%(const ls::std::boxing::Integer &_integer) const
  66. {
  67. return this->value % _integer.getValue();
  68. }
  69. int ls::std::boxing::Integer::operator%(int _value) const
  70. {
  71. return this->value % _value;
  72. }
  73. ls::std::boxing::Integer &ls::std::boxing::Integer::operator+=(const ls::std::boxing::Integer &_integer)
  74. {
  75. this->value += _integer.getValue();
  76. return *this;
  77. }
  78. ls::std::boxing::Integer &ls::std::boxing::Integer::operator+=(int _value)
  79. {
  80. this->value += _value;
  81. return *this;
  82. }
  83. ls::std::boxing::Integer &ls::std::boxing::Integer::operator-=(const ls::std::boxing::Integer &_integer)
  84. {
  85. this->value -= _integer.getValue();
  86. return *this;
  87. }
  88. ls::std::boxing::Integer &ls::std::boxing::Integer::operator-=(int _value)
  89. {
  90. this->value -= _value;
  91. return *this;
  92. }
  93. ls::std::boxing::Integer &ls::std::boxing::Integer::operator*=(const ls::std::boxing::Integer &_integer)
  94. {
  95. this->value *= _integer.getValue();
  96. return *this;
  97. }
  98. ls::std::boxing::Integer &ls::std::boxing::Integer::operator*=(int _value)
  99. {
  100. this->value *= _value;
  101. return *this;
  102. }
  103. ls::std::boxing::Integer &ls::std::boxing::Integer::operator/=(const ls::std::boxing::Integer &_integer)
  104. {
  105. if (_integer == 0)
  106. {
  107. throw ls::std::core::IllegalArithmeticOperationException{"division by zero is not allowed"};
  108. }
  109. this->value /= _integer.getValue();
  110. return *this;
  111. }
  112. ls::std::boxing::Integer &ls::std::boxing::Integer::operator/=(int _value)
  113. {
  114. if (_value == 0)
  115. {
  116. throw ls::std::core::IllegalArithmeticOperationException{"division by zero is not allowed"};
  117. }
  118. this->value /= _value;
  119. return *this;
  120. }
  121. bool ls::std::boxing::Integer::operator==(const ls::std::boxing::Integer &_integer) const
  122. {
  123. return this->value == _integer.getValue();
  124. }
  125. bool ls::std::boxing::Integer::operator==(int _value) const
  126. {
  127. return this->value == _value;
  128. }
  129. bool ls::std::boxing::Integer::operator!=(const ls::std::boxing::Integer &_integer) const
  130. {
  131. return this->value != _integer.getValue();
  132. }
  133. bool ls::std::boxing::Integer::operator!=(int _value) const
  134. {
  135. return this->value != _value;
  136. }
  137. bool ls::std::boxing::Integer::operator>(const ls::std::boxing::Integer &_integer) const
  138. {
  139. return this->value > _integer.getValue();
  140. }
  141. bool ls::std::boxing::Integer::operator>(int _value) const
  142. {
  143. return this->value > _value;
  144. }
  145. bool ls::std::boxing::Integer::operator>=(const ls::std::boxing::Integer &_integer) const
  146. {
  147. return this->value >= _integer.getValue();
  148. }
  149. bool ls::std::boxing::Integer::operator>=(int _value) const
  150. {
  151. return this->value >= _value;
  152. }
  153. bool ls::std::boxing::Integer::operator<(const ls::std::boxing::Integer &_integer) const
  154. {
  155. return this->value < _integer.getValue();
  156. }
  157. bool ls::std::boxing::Integer::operator<(int _value) const
  158. {
  159. return this->value < _value;
  160. }
  161. bool ls::std::boxing::Integer::operator<=(const ls::std::boxing::Integer &_integer) const
  162. {
  163. return this->value <= _integer.getValue();
  164. }
  165. bool ls::std::boxing::Integer::operator<=(int _value) const
  166. {
  167. return this->value <= _value;
  168. }
  169. bool ls::std::boxing::Integer::operator&&(const ls::std::boxing::Integer &_integer) const
  170. {
  171. return this->value && _integer.getValue();
  172. }
  173. bool ls::std::boxing::Integer::operator&&(int _value) const
  174. {
  175. return this->value && _value;
  176. }
  177. bool ls::std::boxing::Integer::operator&&(bool _expression) const
  178. {
  179. return this->value && _expression;
  180. }
  181. bool ls::std::boxing::Integer::operator||(const ls::std::boxing::Integer &_integer) const
  182. {
  183. return this->value || _integer.getValue();
  184. }
  185. bool ls::std::boxing::Integer::operator||(int _value) const
  186. {
  187. return this->value || _value;
  188. }
  189. bool ls::std::boxing::Integer::operator||(bool _expression) const
  190. {
  191. return this->value || _expression;
  192. }
  193. void ls::std::boxing::Integer::operator++()
  194. {
  195. this->value += 1;
  196. }
  197. void ls::std::boxing::Integer::operator--()
  198. {
  199. this->value -= 1;
  200. }
  201. void ls::std::boxing::Integer::parse(::std::string _parseText)
  202. {
  203. this->value = ::std::stoi(_parseText);
  204. }
  205. std::string ls::std::boxing::Integer::toString()
  206. {
  207. return ::std::to_string(this->value);
  208. }
  209. int ls::std::boxing::Integer::getValue() const
  210. {
  211. return this->value;
  212. }