generic_value.hxx 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. #ifndef GENERIC_VALUE_HXX
  2. #define GENERIC_VALUE_HXX
  3. #include "../utils/generic_arithmetic.hxx"
  4. #include <new>
  5. namespace binom {
  6. class GenericValueIterator;
  7. class ReverseGenericValueIterator;
  8. class GenericValueRef;
  9. class GenericValue :
  10. public arithmetic::ArithmeticTypeBase<GenericValue>,
  11. public arithmetic::CastableArithmeticTypeBase<GenericValue>,
  12. arithmetic::EnableCopyableArithmetic,
  13. arithmetic::ArithmeticMthrImplPlaceholders {
  14. USE_ARITHMETIC
  15. USE_ARITHMETIC_CAST
  16. ValType type;
  17. arithmetic::ArithmeticData data;
  18. // ArithmeticTypeBase & CopyableArithmeticTypeBase Implementation
  19. arithmetic::ArithmeticData& getArithmeticDataImpl() const;
  20. ValType getValTypeImpl() const;
  21. // CastableArithmeticTypeBase implementation
  22. void reallocateImpl([[maybe_unused]] ValType type) noexcept;
  23. void setTypeImpl(ValType new_type) noexcept;
  24. friend class Variable;
  25. friend class Number;
  26. friend class GenericValueRef;
  27. friend class KeyValue;
  28. GenericValue(ValType type, arithmetic::ArithmeticData data);
  29. priv::ResourceData toResourceData() const noexcept;
  30. public:
  31. GenericValue() noexcept;
  32. GenericValue(bool value) noexcept;
  33. GenericValue(ui8 value) noexcept;
  34. GenericValue(i8 value) noexcept;
  35. GenericValue(ui16 value) noexcept;
  36. GenericValue(i16 value) noexcept;
  37. GenericValue(ui32 value) noexcept;
  38. GenericValue(i32 value) noexcept;
  39. GenericValue(f32 value) noexcept;
  40. GenericValue(ui64 value) noexcept;
  41. GenericValue(i64 value) noexcept;
  42. GenericValue(f64 value) noexcept;
  43. GenericValue(const GenericValue& other);
  44. GenericValue(const GenericValue&& other);
  45. using arithmetic::ArithmeticTypeBase<GenericValue>::operator=;
  46. };
  47. class GenericValueRef :
  48. public arithmetic::ArithmeticTypeBase<GenericValueRef>,
  49. arithmetic::ArithmeticMthrImplPlaceholders {
  50. USE_ARITHMETIC
  51. ValType value_type;
  52. union pointer {
  53. void* ptr;
  54. bool* bool_ptr;
  55. ui8* ui8_ptr;
  56. ui16* ui16_ptr;
  57. ui32* ui32_ptr;
  58. ui64* ui64_ptr;
  59. i8* i8_ptr;
  60. i16* i16_ptr;
  61. i32* i32_ptr;
  62. i64* i64_ptr;
  63. f32* f32_ptr;
  64. f64* f64_ptr;
  65. arithmetic::ArithmeticData* num_data_ptr;
  66. pointer(void* ptr) : ptr(ptr) {}
  67. } ptr;
  68. arithmetic::ArithmeticData& getArithmeticDataImpl() const noexcept;
  69. ValType getValTypeImpl() const noexcept;
  70. friend class GenericValueIterator;
  71. friend class ReverseGenericValueIterator;
  72. friend class Number;
  73. friend class BufferArray;
  74. friend class priv::BufferArrayImplementation;
  75. GenericValueRef(ValType value_type, void* ptr);
  76. public:
  77. GenericValueRef(const GenericValueRef& other);
  78. GenericValueRef(const GenericValueRef&& other);
  79. using arithmetic::ArithmeticTypeBase<GenericValueRef>::operator=;
  80. operator GenericValue() const;
  81. };
  82. class GenericValueIterator {
  83. ValType value_type;
  84. mutable union pointer {
  85. void* ptr;
  86. bool* bool_ptr;
  87. ui8* ui8_ptr;
  88. ui16* ui16_ptr;
  89. ui32* ui32_ptr;
  90. ui64* ui64_ptr;
  91. i8* i8_ptr;
  92. i16* i16_ptr;
  93. i32* i32_ptr;
  94. i64* i64_ptr;
  95. f32* f32_ptr;
  96. f64* f64_ptr;
  97. arithmetic::ArithmeticData* num_data_ptr;
  98. pointer(void* ptr) : ptr(ptr) {}
  99. } ptr;
  100. friend class BufferArray;
  101. friend class priv::BufferArrayImplementation;
  102. GenericValueIterator(ValType value_type, void* ptr);
  103. public:
  104. GenericValueIterator(const GenericValueIterator& other);
  105. GenericValueIterator(const GenericValueIterator&& other);
  106. GenericValueIterator& operator=(GenericValueIterator&& other) noexcept;
  107. GenericValueIterator& operator++() noexcept;
  108. GenericValueIterator& operator--() noexcept;
  109. const GenericValueIterator& operator++() const noexcept;
  110. const GenericValueIterator& operator--() const noexcept;
  111. GenericValueIterator operator+(ssize_t) noexcept;
  112. GenericValueIterator operator-(ssize_t) noexcept;
  113. const GenericValueIterator operator+(ssize_t) const noexcept;
  114. const GenericValueIterator operator-(ssize_t) const noexcept;
  115. GenericValueIterator operator++(int) noexcept;
  116. GenericValueIterator operator--(int) noexcept;
  117. const GenericValueIterator operator++(int) const noexcept;
  118. const GenericValueIterator operator--(int) const noexcept;
  119. GenericValueIterator& operator+=(ssize_t shift) noexcept;
  120. GenericValueIterator& operator-=(ssize_t shift) noexcept;
  121. const GenericValueIterator& operator+=(ssize_t shift) const noexcept;
  122. const GenericValueIterator& operator-=(ssize_t shift) const noexcept;
  123. bool operator==(GenericValueIterator&& other) const noexcept;
  124. bool operator!=(GenericValueIterator&& other) const noexcept;
  125. bool operator==(const GenericValueIterator& other) const noexcept;
  126. bool operator!=(const GenericValueIterator& other) const noexcept;
  127. GenericValueRef operator*() noexcept;
  128. const GenericValueRef operator*() const noexcept;
  129. GenericValueRef operator[](ssize_t) noexcept;
  130. const GenericValueRef operator[](ssize_t) const noexcept;
  131. };
  132. class ReverseGenericValueIterator {
  133. friend class GenericValueIterator;
  134. ValType value_type;
  135. mutable union pointer {
  136. void* ptr;
  137. bool* bool_ptr;
  138. ui8* ui8_ptr;
  139. ui16* ui16_ptr;
  140. ui32* ui32_ptr;
  141. ui64* ui64_ptr;
  142. i8* i8_ptr;
  143. i16* i16_ptr;
  144. i32* i32_ptr;
  145. i64* i64_ptr;
  146. f32* f32_ptr;
  147. f64* f64_ptr;
  148. arithmetic::ArithmeticData* num_data_ptr;
  149. pointer(void* ptr) : ptr(ptr) {}
  150. } ptr;
  151. friend class BufferArray;
  152. friend class priv::BufferArrayImplementation;
  153. ReverseGenericValueIterator(ValType value_type, void* ptr);
  154. public:
  155. ReverseGenericValueIterator(const ReverseGenericValueIterator& other);
  156. ReverseGenericValueIterator(ReverseGenericValueIterator&& other);
  157. ReverseGenericValueIterator& operator=(ReverseGenericValueIterator&& other) noexcept;
  158. ReverseGenericValueIterator& operator++() noexcept;
  159. ReverseGenericValueIterator& operator--() noexcept;
  160. const ReverseGenericValueIterator& operator++() const noexcept;
  161. const ReverseGenericValueIterator& operator--() const noexcept;
  162. ReverseGenericValueIterator operator++(int) noexcept;
  163. ReverseGenericValueIterator operator--(int) noexcept;
  164. const ReverseGenericValueIterator operator++(int) const noexcept;
  165. const ReverseGenericValueIterator operator--(int) const noexcept;
  166. ReverseGenericValueIterator& operator+=(ptrdiff_t shift) noexcept;
  167. ReverseGenericValueIterator& operator-=(ptrdiff_t shift) noexcept;
  168. const ReverseGenericValueIterator& operator+=(ptrdiff_t shift) const noexcept;
  169. const ReverseGenericValueIterator& operator-=(ptrdiff_t shift) const noexcept;
  170. bool operator==(ReverseGenericValueIterator&& other) const noexcept;
  171. bool operator!=(ReverseGenericValueIterator&& other) const noexcept;
  172. GenericValueRef operator*() noexcept;
  173. const GenericValueRef operator*() const noexcept;
  174. };
  175. }
  176. #endif // GENERIC_VALUE_HXX