PMDK C++ bindings
1.5.2
This is the C++ bindings documentation for PMDK's libpmemobj.
|
Go to the documentation of this file.
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<Iterator *
>(
this));
164 Iterator tmp(*
static_cast<Iterator *
>(
this));
172 friend std::ptrdiff_t
175 return lhs.ptr - rhs.ptr;
207 template <
typename T>
208 struct const_contiguous_iterator;
215 template <
typename T>
224 return lhs.get_ptr() == rhs.get_ptr();
234 return !(lhs == rhs);
244 return lhs.get_ptr() < rhs.get_ptr();
254 return lhs.get_ptr() > rhs.get_ptr();
293 template <
typename T>
297 using iterator_category = std::random_access_iterator_tag;
298 using value_type = T;
299 using difference_type = std::ptrdiff_t;
300 using reference = T &;
310 pointer data =
nullptr,
311 std::size_t size = 0,
312 std::size_t snapshot_size = 1)
316 snapshot_size(snapshot_size)
320 if (snapshot_size > 0)
331 detail::conditional_add_to_tx(&this->ptr[n]);
341 std::swap(lhs.ptr, rhs.ptr);
342 std::swap(lhs.data, rhs.data);
343 std::swap(lhs.size, rhs.size);
344 std::swap(lhs.snapshot_size, rhs.snapshot_size);
347 template <
typename Iterator,
typename Reference,
typename Po
inter>
352 change_by(std::ptrdiff_t n)
354 conditional_snapshot_range(this->ptr, n);
364 conditional_snapshot_range(pointer ptr, difference_type diff)
366 if (snapshot_size == 0)
369 auto new_ptr = ptr + diff;
372 if (new_ptr < data || new_ptr >= data + size)
376 if (
static_cast<std::size_t
>(ptr - data) / snapshot_size ==
377 static_cast<std::size_t
>(new_ptr - data) / snapshot_size)
380 snapshot_range(new_ptr);
384 snapshot_range(pointer ptr)
388 ptr -
static_cast<uint64_t
>(ptr - data) % snapshot_size;
389 auto range_size = snapshot_size;
391 if (range_begin + range_size > data + size)
392 range_size =
static_cast<uint64_t
>(data + size -
395 verify_range(range_begin, range_size);
398 detail::conditional_add_to_tx(range_begin, range_size);
403 verify_range(pointer range_begin, uint64_t range_size)
405 auto range_offset =
static_cast<uint64_t
>(range_begin - data);
407 assert(range_begin >= data);
408 assert(range_offset % snapshot_size == 0);
409 assert((range_offset + range_size) % snapshot_size == 0 ||
410 range_begin + range_size == data + size);
416 std::size_t snapshot_size;
423 template <
typename T>
427 using iterator_category = std::random_access_iterator_tag;
428 using value_type = T;
429 using difference_type = std::ptrdiff_t;
430 using reference = T &;
449 detail::conditional_add_to_tx(this->ptr);
459 detail::conditional_add_to_tx(this->ptr);
470 detail::conditional_add_to_tx(&this->ptr[n]);
480 std::swap(lhs.ptr, rhs.ptr);
487 template <
typename T>
492 using iterator_category = std::random_access_iterator_tag;
493 using value_type = T;
494 using difference_type = std::ptrdiff_t;
495 using reference =
const T &;
496 using pointer =
const T *;
529 std::swap(lhs.ptr, rhs.ptr);
friend bool operator!=(const const_contiguous_iterator< T > &lhs, const const_contiguous_iterator< T > &rhs)
Non-member not equal operator.
Definition: contiguous_iterator.hpp:231
This struct provides comparison operators between const_contiguous_iterator for specified type (as al...
Definition: contiguous_iterator.hpp:216
Iterator operator--(int)
Postfix decrement operator.
Definition: contiguous_iterator.hpp:120
Commonly used functionality.
friend bool operator<(const const_contiguous_iterator< T > &lhs, const const_contiguous_iterator< T > &rhs)
Non-member less than operator.
Definition: contiguous_iterator.hpp:241
const_contiguous_iterator(pointer ptr=nullptr)
Constructor taking pointer as argument.
Definition: contiguous_iterator.hpp:503
pmem::obj::experimental::array< T, N >::iterator begin(pmem::obj::experimental::array< T, N > &a)
Non-member begin.
Definition: array.hpp:691
friend std::ptrdiff_t operator-(const Iterator &lhs, const Iterator &rhs)
Subtraction operator overload Iterator type.
Definition: contiguous_iterator.hpp:173
friend bool operator>=(const const_contiguous_iterator< T > &lhs, const const_contiguous_iterator< T > &rhs)
Non-member greater or equal operator.
Definition: contiguous_iterator.hpp:271
Reference operator[](std::ptrdiff_t n)
Element access operator.
Definition: contiguous_iterator.hpp:181
Base class for iterators which satisfies RandomAccessIterator and operate on contiguous memory.
Definition: contiguous_iterator.hpp:61
const_contiguous_iterator(const range_snapshotting_iterator< T > &other)
Conversion operator from non-const iterator.
Definition: contiguous_iterator.hpp:518
basic_contiguous_iterator(pointer ptr=nullptr)
Constructor taking pointer and snapshotting function as arguments.
Definition: contiguous_iterator.hpp:439
Pointer operator->() const
Arrow operator.
Definition: contiguous_iterator.hpp:80
Reference operator*() const
Dereference operator.
Definition: contiguous_iterator.hpp:72
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:309
Iterator operator+(std::ptrdiff_t n)
Addition operator.
Definition: contiguous_iterator.hpp:151
void change_by(std::ptrdiff_t n)
Function for changing underlying pointer.
Definition: contiguous_iterator.hpp:199
friend void swap(const_contiguous_iterator &lhs, const_contiguous_iterator &rhs)
Non-member swap function.
Definition: contiguous_iterator.hpp:527
Iterator & operator-=(std::ptrdiff_t n)
Subtraction assignment operator.
Definition: contiguous_iterator.hpp:141
Const iterator.
Definition: contiguous_iterator.hpp:491
friend void swap(basic_contiguous_iterator &lhs, basic_contiguous_iterator &rhs)
Non-member swap function.
Definition: contiguous_iterator.hpp:478
constexpr contiguous_iterator(Pointer begin)
Constructor taking a pointer.
Definition: contiguous_iterator.hpp:65
reference operator*() const
Dereference operator which adds dereferenced element to a transaction.
Definition: contiguous_iterator.hpp:447
friend bool operator==(const const_contiguous_iterator< T > &lhs, const const_contiguous_iterator< T > &rhs)
Non-member equal operator.
Definition: contiguous_iterator.hpp:221
Non-const iterator which adds elements to a transaction in a bulk.
Definition: contiguous_iterator.hpp:296
friend void swap(range_snapshotting_iterator &lhs, range_snapshotting_iterator &rhs)
Non-member swap function.
Definition: contiguous_iterator.hpp:339
reference operator[](std::ptrdiff_t n)
Element access operator.
Definition: contiguous_iterator.hpp:329
friend bool operator<=(const const_contiguous_iterator< T > &lhs, const const_contiguous_iterator< T > &rhs)
Non-member less or equal operator.
Definition: contiguous_iterator.hpp:261
Iterator operator-(std::ptrdiff_t n)
Subtraction operator overload for integral type.
Definition: contiguous_iterator.hpp:162
Iterator & operator--()
Prefix decrement operator.
Definition: contiguous_iterator.hpp:110
pointer operator->() const
Arrow operator which adds underlying element to a transactions.
Definition: contiguous_iterator.hpp:457
const_contiguous_iterator(const basic_contiguous_iterator< T > &other)
Conversion operator from non-const iterator.
Definition: contiguous_iterator.hpp:510
Iterator & operator+=(std::ptrdiff_t n)
Addition assignment operator.
Definition: contiguous_iterator.hpp:131
reference operator[](std::ptrdiff_t n)
Element access operator.
Definition: contiguous_iterator.hpp:468
Iterator operator++(int)
Postfix increment operator.
Definition: contiguous_iterator.hpp:99
Default non-const iterator which adds element to a transaction on every access.
Definition: contiguous_iterator.hpp:426
Iterator & operator++()
Prefix increment operator.
Definition: contiguous_iterator.hpp:89
friend bool operator>(const const_contiguous_iterator< T > &lhs, const const_contiguous_iterator< T > &rhs)
Non-member greater than operator.
Definition: contiguous_iterator.hpp:251