Long.cpp 5.4 KB

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