Integer.cpp 5.7 KB

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