Long.cpp 6.0 KB

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