PMDK C++ bindings
1.9.1
This is the C++ bindings documentation for PMDK's libpmemobj.
|
Go to the documentation of this file.
38 #ifndef LIBPMEMOBJ_CPP_ARRAY_HPP
39 #define LIBPMEMOBJ_CPP_ARRAY_HPP
50 #include <libpmemobj/base.h>
73 template <
typename T, std::
size_t N>
76 template <
typename Y, std::
size_t M>
77 struct standard_array_traits {
83 struct standard_array_traits<Y, 0> {
84 struct _alignment_struct {
88 struct alignas(_alignment_struct) type {
89 char _data[
sizeof(_alignment_struct)];
95 using pointer = value_type *;
96 using const_pointer =
const value_type *;
97 using reference = value_type &;
98 using const_reference =
const value_type &;
100 using const_iterator = const_pointer;
101 using size_type = std::size_t;
102 using difference_type = std::ptrdiff_t;
103 using reverse_iterator = std::reverse_iterator<iterator>;
104 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
109 typename standard_array_traits<T, N>::type _data;
152 detail::conditional_add_to_tx(
153 this, 1, POBJ_XADD_ASSUME_INITIALIZED);
183 detail::conditional_add_to_tx(
184 this, 1, POBJ_XADD_ASSUME_INITIALIZED);
185 detail::conditional_add_to_tx(
186 &other, 1, POBJ_XADD_ASSUME_INITIALIZED);
187 std::move(other._get_data(), other._get_data() +
size(),
205 throw std::out_of_range(
"array::at");
207 detail::conditional_add_to_tx(
_get_data() + n, 1,
208 POBJ_XADD_ASSUME_INITIALIZED);
219 at(size_type n)
const
222 throw std::out_of_range(
"array::at");
236 throw std::out_of_range(
"array::const_at");
250 detail::conditional_add_to_tx(
_get_data() + n, 1,
251 POBJ_XADD_ASSUME_INITIALIZED);
275 detail::conditional_add_to_tx(
this, 1,
276 POBJ_XADD_ASSUME_INITIALIZED);
385 const_reverse_iterator
388 return const_reverse_iterator(
cend());
394 const_reverse_iterator
397 return const_reverse_iterator(
cend());
403 const_reverse_iterator
406 return const_reverse_iterator(
cbegin());
412 const_reverse_iterator
415 return const_reverse_iterator(
cbegin());
427 detail::conditional_add_to_tx(
_get_data(), 1,
428 POBJ_XADD_ASSUME_INITIALIZED);
442 POBJ_XADD_ASSUME_INITIALIZED);
497 throw std::out_of_range(
"array::range");
499 detail::conditional_add_to_tx(
_get_data() + start, n,
500 POBJ_XADD_ASSUME_INITIALIZED);
522 range(size_type start, size_type n, size_type snapshot_size)
525 throw std::out_of_range(
"array::range");
527 if (snapshot_size > n)
550 range(size_type start, size_type n)
const
553 throw std::out_of_range(
"array::range");
555 return {const_iterator(
_get_data() + start),
556 const_iterator(
_get_data() + start + n)};
571 crange(size_type start, size_type n)
const
574 throw std::out_of_range(
"array::crange");
576 return {const_iterator(
_get_data() + start),
577 const_iterator(
_get_data() + start + n)};
620 detail::conditional_add_to_tx(
621 this, 1, POBJ_XADD_ASSUME_INITIALIZED);
633 template <std::
size_t Size = N>
634 typename std::enable_if<Size != 0>::type
647 detail::conditional_add_to_tx(
648 this, 1, POBJ_XADD_ASSUME_INITIALIZED);
649 detail::conditional_add_to_tx(
650 &other, 1, POBJ_XADD_ASSUME_INITIALIZED);
660 template <std::
size_t Size = N>
661 typename std::enable_if<Size == 0>::type
664 static_assert(!std::is_const<T>::value,
665 "cannot swap zero-sized array of type 'const T'");
672 template <std::
size_t Size = N>
673 typename std::enable_if<Size != 0, T *>::type
682 template <std::
size_t Size = N>
683 typename std::enable_if<Size != 0, const T *>::type
693 template <std::
size_t Size = N>
694 typename std::enable_if<Size == 0, T *>::type
697 return reinterpret_cast<T *
>(&this->_data);
703 template <std::
size_t Size = N>
704 typename std::enable_if<Size == 0, const T *>::type
707 return reinterpret_cast<const T *
>(&this->_data);
718 auto pop = pmemobj_pool_by_ptr(
this);
721 "Object outside of pmemobj pool.");
730 template <
typename T, std::
size_t N>
740 template <
typename T, std::
size_t N>
744 return !(lhs == rhs);
750 template <
typename T, std::
size_t N>
754 return std::lexicographical_compare(lhs.
cbegin(), lhs.
cend(),
761 template <
typename T, std::
size_t N>
771 template <
typename T, std::
size_t N>
781 template <
typename T, std::
size_t N>
791 template <
typename T, std::
size_t N>
792 typename pmem::obj::array<T, N>::const_iterator
801 template <
typename T, std::
size_t N>
802 typename pmem::obj::array<T, N>::const_iterator
811 template <
typename T, std::
size_t N>
812 typename pmem::obj::array<T, N>::const_reverse_iterator
821 template <
typename T, std::
size_t N>
822 typename pmem::obj::array<T, N>::const_reverse_iterator
831 template <
typename T, std::
size_t N>
841 template <
typename T, std::
size_t N>
842 typename pmem::obj::array<T, N>::const_iterator
851 template <
typename T, std::
size_t N>
861 template <
typename T, std::
size_t N>
862 typename pmem::obj::array<T, N>::const_iterator
871 template <
typename T, std::
size_t N>
872 typename pmem::obj::array<T, N>::reverse_iterator
881 template <
typename T, std::
size_t N>
882 typename pmem::obj::array<T, N>::const_reverse_iterator
891 template <
typename T, std::
size_t N>
892 typename pmem::obj::array<T, N>::reverse_iterator
901 template <
typename T, std::
size_t N>
902 typename pmem::obj::array<T, N>::const_reverse_iterator
911 template <
typename T,
size_t N>
921 template <
size_t I,
typename T,
size_t N>
926 "Index out of bounds in std::get<> (pmem::obj::array)");
933 template <
size_t I,
typename T,
size_t N>
938 "Index out of bounds in std::get<> (pmem::obj::array)");
939 return std::move(a.at(I));
945 template <
size_t I,
typename T,
size_t N>
950 "Index out of bounds in std::get<> (pmem::obj::array)");
957 template <
size_t I,
typename T,
size_t N>
962 "Index out of bounds in std::get<> (pmem::obj::array)");
963 return std::move(a.at(I));
const_reverse_iterator rbegin() const noexcept
Returns a const reverse iterator to the beginning.
Definition: array.hpp:386
const_reference operator[](size_type n) const
Access element at specific index.
Definition: array.hpp:260
constexpr size_type max_size() const noexcept
Returns the maximum size of the array.
Definition: array.hpp:593
const_reference back() const
Access the last element.
Definition: array.hpp:468
slice< const_iterator > range(size_type start, size_type n) const
Returns const slice.
Definition: array.hpp:550
reference operator[](size_type n)
Access element at specific index and add it to a transaction.
Definition: array.hpp:248
array(array &&)=default
Defaulted move constructor.
Custom pool error class.
Definition: pexceptions.hpp:76
reference back()
Access the last element and add this element to a transaction.
Definition: array.hpp:439
Persistent memory namespace.
Definition: allocation_flag.hpp:44
slice< range_snapshotting_iterator > range(size_type start, size_type n, size_type snapshot_size)
Returns slice.
Definition: array.hpp:522
const T * cdata() const noexcept
Returns const raw pointer to the underlying data.
Definition: array.hpp:293
Commonly used functionality.
const_iterator cbegin() const noexcept
Returns const iterator to the beginning.
Definition: array.hpp:335
bool operator>(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member greater than operator.
Definition: array.hpp:763
const_reverse_iterator crbegin() const noexcept
Returns a const reverse iterator to the beginning.
Definition: array.hpp:395
const_iterator begin() const noexcept
Returns const iterator to the beginning.
Definition: array.hpp:326
std::enable_if< Size==0, T * >::type _get_data()
Support for zero sized array.
Definition: array.hpp:695
bool operator>=(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member greater or equal operator.
Definition: array.hpp:773
void fill(const_reference value)
Fills array with specified value inside internal transaction.
Definition: array.hpp:615
pool_base _get_pool() const
Check whether object is on pmem and return pool_base instance.
Definition: array.hpp:716
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:402
std::enable_if< Size !=0, T * >::type _get_data()
Support for non-zero sized array.
Definition: array.hpp:674
const_iterator cend() const noexcept
Returns a const iterator to the end.
Definition: array.hpp:353
array & operator=(const array &other)
Copy assignment operator - perform assignment from other pmem::obj::array.
Definition: array.hpp:140
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:422
const_reference at(size_type n) const
Access element at specific index.
Definition: array.hpp:219
const_reference cfront() const
Access the first element.
Definition: array.hpp:459
Default non-const iterator which adds element to a transaction on every access.
Definition: contiguous_iterator.hpp:360
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:518
const T * data() const noexcept
Returns const raw pointer to the underlying data.
Definition: array.hpp:284
std::enable_if< Size !=0 >::type swap(array &other)
Swaps content with other array's content inside internal transaction.
Definition: array.hpp:635
Iterators for contiguous persistent containers.
C++ pmemobj transactions.
iterator begin()
Returns an iterator to the beginning.
Definition: array.hpp:305
T * data()
Returns raw pointer to the underlying data and adds entire array to a transaction.
Definition: array.hpp:273
array & operator=(array &&other)
Move assignment operator - perform move assignment from other pmem::obj::array.
Definition: array.hpp:171
const_reference front() const
Access the first element.
Definition: array.hpp:450
bool operator<(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member less than operator.
Definition: array.hpp:752
constexpr bool empty() const noexcept
Checks whether array is empty.
Definition: array.hpp:602
reverse_iterator rbegin()
Returns a reverse iterator to the beginning.
Definition: array.hpp:365
reference at(size_type n)
Access element at specific index and add it to a transaction.
Definition: array.hpp:202
T & get(pmem::obj::array< T, N > &a)
Non-member get function.
Definition: array.hpp:923
const_reverse_iterator crend() const noexcept
Returns a const reverse iterator to the beginning.
Definition: array.hpp:413
pmem::obj::slice - provides interface to access sequence of objects.
Definition: slice.hpp:56
const_reference const_at(size_type n) const
Access element at specific index.
Definition: array.hpp:233
const_reference cback() const
Access the last element.
Definition: array.hpp:477
bool operator<=(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member less or equal operator.
Definition: array.hpp:783
const_iterator end() const noexcept
Returns a const iterator to the end.
Definition: array.hpp:344
pmem::obj::array - persistent container with std::array compatible interface.
Definition: array.hpp:74
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:494
Non-const iterator which adds elements to a transaction in a bulk.
Definition: contiguous_iterator.hpp:221
std::enable_if< Size !=0, const T * >::type _get_data() const
Support for non-zero sized array.
Definition: array.hpp:684
slice< const_iterator > crange(size_type start, size_type n) const
Returns const slice.
Definition: array.hpp:571
std::enable_if< Size==0, const T * >::type _get_data() const
Support for zero sized array.
Definition: array.hpp:705
const_reverse_iterator rend() const noexcept
Returns a const reverse iterator to the end.
Definition: array.hpp:404
The non-template pool base class.
Definition: pool.hpp:75
reverse_iterator rend()
Returns a reverse iterator to the end.
Definition: array.hpp:377
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:425
iterator end()
Returns an iterator to the end.
Definition: array.hpp:317
std::enable_if< Size==0 >::type swap(array &other)
Swap for zero-sized array.
Definition: array.hpp:662
constexpr size_type size() const noexcept
Returns size of the array.
Definition: array.hpp:584