Long.cpp 4.5 KB

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