PMDK C++ bindings
1.11.1
This is the C++ bindings documentation for PMDK's libpmemobj.
|
Go to the documentation of this file.
9 #ifndef LIBPMEMOBJ_CPP_CONTIGUOUS_ITERATOR_HPP
10 #define LIBPMEMOBJ_CPP_CONTIGUOUS_ITERATOR_HPP
28 template <
typename Iterator,
typename Reference,
typename Po
inter>
59 static_cast<Iterator *
>(
this)->
change_by(1);
60 return *
static_cast<Iterator *
>(
this);
69 Iterator tmp(*
static_cast<Iterator *
>(
this));
70 static_cast<Iterator *
>(
this)->
change_by(1);
80 static_cast<Iterator *
>(
this)->
change_by(-1);
81 return *
static_cast<Iterator *
>(
this);
90 Iterator tmp(*
static_cast<Iterator *
>(
this));
91 static_cast<Iterator *
>(
this)->
change_by(-1);
101 static_cast<Iterator *
>(
this)->
change_by(n);
102 return *
static_cast<Iterator *
>(
this);
111 static_cast<Iterator *
>(
this)->
change_by(-n);
112 return *
static_cast<Iterator *
>(
this);
121 Iterator tmp(*
static_cast<const Iterator *
>(
this));
132 Iterator tmp(*
static_cast<const Iterator *
>(
this));
140 friend std::ptrdiff_t
143 return lhs.ptr - rhs.ptr;
190 template <
typename T>
193 using iterator_category = std::random_access_iterator_tag;
194 using value_type = T;
195 using difference_type = std::ptrdiff_t;
196 using reference = T &;
206 pointer data =
nullptr,
207 std::size_t size = 0,
208 std::size_t snapshot_size = 1)
212 snapshot_size(snapshot_size)
216 if (snapshot_size && ptr)
223 operator const T *()
const
235 detail::conditional_add_to_tx(&this->ptr[n], 1,
236 POBJ_XADD_ASSUME_INITIALIZED);
249 std::swap(lhs.snapshot_size, rhs.snapshot_size);
252 template <
typename Iterator,
typename Reference,
typename Po
inter>
257 change_by(std::ptrdiff_t n)
259 conditional_snapshot_range(this->ptr, n);
269 conditional_snapshot_range(pointer ptr, difference_type diff)
271 if (snapshot_size == 0)
274 auto new_ptr = ptr + diff;
277 if (new_ptr < data || new_ptr >= data + size)
281 if (
static_cast<std::size_t
>(ptr - data) / snapshot_size ==
282 static_cast<std::size_t
>(new_ptr - data) / snapshot_size)
285 snapshot_range(new_ptr);
289 snapshot_range(pointer ptr)
293 ptr -
static_cast<uint64_t
>(ptr - data) % snapshot_size;
294 auto range_size = snapshot_size;
296 if (range_begin + range_size > data + size)
297 range_size =
static_cast<uint64_t
>(data + size -
300 verify_range(range_begin, range_size);
303 detail::conditional_add_to_tx(range_begin, range_size,
304 POBJ_XADD_ASSUME_INITIALIZED);
309 verify_range(pointer range_begin, uint64_t range_size)
311 auto range_offset =
static_cast<uint64_t
>(range_begin - data);
313 assert(range_begin >= data);
314 assert(range_offset % snapshot_size == 0);
315 assert((range_offset + range_size) % snapshot_size == 0 ||
316 range_begin + range_size == data + size);
322 std::size_t snapshot_size;
329 template <
typename T>
332 using iterator_category = std::random_access_iterator_tag;
333 using value_type = T;
334 using difference_type = std::ptrdiff_t;
335 using reference = T &;
351 operator const T *()
const
362 detail::conditional_add_to_tx(this->ptr, 1,
363 POBJ_XADD_ASSUME_INITIALIZED);
373 detail::conditional_add_to_tx(this->ptr, 1,
374 POBJ_XADD_ASSUME_INITIALIZED);
385 detail::conditional_add_to_tx(&this->ptr[n], 1,
386 POBJ_XADD_ASSUME_INITIALIZED);
basic_contiguous_iterator(pointer ptr=nullptr)
Constructor taking pointer and snapshotting function as arguments.
Definition: contiguous_iterator.hpp:344
Iterator operator++(int)
Postfix increment operator.
Definition: contiguous_iterator.hpp:67
Persistent memory namespace.
Definition: allocation_flag.hpp:15
Base class for iterators which satisfies RandomAccessIterator and operate on contiguous memory.
Definition: contiguous_iterator.hpp:29
pmem::obj::array< T, N >::iterator begin(pmem::obj::array< T, N > &a)
Non-member begin.
Definition: array.hpp:800
Pointer operator->() const
Arrow operator.
Definition: contiguous_iterator.hpp:48
Commonly used functionality.
Reference operator[](std::ptrdiff_t n)
Element access operator.
Definition: contiguous_iterator.hpp:149
Iterator operator--(int)
Postfix decrement operator.
Definition: contiguous_iterator.hpp:88
Iterator & operator++()
Prefix increment operator.
Definition: contiguous_iterator.hpp:57
constexpr contiguous_iterator(Pointer begin)
Constructor taking a pointer.
Definition: contiguous_iterator.hpp:33
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:205
Iterator operator+(std::ptrdiff_t n) const
Addition operator.
Definition: contiguous_iterator.hpp:119
void swap(pmem::obj::array< T, N > &lhs, pmem::obj::array< T, N > &rhs)
Non-member swap function.
Definition: array.hpp:880
Default non-const iterator which adds element to a transaction on every access.
Definition: contiguous_iterator.hpp:331
Reference operator*() const
Dereference operator.
Definition: contiguous_iterator.hpp:40
Iterator & operator+=(std::ptrdiff_t n)
Addition assignment operator.
Definition: contiguous_iterator.hpp:99
friend void swap(basic_contiguous_iterator &lhs, basic_contiguous_iterator &rhs)
Non-member swap function.
Definition: contiguous_iterator.hpp:394
Iterator & operator--()
Prefix decrement operator.
Definition: contiguous_iterator.hpp:78
Iterator & operator-=(std::ptrdiff_t n)
Subtraction assignment operator.
Definition: contiguous_iterator.hpp:109
friend std::ptrdiff_t operator-(const Iterator &lhs, const Iterator &rhs)
Subtraction operator overload Iterator type.
Definition: contiguous_iterator.hpp:141
pointer operator->() const
Arrow operator which adds underlying element to a transactions.
Definition: contiguous_iterator.hpp:371
reference operator[](std::ptrdiff_t n)
Element access operator.
Definition: contiguous_iterator.hpp:383
reference operator*() const
Dereference operator which adds dereferenced element to a transaction.
Definition: contiguous_iterator.hpp:360
Non-const iterator which adds elements to a transaction in a bulk.
Definition: contiguous_iterator.hpp:192
void change_by(std::ptrdiff_t n)
Function for changing underlying pointer.
Definition: contiguous_iterator.hpp:167
friend void swap(range_snapshotting_iterator &lhs, range_snapshotting_iterator &rhs)
Non-member swap function.
Definition: contiguous_iterator.hpp:244
Iterator operator-(std::ptrdiff_t n) const
Subtraction operator overload for integral type.
Definition: contiguous_iterator.hpp:130
reference operator[](std::ptrdiff_t n)
Element access operator.
Definition: contiguous_iterator.hpp:233