Long.cpp 4.7 KB

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