Long.cpp 4.4 KB

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