buffer_array.hxx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #ifndef BUFFER_ARRAY_HXX
  2. #define BUFFER_ARRAY_HXX
  3. #include "variable.hxx"
  4. #include "../binom_impl/ram_storage_implementation/buffer_array_impl.hxx"
  5. namespace binom {
  6. class BufferArray : public Variable {
  7. operator Number& () = delete;
  8. operator BitArray& () = delete;
  9. operator Array& () = delete;
  10. operator List& () = delete;
  11. operator Map& () = delete;
  12. operator MultiMap& () = delete;
  13. operator Table& () = delete;
  14. Number& toNumber() = delete;
  15. BitArray& toBitArray() = delete;
  16. BufferArray& toBufferArray() = delete;
  17. Array& toArray() = delete;
  18. List& toList() = delete;
  19. Map& toMap() = delete;
  20. MultiMap& toMultiMap() = delete;
  21. Table& toTable() = delete;
  22. operator const Number& () const = delete;
  23. operator const BitArray& () const = delete;
  24. operator const Array& () const = delete;
  25. operator const List& () const = delete;
  26. operator const Map& () const = delete;
  27. operator const MultiMap& () const = delete;
  28. operator const Table& () const = delete;
  29. const Number& toNumber() const = delete;
  30. const BitArray& toBitArray() const = delete;
  31. const BufferArray& toBufferArray() const = delete;
  32. const Array& toArray() const = delete;
  33. const List& toList() const = delete;
  34. const Map& toMap() const = delete;
  35. const MultiMap& toMultiMap() const = delete;
  36. const Table& toTable() const = delete;
  37. Variable& operator=(const Variable& other) = delete;
  38. Variable& operator=(Variable&& other) = delete;
  39. Variable& changeLink(const Variable& other) = delete;
  40. Variable& changeLink(Variable&& other) = delete;
  41. priv::BufferArrayImplementation*& getData() const noexcept;
  42. BufferArray(priv::Link&& link);
  43. friend class binom::Variable;
  44. friend class binom::KeyValue;
  45. public:
  46. typedef GenericValueIterator Iterator;
  47. typedef ReverseGenericValueIterator ReverseIterator;
  48. typedef const Iterator ConstIterator;
  49. typedef const ReverseIterator ConstReverseIterator;
  50. typedef GenericValueRef ValueRef;
  51. BufferArray() noexcept;
  52. template<typename CharT>
  53. requires extended_type_traits::is_char_v<CharT>
  54. BufferArray(const std::basic_string_view<CharT> string_view) : Variable(string_view) {}
  55. template<typename CharT>
  56. requires extended_type_traits::is_char_v<CharT>
  57. BufferArray(const CharT* c_str) : Variable(std::basic_string_view<CharT>(c_str)) {}
  58. template<typename T>
  59. requires std::is_arithmetic_v<T>
  60. BufferArray(const std::initializer_list<T> init_list) noexcept : Variable(init_list) {}
  61. BufferArray(const BufferArray& other) noexcept;
  62. BufferArray(const BufferArray&& other) noexcept;
  63. BufferArray move() noexcept;
  64. const BufferArray move() const noexcept;
  65. size_t getElementCount() const noexcept;
  66. size_t getSize() const noexcept;
  67. size_t getCapacity() const noexcept;
  68. bool isPrintable() const noexcept;
  69. bool isPrintable(std::locale loc) const noexcept;
  70. ValueRef operator[](size_t index) noexcept;
  71. const ValueRef operator[](size_t index) const noexcept;
  72. template<typename T>
  73. requires extended_type_traits::is_crtp_base_of_v<arithmetic::ArithmeticTypeBase, T> || extended_type_traits::is_arithmetic_without_cvref_v<T>
  74. ValueRef pushBack(T value) noexcept {
  75. if(auto lk = getLock(MtxLockType::unique_locked); lk)
  76. return priv::BufferArrayImplementation::pushBack(getData(), getValType(), value);
  77. else return ValueRef(ValType::invalid_type, nullptr);
  78. }
  79. template<typename T>
  80. requires extended_type_traits::is_crtp_base_of_v<arithmetic::ArithmeticTypeBase, T> || extended_type_traits::is_arithmetic_without_cvref_v<T>
  81. Iterator pushBack(const std::initializer_list<T> value_list) {
  82. if(auto lk = getLock(MtxLockType::unique_locked); lk)
  83. return priv::BufferArrayImplementation::pushBack(getData(), getValType(), value_list);
  84. else return Iterator(ValType::invalid_type, nullptr);
  85. }
  86. template<typename T>
  87. requires extended_type_traits::is_crtp_base_of_v<arithmetic::ArithmeticTypeBase, T> || extended_type_traits::is_arithmetic_without_cvref_v<T>
  88. ValueRef pushFront(T value) noexcept {return insert<T>(0, value);}
  89. template<typename T>
  90. requires extended_type_traits::is_crtp_base_of_v<arithmetic::ArithmeticTypeBase, T> || extended_type_traits::is_arithmetic_without_cvref_v<T>
  91. Iterator pushFront(std::initializer_list<T> value_list) {return insert<T>(0, value_list);}
  92. template<typename T>
  93. requires extended_type_traits::is_crtp_base_of_v<arithmetic::ArithmeticTypeBase, T> || extended_type_traits::is_arithmetic_without_cvref_v<T>
  94. ValueRef insert(size_t at, T value) noexcept {
  95. if(auto lk = getLock(MtxLockType::unique_locked); lk)
  96. return priv::BufferArrayImplementation::insert(getData(), getBitWidth(), at, 1, value);
  97. else return ValueRef(ValType::invalid_type, nullptr);
  98. }
  99. template<typename T>
  100. requires extended_type_traits::is_crtp_base_of_v<arithmetic::ArithmeticTypeBase, T> || extended_type_traits::is_arithmetic_without_cvref_v<T>
  101. Iterator insert(size_t at, std::initializer_list<T> value_list) {
  102. if(auto lk = getLock(MtxLockType::unique_locked); lk)
  103. return priv::BufferArrayImplementation::insert(getData(), getBitWidth(), at, 1, value_list);
  104. else return Iterator(ValType::invalid_type, nullptr);
  105. }
  106. void remove(size_t at, size_t count = 1);
  107. void popBack(size_t count = 1);
  108. void popFront(size_t count = 1);
  109. void clear();
  110. Iterator begin();
  111. Iterator end();
  112. const Iterator cbegin() const;
  113. const Iterator cend() const;
  114. ReverseIterator rbegin();
  115. ReverseIterator rend();
  116. inline ConstIterator begin() const noexcept {return cbegin();}
  117. inline ConstIterator end() const noexcept {return cend();}
  118. inline ConstReverseIterator rbegin() const noexcept {return crbegin();}
  119. inline ConstReverseIterator rend() const noexcept {return crend();}
  120. const ReverseIterator crbegin() const;
  121. const ReverseIterator crend() const;
  122. template<typename CharT>
  123. requires extended_type_traits::is_char_v<CharT>
  124. operator std::basic_string<CharT>() const;
  125. BufferArray& operator=(const BufferArray& other);
  126. BufferArray& operator=(BufferArray&& other);
  127. BufferArray& changeLink(const BufferArray& other);
  128. BufferArray& changeLink(BufferArray&& other);
  129. };
  130. }
  131. #endif // BUFFER_ARRAY_HXX