Float.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-14
  6. * Changed: 2021-04-23
  7. *
  8. * */
  9. #ifndef LS_STD_FLOAT_HPP
  10. #define LS_STD_FLOAT_HPP
  11. #include <memory>
  12. #include <ls_std/base/Class.hpp>
  13. #include "IBoxing.hpp"
  14. #include <ls_std/serialization/ISerializable.hpp>
  15. #include <ls_std/io/IStorable.hpp>
  16. namespace ls_std
  17. {
  18. class Float : public Class, public IBoxing, public ISerializable, public IStorable
  19. {
  20. public:
  21. Float();
  22. explicit Float(float _value);
  23. ~Float() override = default;
  24. // conversion operator
  25. operator float() const; // do not make explicit!
  26. // assignment operators
  27. ls_std::Float &operator=(float _value);
  28. // arithmetic operators
  29. float operator-() const;
  30. float operator+(const ls_std::Float &_float) const;
  31. float operator+(float _value) const;
  32. float operator*(const ls_std::Float &_float) const;
  33. float operator*(float _value) const;
  34. float operator-(const ls_std::Float &_float) const;
  35. float operator-(float _value) const;
  36. float operator/(const ls_std::Float &_float) const;
  37. float operator/(float _value) const;
  38. // compound operators
  39. ls_std::Float &operator+=(const ls_std::Float &_float);
  40. ls_std::Float &operator+=(float _value);
  41. ls_std::Float &operator-=(const ls_std::Float &_float);
  42. ls_std::Float &operator-=(float _value);
  43. ls_std::Float &operator*=(const ls_std::Float &_float);
  44. ls_std::Float &operator*=(float _value);
  45. ls_std::Float &operator/=(const ls_std::Float &_float);
  46. ls_std::Float &operator/=(float _value);
  47. // comparison operators
  48. bool operator==(const ls_std::Float &_float) const;
  49. bool operator==(float _value) const;
  50. bool operator!=(const ls_std::Float &_float) const;
  51. bool operator!=(float _value) const;
  52. bool operator>(const ls_std::Float &_float) const;
  53. bool operator>(float _value) const;
  54. bool operator>=(const ls_std::Float &_float) const;
  55. bool operator>=(float _value) const;
  56. bool operator<(const ls_std::Float &_float) const;
  57. bool operator<(float _value) const;
  58. bool operator<=(const ls_std::Float &_float) const;
  59. bool operator<=(float _value) const;
  60. // increment / decrement operator
  61. void operator++();
  62. void operator--();
  63. // implementation
  64. ls_std::byte_field load() override;
  65. ls_std::byte_field marshal() override;
  66. void parse(std::string _parseText) override;
  67. void save(const ls_std::byte_field &_data) override;
  68. std::string toString() override;
  69. void unmarshal(const ls_std::byte_field &_data) override;
  70. // additional functionality
  71. float getEpsilon();
  72. float getValue();
  73. void setEpsilon(float _epsilon);
  74. void setSerializable(std::shared_ptr<ISerializable> _serializable);
  75. void setStorable(std::shared_ptr<IStorable> _storable);
  76. private:
  77. float epsilon{};
  78. std::shared_ptr<ISerializable> serializable{};
  79. std::shared_ptr<IStorable> storable{};
  80. float value{};
  81. };
  82. }
  83. #endif