Integer.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. #include "Integer.hpp"
  10. #include "../exception/IllegalOperationException.hpp"
  11. ls_std::Integer::Integer(int _value) : Class("Integer"),
  12. value(_value)
  13. {}
  14. ls_std::Integer::Integer() : Class("Integer")
  15. {}
  16. ls_std::Integer& ls_std::Integer::operator=(int _value)
  17. {
  18. this->value = _value;
  19. return *this;
  20. }
  21. int ls_std::Integer::operator-() const
  22. {
  23. return -this->value;
  24. }
  25. int ls_std::Integer::operator+(const Integer &_integer) const
  26. {
  27. return this->value + _integer.value;
  28. }
  29. int ls_std::Integer::operator+(int _value) const
  30. {
  31. return this->value + _value;
  32. }
  33. int ls_std::Integer::operator*(const Integer &_integer) const
  34. {
  35. return this->value * _integer.value;
  36. }
  37. int ls_std::Integer::operator*(int _value) const
  38. {
  39. return this->value * _value;
  40. }
  41. int ls_std::Integer::operator-(const Integer &_integer) const
  42. {
  43. return this->value - _integer.value;
  44. }
  45. int ls_std::Integer::operator-(int _value) const
  46. {
  47. return this->value - _value;
  48. }
  49. int ls_std::Integer::operator/(const Integer &_integer) const
  50. {
  51. if(_integer.value == 0) {
  52. throw ls_std::IllegalOperationException {};
  53. }
  54. return this->value / _integer.value;
  55. }
  56. int ls_std::Integer::operator/(int _value) const
  57. {
  58. if(_value == 0) {
  59. throw ls_std::IllegalOperationException {};
  60. }
  61. return this->value / _value;
  62. }
  63. ls_std::Integer & ls_std::Integer::operator+=(const Integer &_integer)
  64. {
  65. this->value += _integer.value;
  66. return *this;
  67. }
  68. ls_std::Integer & ls_std::Integer::operator+=(int _value)
  69. {
  70. this->value += _value;
  71. return *this;
  72. }
  73. ls_std::Integer & ls_std::Integer::operator-=(const Integer &_integer)
  74. {
  75. this->value -= _integer.value;
  76. return *this;
  77. }
  78. ls_std::Integer & ls_std::Integer::operator-=(int _value)
  79. {
  80. this->value -= _value;
  81. return *this;
  82. }
  83. ls_std::Integer & ls_std::Integer::operator*=(const Integer &_integer)
  84. {
  85. this->value *= _integer.value;
  86. return *this;
  87. }
  88. ls_std::Integer & ls_std::Integer::operator*=(int _value)
  89. {
  90. this->value *= _value;
  91. return *this;
  92. }
  93. ls_std::Integer & ls_std::Integer::operator/=(const Integer &_integer)
  94. {
  95. if(_integer.value == 0) {
  96. throw ls_std::IllegalOperationException {};
  97. }
  98. this->value /= _integer.value;
  99. return *this;
  100. }
  101. ls_std::Integer & ls_std::Integer::operator/=(int _value)
  102. {
  103. if(_value == 0) {
  104. throw ls_std::IllegalOperationException {};
  105. }
  106. this->value /= _value;
  107. return *this;
  108. }
  109. bool ls_std::Integer::operator==(const Integer &_integer) const
  110. {
  111. return this->value == _integer.value;
  112. }
  113. bool ls_std::Integer::operator==(int _value) const
  114. {
  115. return this->value == _value;
  116. }
  117. bool ls_std::Integer::operator!=(const Integer &_integer) const
  118. {
  119. return this->value == _integer.value;
  120. }
  121. bool ls_std::Integer::operator!=(int _value) const
  122. {
  123. return this->value == _value;
  124. }
  125. bool ls_std::Integer::operator>(const Integer &_integer) const
  126. {
  127. return this->value > _integer.value;
  128. }
  129. bool ls_std::Integer::operator>(int _value) const
  130. {
  131. return this->value > _value;
  132. }
  133. bool ls_std::Integer::operator>=(const Integer &_integer) const
  134. {
  135. return this->value >= _integer.value;
  136. }
  137. bool ls_std::Integer::operator>=(int _value) const
  138. {
  139. return this->value >= _value;
  140. }
  141. bool ls_std::Integer::operator<(const Integer &_integer) const
  142. {
  143. return this->value < _integer.value;
  144. }
  145. bool ls_std::Integer::operator<(int _value) const
  146. {
  147. return this->value < _value;
  148. }
  149. bool ls_std::Integer::operator<=(const Integer &_integer) const
  150. {
  151. return this->value <= _integer.value;
  152. }
  153. bool ls_std::Integer::operator<=(int _value) const
  154. {
  155. return this->value <= _value;
  156. }
  157. bool ls_std::Integer::operator&&(const Integer &_integer) const
  158. {
  159. return this->value && _integer.value;
  160. }
  161. bool ls_std::Integer::operator&&(int _value) const
  162. {
  163. return this->value && _value;
  164. }
  165. bool ls_std::Integer::operator||(const Integer &_integer) const
  166. {
  167. return this->value || _integer.value;
  168. }
  169. bool ls_std::Integer::operator||(int _value) const
  170. {
  171. return this->value || _value;
  172. }
  173. void ls_std::Integer::operator++()
  174. {
  175. this->value += 1;
  176. }
  177. void ls_std::Integer::operator--()
  178. {
  179. this->value -= 1;
  180. }
  181. void ls_std::Integer::parse(std::string parseText)
  182. {
  183. this->value = std::stoi(parseText);
  184. }