PMDK C++ bindings
1.10
This is the C++ bindings documentation for PMDK's libpmemobj.
|
Go to the documentation of this file.
9 #ifndef LIBPMEMOBJ_CPP_ARRAY_HPP
10 #define LIBPMEMOBJ_CPP_ARRAY_HPP
21 #include <libpmemobj/base.h>
44 template <
typename T, std::
size_t N>
47 template <
typename Y, std::
size_t M>
48 struct standard_array_traits {
54 struct standard_array_traits<Y, 0> {
55 struct _alignment_struct {
59 struct alignas(_alignment_struct) type {
60 char _data[
sizeof(_alignment_struct)];
66 using pointer = value_type *;
67 using const_pointer =
const value_type *;
68 using reference = value_type &;
69 using const_reference =
const value_type &;
71 using const_iterator = const_pointer;
72 using size_type = std::size_t;
73 using difference_type = std::ptrdiff_t;
74 using reverse_iterator = std::reverse_iterator<iterator>;
75 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
80 typename standard_array_traits<T, N>::type _data;
123 detail::conditional_add_to_tx(
124 this, 1, POBJ_XADD_ASSUME_INITIALIZED);
154 detail::conditional_add_to_tx(
155 this, 1, POBJ_XADD_ASSUME_INITIALIZED);
156 detail::conditional_add_to_tx(
157 &other, 1, POBJ_XADD_ASSUME_INITIALIZED);
158 std::move(other._get_data(), other._get_data() +
size(),
176 throw std::out_of_range(
"array::at");
178 detail::conditional_add_to_tx(
_get_data() + n, 1,
179 POBJ_XADD_ASSUME_INITIALIZED);
190 at(size_type n)
const
193 throw std::out_of_range(
"array::at");
207 throw std::out_of_range(
"array::const_at");
221 detail::conditional_add_to_tx(
_get_data() + n, 1,
222 POBJ_XADD_ASSUME_INITIALIZED);
246 detail::conditional_add_to_tx(
this, 1,
247 POBJ_XADD_ASSUME_INITIALIZED);
356 const_reverse_iterator
359 return const_reverse_iterator(
cend());
365 const_reverse_iterator
368 return const_reverse_iterator(
cend());
374 const_reverse_iterator
377 return const_reverse_iterator(
cbegin());
383 const_reverse_iterator
386 return const_reverse_iterator(
cbegin());
398 detail::conditional_add_to_tx(
_get_data(), 1,
399 POBJ_XADD_ASSUME_INITIALIZED);
413 POBJ_XADD_ASSUME_INITIALIZED);
468 throw std::out_of_range(
"array::range");
470 detail::conditional_add_to_tx(
_get_data() + start, n,
471 POBJ_XADD_ASSUME_INITIALIZED);
493 range(size_type start, size_type n, size_type snapshot_size)
496 throw std::out_of_range(
"array::range");
498 if (snapshot_size > n)
521 range(size_type start, size_type n)
const
524 throw std::out_of_range(
"array::range");
526 return {const_iterator(
_get_data() + start),
527 const_iterator(
_get_data() + start + n)};
542 crange(size_type start, size_type n)
const
545 throw std::out_of_range(
"array::crange");
547 return {const_iterator(
_get_data() + start),
548 const_iterator(
_get_data() + start + n)};
591 detail::conditional_add_to_tx(
592 this, 1, POBJ_XADD_ASSUME_INITIALIZED);
604 template <std::
size_t Size = N>
605 typename std::enable_if<Size != 0>::type
618 detail::conditional_add_to_tx(
619 this, 1, POBJ_XADD_ASSUME_INITIALIZED);
620 detail::conditional_add_to_tx(
621 &other, 1, POBJ_XADD_ASSUME_INITIALIZED);
631 template <std::
size_t Size = N>
632 typename std::enable_if<Size == 0>::type
635 static_assert(!std::is_const<T>::value,
636 "cannot swap zero-sized array of type 'const T'");
643 template <std::
size_t Size = N>
644 typename std::enable_if<Size != 0, T *>::type
653 template <std::
size_t Size = N>
654 typename std::enable_if<Size != 0, const T *>::type
664 template <std::
size_t Size = N>
665 typename std::enable_if<Size == 0, T *>::type
668 return reinterpret_cast<T *
>(&this->_data);
674 template <std::
size_t Size = N>
675 typename std::enable_if<Size == 0, const T *>::type
678 return reinterpret_cast<const T *
>(&this->_data);
689 auto pop = pmemobj_pool_by_ptr(
this);
692 "Object outside of pmemobj pool.");
701 template <
typename T, std::
size_t N>
711 template <
typename T, std::
size_t N>
715 return !(lhs == rhs);
721 template <
typename T, std::
size_t N>
725 return std::lexicographical_compare(lhs.
cbegin(), lhs.
cend(),
732 template <
typename T, std::
size_t N>
742 template <
typename T, std::
size_t N>
752 template <
typename T, std::
size_t N>
762 template <
typename T, std::
size_t N>
763 typename pmem::obj::array<T, N>::const_iterator
772 template <
typename T, std::
size_t N>
773 typename pmem::obj::array<T, N>::const_iterator
782 template <
typename T, std::
size_t N>
783 typename pmem::obj::array<T, N>::const_reverse_iterator
792 template <
typename T, std::
size_t N>
793 typename pmem::obj::array<T, N>::const_reverse_iterator
802 template <
typename T, std::
size_t N>
812 template <
typename T, std::
size_t N>
813 typename pmem::obj::array<T, N>::const_iterator
822 template <
typename T, std::
size_t N>
832 template <
typename T, std::
size_t N>
833 typename pmem::obj::array<T, N>::const_iterator
842 template <
typename T, std::
size_t N>
843 typename pmem::obj::array<T, N>::reverse_iterator
852 template <
typename T, std::
size_t N>
853 typename pmem::obj::array<T, N>::const_reverse_iterator
862 template <
typename T, std::
size_t N>
863 typename pmem::obj::array<T, N>::reverse_iterator
872 template <
typename T, std::
size_t N>
873 typename pmem::obj::array<T, N>::const_reverse_iterator
882 template <
typename T,
size_t N>
892 template <
size_t I,
typename T,
size_t N>
897 "Index out of bounds in std::get<> (pmem::obj::array)");
904 template <
size_t I,
typename T,
size_t N>
909 "Index out of bounds in std::get<> (pmem::obj::array)");
910 return std::move(a.at(I));
916 template <
size_t I,
typename T,
size_t N>
921 "Index out of bounds in std::get<> (pmem::obj::array)");
928 template <
size_t I,
typename T,
size_t N>
933 "Index out of bounds in std::get<> (pmem::obj::array)");
934 return std::move(a.at(I));
const_reverse_iterator rbegin() const noexcept
Returns a const reverse iterator to the beginning.
Definition: array.hpp:357
const_reference operator[](size_type n) const
Access element at specific index.
Definition: array.hpp:231
constexpr size_type max_size() const noexcept
Returns the maximum size of the array.
Definition: array.hpp:564
const_reference back() const
Access the last element.
Definition: array.hpp:439
slice< const_iterator > range(size_type start, size_type n) const
Returns const slice.
Definition: array.hpp:521
reference operator[](size_type n)
Access element at specific index and add it to a transaction.
Definition: array.hpp:219
array(array &&)=default
Defaulted move constructor.
Custom pool error class.
Definition: pexceptions.hpp:45
reference back()
Access the last element and add this element to a transaction.
Definition: array.hpp:410
Persistent memory namespace.
Definition: allocation_flag.hpp:15
slice< range_snapshotting_iterator > range(size_type start, size_type n, size_type snapshot_size)
Returns slice.
Definition: array.hpp:493
const T * cdata() const noexcept
Returns const raw pointer to the underlying data.
Definition: array.hpp:264
Commonly used functionality.
const_iterator cbegin() const noexcept
Returns const iterator to the beginning.
Definition: array.hpp:306
bool operator>(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member greater than operator.
Definition: array.hpp:734
const_reverse_iterator crbegin() const noexcept
Returns a const reverse iterator to the beginning.
Definition: array.hpp:366
const_iterator begin() const noexcept
Returns const iterator to the beginning.
Definition: array.hpp:297
std::enable_if< Size==0, T * >::type _get_data()
Support for zero sized array.
Definition: array.hpp:666
bool operator>=(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member greater or equal operator.
Definition: array.hpp:744
void fill(const_reference value)
Fills array with specified value inside internal transaction.
Definition: array.hpp:586
pool_base _get_pool() const
Check whether object is on pmem and return pool_base instance.
Definition: array.hpp:687
bool operator==(standard_alloc_policy< T > const &, standard_alloc_policy< T2 > const &)
Determines if memory from another allocator can be deallocated from this one.
Definition: allocator.hpp:406
std::enable_if< Size !=0, T * >::type _get_data()
Support for non-zero sized array.
Definition: array.hpp:645
const_iterator cend() const noexcept
Returns a const iterator to the end.
Definition: array.hpp:324
array & operator=(const array &other)
Copy assignment operator - perform assignment from other pmem::obj::array.
Definition: array.hpp:111
Interface to access sequence of objects.
static void run(pool_base &pool, std::function< void()> tx, Locks &... locks)
Execute a closure-like transaction and lock locks.
Definition: transaction.hpp:393
const_reference at(size_type n) const
Access element at specific index.
Definition: array.hpp:190
const_reference cfront() const
Access the first element.
Definition: array.hpp:430
Default non-const iterator which adds element to a transaction on every access.
Definition: contiguous_iterator.hpp:331
bool operator!=(const allocator< T, P, Tr > &lhs, const OtherAllocator &rhs)
Determines if memory from another allocator can be deallocated from this one.
Definition: allocator.hpp:522
const T * data() const noexcept
Returns const raw pointer to the underlying data.
Definition: array.hpp:255
std::enable_if< Size !=0 >::type swap(array &other)
Swaps content with other array's content inside internal transaction.
Definition: array.hpp:606
Iterators for contiguous persistent containers.
C++ pmemobj transactions.
iterator begin()
Returns an iterator to the beginning.
Definition: array.hpp:276
T * data()
Returns raw pointer to the underlying data and adds entire array to a transaction.
Definition: array.hpp:244
array & operator=(array &&other)
Move assignment operator - perform move assignment from other pmem::obj::array.
Definition: array.hpp:142
const_reference front() const
Access the first element.
Definition: array.hpp:421
bool operator<(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member less than operator.
Definition: array.hpp:723
constexpr bool empty() const noexcept
Checks whether array is empty.
Definition: array.hpp:573
reverse_iterator rbegin()
Returns a reverse iterator to the beginning.
Definition: array.hpp:336
reference at(size_type n)
Access element at specific index and add it to a transaction.
Definition: array.hpp:173
T & get(pmem::obj::array< T, N > &a)
Non-member get function.
Definition: array.hpp:894
const_reverse_iterator crend() const noexcept
Returns a const reverse iterator to the beginning.
Definition: array.hpp:384
pmem::obj::slice - provides interface to access sequence of objects.
Definition: slice.hpp:27
const_reference const_at(size_type n) const
Access element at specific index.
Definition: array.hpp:204
const_reference cback() const
Access the last element.
Definition: array.hpp:448
bool operator<=(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member less or equal operator.
Definition: array.hpp:754
const_iterator end() const noexcept
Returns a const iterator to the end.
Definition: array.hpp:315
pmem::obj::array - persistent container with std::array compatible interface.
Definition: array.hpp:45
Convenience extensions for the resides on pmem property template.
array()=default
Defaulted constructor.
slice< pointer > range(size_type start, size_type n)
Returns slice and snapshots requested range.
Definition: array.hpp:465
Non-const iterator which adds elements to a transaction in a bulk.
Definition: contiguous_iterator.hpp:192
std::enable_if< Size !=0, const T * >::type _get_data() const
Support for non-zero sized array.
Definition: array.hpp:655
slice< const_iterator > crange(size_type start, size_type n) const
Returns const slice.
Definition: array.hpp:542
std::enable_if< Size==0, const T * >::type _get_data() const
Support for zero sized array.
Definition: array.hpp:676
const_reverse_iterator rend() const noexcept
Returns a const reverse iterator to the end.
Definition: array.hpp:375
The non-template pool base class.
Definition: pool.hpp:46
reverse_iterator rend()
Returns a reverse iterator to the end.
Definition: array.hpp:348
array(const array &)=default
Defaulted copy constructor.
Persistent smart pointer.
reference front()
Access the first element and add this element to a transaction.
Definition: array.hpp:396
iterator end()
Returns an iterator to the end.
Definition: array.hpp:288
std::enable_if< Size==0 >::type swap(array &other)
Swap for zero-sized array.
Definition: array.hpp:633
constexpr size_type size() const noexcept
Returns size of the array.
Definition: array.hpp:555