38 #ifndef LIBPMEMOBJ_CPP_ARRAY_ITERATOR_HPP 39 #define LIBPMEMOBJ_CPP_ARRAY_ITERATOR_HPP 53 namespace experimental
60 template <
typename Iterator,
typename Reference,
typename Po
inter>
91 static_cast<Iterator *>(
this)->change_by(1);
92 return *static_cast<Iterator *>(
this);
101 Iterator tmp(*static_cast<Iterator *>(
this));
102 static_cast<Iterator *>(
this)->change_by(1);
112 static_cast<Iterator *>(
this)->change_by(-1);
113 return *static_cast<Iterator *>(
this);
122 Iterator tmp(*static_cast<Iterator *>(
this));
123 static_cast<Iterator *>(
this)->change_by(-1);
133 static_cast<Iterator *>(
this)->change_by(n);
134 return *static_cast<Iterator *>(
this);
143 static_cast<Iterator *>(
this)->change_by(-n);
144 return *static_cast<Iterator *>(
this);
153 Iterator tmp(*static_cast<const Iterator *>(
this));
164 Iterator tmp(*static_cast<const Iterator *>(
this));
172 friend std::ptrdiff_t
175 return lhs.ptr - rhs.ptr;
222 template <
typename T>
225 using iterator_category = std::random_access_iterator_tag;
226 using value_type = T;
227 using difference_type = std::ptrdiff_t;
228 using reference = T &;
238 pointer data =
nullptr,
239 std::size_t size = 0,
240 std::size_t snapshot_size = 1)
244 snapshot_size(snapshot_size)
248 if (snapshot_size && ptr)
267 detail::conditional_add_to_tx(&this->ptr[n]);
277 std::swap(lhs.ptr, rhs.ptr);
278 std::swap(lhs.data, rhs.data);
279 std::swap(lhs.size, rhs.size);
280 std::swap(lhs.snapshot_size, rhs.snapshot_size);
283 template <
typename Iterator,
typename Reference,
typename Po
inter>
288 change_by(std::ptrdiff_t n)
290 conditional_snapshot_range(this->ptr, n);
300 conditional_snapshot_range(pointer ptr, difference_type diff)
302 if (snapshot_size == 0)
305 auto new_ptr = ptr + diff;
308 if (new_ptr < data || new_ptr >= data + size)
312 if (static_cast<std::size_t>(ptr - data) / snapshot_size ==
313 static_cast<std::size_t>(new_ptr - data) / snapshot_size)
316 snapshot_range(new_ptr);
320 snapshot_range(pointer ptr)
324 ptr - static_cast<uint64_t>(ptr - data) % snapshot_size;
325 auto range_size = snapshot_size;
327 if (range_begin + range_size > data + size)
328 range_size = static_cast<uint64_t>(data + size -
331 verify_range(range_begin, range_size);
334 detail::conditional_add_to_tx(range_begin, range_size);
339 verify_range(pointer range_begin, uint64_t range_size)
341 auto range_offset = static_cast<uint64_t>(range_begin - data);
343 assert(range_begin >= data);
344 assert(range_offset % snapshot_size == 0);
345 assert((range_offset + range_size) % snapshot_size == 0 ||
346 range_begin + range_size == data + size);
352 std::size_t snapshot_size;
359 template <
typename T>
362 using iterator_category = std::random_access_iterator_tag;
363 using value_type = T;
364 using difference_type = std::ptrdiff_t;
365 using reference = T &;
392 detail::conditional_add_to_tx(this->ptr);
402 detail::conditional_add_to_tx(this->ptr);
413 detail::conditional_add_to_tx(&this->ptr[n]);
423 std::swap(lhs.ptr, rhs.ptr);
Non-const iterator which adds elements to a transaction in a bulk.
Definition: contiguous_iterator.hpp:223
Iterator & operator+=(std::ptrdiff_t n)
Addition assignment operator.
Definition: contiguous_iterator.hpp:131
Default non-const iterator which adds element to a transaction on every access.
Definition: contiguous_iterator.hpp:360
reference operator *() const
Dereference operator which adds dereferenced element to a transaction.
Definition: contiguous_iterator.hpp:390
range_snapshotting_iterator(pointer ptr=nullptr, pointer data=nullptr, std::size_t size=0, std::size_t snapshot_size=1)
Constructor taking pointer to data, pointer to the beginning of the array and snapshot_size.
Definition: contiguous_iterator.hpp:237
pmem::obj::experimental::array< T, N >::iterator begin(pmem::obj::experimental::array< T, N > &a)
Non-member begin.
Definition: array.hpp:817
Iterator operator--(int)
Postfix decrement operator.
Definition: contiguous_iterator.hpp:120
friend void swap(range_snapshotting_iterator &lhs, range_snapshotting_iterator &rhs)
Non-member swap function.
Definition: contiguous_iterator.hpp:275
reference operator[](std::ptrdiff_t n)
Element access operator.
Definition: contiguous_iterator.hpp:411
Iterator & operator++()
Prefix increment operator.
Definition: contiguous_iterator.hpp:89
Reference operator[](std::ptrdiff_t n)
Element access operator.
Definition: contiguous_iterator.hpp:181
reference operator[](std::ptrdiff_t n)
Element access operator.
Definition: contiguous_iterator.hpp:265
friend std::ptrdiff_t operator-(const Iterator &lhs, const Iterator &rhs)
Subtraction operator overload Iterator type.
Definition: contiguous_iterator.hpp:173
void change_by(std::ptrdiff_t n)
Function for changing underlying pointer.
Definition: contiguous_iterator.hpp:199
Commonly used functionality.
friend void swap(basic_contiguous_iterator &lhs, basic_contiguous_iterator &rhs)
Non-member swap function.
Definition: contiguous_iterator.hpp:421
Iterator & operator-=(std::ptrdiff_t n)
Subtraction assignment operator.
Definition: contiguous_iterator.hpp:141
pointer operator->() const
Arrow operator which adds underlying element to a transactions.
Definition: contiguous_iterator.hpp:400
basic_contiguous_iterator(pointer ptr=nullptr)
Constructor taking pointer and snapshotting function as arguments.
Definition: contiguous_iterator.hpp:374
Pointer operator->() const
Arrow operator.
Definition: contiguous_iterator.hpp:80
Base class for iterators which satisfies RandomAccessIterator and operate on contiguous memory.
Definition: contiguous_iterator.hpp:61
constexpr contiguous_iterator(Pointer begin)
Constructor taking a pointer.
Definition: contiguous_iterator.hpp:65
Reference operator *() const
Dereference operator.
Definition: contiguous_iterator.hpp:72
Iterator & operator--()
Prefix decrement operator.
Definition: contiguous_iterator.hpp:110
Iterator operator+(std::ptrdiff_t n) const
Addition operator.
Definition: contiguous_iterator.hpp:151
Iterator operator++(int)
Postfix increment operator.
Definition: contiguous_iterator.hpp:99
Iterator operator-(std::ptrdiff_t n) const
Subtraction operator overload for integral type.
Definition: contiguous_iterator.hpp:162