PMDK C++ bindings
1.7
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.h>
58 namespace experimental
77 template <
typename T, std::
size_t N>
80 template <
typename Y, std::
size_t M>
81 struct standard_array_traits {
87 struct standard_array_traits<Y, 0> {
88 struct _alignment_struct {
92 struct alignas(_alignment_struct) type {
93 char _data[
sizeof(_alignment_struct)];
99 using pointer = value_type *;
100 using const_pointer =
const value_type *;
101 using reference = value_type &;
102 using const_reference =
const value_type &;
104 using const_iterator = const_pointer;
105 using size_type = std::size_t;
106 using difference_type = std::ptrdiff_t;
107 using reverse_iterator = std::reverse_iterator<iterator>;
108 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
111 typename standard_array_traits<T, N>::type _data;
151 detail::conditional_add_to_tx(
this);
181 detail::conditional_add_to_tx(
this);
182 std::copy(other.cbegin(), other.cend(),
_get_data());
199 throw std::out_of_range(
"array::at");
201 detail::conditional_add_to_tx(
_get_data() + n);
212 at(size_type n)
const
215 throw std::out_of_range(
"array::at");
229 throw std::out_of_range(
"array::const_at");
243 detail::conditional_add_to_tx(
_get_data() + n);
267 detail::conditional_add_to_tx(
this);
376 const_reverse_iterator
379 return const_reverse_iterator(
cend());
385 const_reverse_iterator
388 return const_reverse_iterator(
cend());
394 const_reverse_iterator
397 return const_reverse_iterator(
cbegin());
403 const_reverse_iterator
406 return const_reverse_iterator(
cbegin());
418 detail::conditional_add_to_tx(
_get_data());
486 throw std::out_of_range(
"array::range");
488 detail::conditional_add_to_tx(
_get_data() + start, n);
510 range(size_type start, size_type n, size_type snapshot_size)
513 throw std::out_of_range(
"array::range");
515 if (snapshot_size > n)
538 range(size_type start, size_type n)
const
541 throw std::out_of_range(
"array::range");
543 return {const_iterator(
_get_data() + start),
544 const_iterator(
_get_data() + start + n)};
559 crange(size_type start, size_type n)
const
562 throw std::out_of_range(
"array::crange");
564 return {const_iterator(
_get_data() + start),
565 const_iterator(
_get_data() + start + n)};
608 detail::conditional_add_to_tx(
this);
620 template <std::
size_t Size = N>
621 typename std::enable_if<Size != 0>::type
634 detail::conditional_add_to_tx(
this);
635 detail::conditional_add_to_tx(&other);
645 template <std::
size_t Size = N>
646 typename std::enable_if<Size == 0>::type
649 static_assert(!std::is_const<T>::value,
650 "cannot swap zero-sized array of type 'const T'");
657 template <std::
size_t Size = N>
658 typename std::enable_if<Size != 0, T *>::type
667 template <std::
size_t Size = N>
668 typename std::enable_if<Size != 0, const T *>::type
678 template <std::
size_t Size = N>
679 typename std::enable_if<Size == 0, T *>::type
682 return reinterpret_cast<T *
>(&this->_data);
688 template <std::
size_t Size = N>
689 typename std::enable_if<Size == 0, const T *>::type
692 return reinterpret_cast<const T *
>(&this->_data);
703 auto pop = pmemobj_pool_by_ptr(
this);
705 throw pool_error(
"Object outside of pmemobj pool.");
714 template <
typename T, std::
size_t N>
724 template <
typename T, std::
size_t N>
728 return !(lhs == rhs);
734 template <
typename T, std::
size_t N>
738 return std::lexicographical_compare(lhs.
cbegin(), lhs.
cend(),
745 template <
typename T, std::
size_t N>
755 template <
typename T, std::
size_t N>
765 template <
typename T, std::
size_t N>
775 template <
typename T, std::
size_t N>
776 typename pmem::obj::experimental::array<T, N>::const_iterator
785 template <
typename T, std::
size_t N>
786 typename pmem::obj::experimental::array<T, N>::const_iterator
795 template <
typename T, std::
size_t N>
796 typename pmem::obj::experimental::array<T, N>::const_reverse_iterator
805 template <
typename T, std::
size_t N>
806 typename pmem::obj::experimental::array<T, N>::const_reverse_iterator
815 template <
typename T, std::
size_t N>
825 template <
typename T, std::
size_t N>
826 typename pmem::obj::experimental::array<T, N>::const_iterator
835 template <
typename T, std::
size_t N>
845 template <
typename T, std::
size_t N>
846 typename pmem::obj::experimental::array<T, N>::const_iterator
855 template <
typename T, std::
size_t N>
856 typename pmem::obj::experimental::array<T, N>::reverse_iterator
865 template <
typename T, std::
size_t N>
866 typename pmem::obj::experimental::array<T, N>::const_reverse_iterator
875 template <
typename T, std::
size_t N>
876 typename pmem::obj::experimental::array<T, N>::reverse_iterator
885 template <
typename T, std::
size_t N>
886 typename pmem::obj::experimental::array<T, N>::const_reverse_iterator
895 template <
typename T,
size_t N>
906 template <
size_t I,
typename T,
size_t N>
911 "Index out of bounds in std::get<> (pmem::obj::array)");
918 template <
size_t I,
typename T,
size_t N>
923 "Index out of bounds in std::get<> (pmem::obj::array)");
924 return std::move(a.at(I));
930 template <
size_t I,
typename T,
size_t N>
935 "Index out of bounds in std::get<> (pmem::obj::array)");
942 template <
size_t I,
typename T,
size_t N>
947 "Index out of bounds in std::get<> (pmem::obj::array)");
948 return std::move(a.at(I));
array(array &&)=default
Defaulted move constructor.
std::enable_if< Size !=0 >::type swap(array &other)
Swaps content with other array's content inside internal transaction.
Definition: array.hpp:622
reference operator[](size_type n)
Access element at specific index and add it to a transaction.
Definition: array.hpp:241
iterator end()
Returns an iterator to the end.
Definition: array.hpp:308
T * data()
Returns raw pointer to the underlying data and adds entire array to a transaction.
Definition: array.hpp:265
T & get(pmem::obj::experimental::array< T, N > &a)
Non-member get function.
Definition: array.hpp:908
std::enable_if< Size==0 >::type swap(array &other)
Swap for zero-sized array.
Definition: array.hpp:647
array & operator=(array &&other)
Move assignment operator - perform move assignment from other pmem::obj::experimental::array.
Definition: array.hpp:169
array()=default
Defaulted constructor.
Custom pool error class.
Definition: pexceptions.hpp:53
const_iterator cend() const noexcept
Returns a const iterator to the end.
Definition: array.hpp:344
slice< const_iterator > crange(size_type start, size_type n) const
Returns const slice.
Definition: array.hpp:559
const_reference cback() const
Access the last element.
Definition: array.hpp:466
const_reference cfront() const
Access the first element.
Definition: array.hpp:448
void fill(const_reference value)
Fills array with specified value inside internal transaction.
Definition: array.hpp:603
Commonly used functionality.
constexpr bool empty() const noexcept
Checks whether array is empty.
Definition: array.hpp:590
const_reference operator[](size_type n) const
Access element at specific index.
Definition: array.hpp:252
constexpr size_type size() const noexcept
Returns size of the array.
Definition: array.hpp:572
iterator begin()
Returns an iterator to the beginning.
Definition: array.hpp:296
constexpr size_type max_size() const noexcept
Returns the maximum size of the array.
Definition: array.hpp:581
array(const array &)=default
Defaulted copy constructor.
pool_base _get_pool() const
Check whether object is on pmem and return pool_base instance.
Definition: array.hpp:701
const_reverse_iterator rbegin() const noexcept
Returns a const reverse iterator to the beginning.
Definition: array.hpp:377
const_reference back() const
Access the last element.
Definition: array.hpp:457
const T * data() const noexcept
Returns const raw pointer to the underlying data.
Definition: array.hpp:275
reverse_iterator rbegin()
Returns a reverse iterator to the beginning.
Definition: array.hpp:356
slice< const_iterator > range(size_type start, size_type n) const
Returns const slice.
Definition: array.hpp:538
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:516
const_reverse_iterator rend() const noexcept
Returns a const reverse iterator to the end.
Definition: array.hpp:395
pmem::obj::experimental::slice - provides interface to access sequence of objects.
Definition: slice.hpp:59
const T * cdata() const noexcept
Returns const raw pointer to the underlying data.
Definition: array.hpp:284
Iterface 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:398
const_iterator begin() const noexcept
Returns const iterator to the beginning.
Definition: array.hpp:317
std::enable_if< Size !=0, const T * >::type _get_data() const
Support for non-zero sized array.
Definition: array.hpp:669
const_iterator end() const noexcept
Returns a const iterator to the end.
Definition: array.hpp:335
std::enable_if< Size==0, T * >::type _get_data()
Support for zero sized array.
Definition: array.hpp:680
reverse_iterator rend()
Returns a reverse iterator to the end.
Definition: array.hpp:368
slice< range_snapshotting_iterator< T > > range(size_type start, size_type n, size_type snapshot_size)
Returns slice.
Definition: array.hpp:510
Iterators for pmem::obj::array.
C++ pmemobj transactions.
const_reference at(size_type n) const
Access element at specific index.
Definition: array.hpp:212
const_reference front() const
Access the first element.
Definition: array.hpp:439
bool operator>(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member greater than operator.
Definition: array.hpp:747
array & operator=(const array &other)
Copy assignment operator - perform assignment from other pmem::obj::experimental::array.
Definition: array.hpp:139
reference at(size_type n)
Access element at specific index and add it to a transaction.
Definition: array.hpp:196
Non-const iterator which adds elements to a transaction in a bulk.
Definition: contiguous_iterator.hpp:224
std::enable_if< Size !=0, T * >::type _get_data()
Support for non-zero sized array.
Definition: array.hpp:659
const_reverse_iterator crbegin() const noexcept
Returns a const reverse iterator to the beginning.
Definition: array.hpp:386
bool operator<(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member less than operator.
Definition: array.hpp:736
reference back()
Access the last element and add this element to a transaction.
Definition: array.hpp:429
const_iterator cbegin() const noexcept
Returns const iterator to the beginning.
Definition: array.hpp:326
const_reference const_at(size_type n) const
Access element at specific index.
Definition: array.hpp:226
std::enable_if< Size==0, const T * >::type _get_data() const
Support for zero sized array.
Definition: array.hpp:690
Convenience extensions for the resides on pmem property template.
slice< pointer > range(size_type start, size_type n)
Returns slice and snapshots requested range.
Definition: array.hpp:483
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:400
pmem::obj::experimental::array - EXPERIMENTAL persistent container with std::array compatible interfa...
Definition: array.hpp:78
bool operator<=(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member less or equal operator.
Definition: array.hpp:767
reference front()
Access the first element and add this element to a transaction.
Definition: array.hpp:416
The non-template pool base class.
Definition: pool.hpp:67
const_reverse_iterator crend() const noexcept
Returns a const reverse iterator to the beginning.
Definition: array.hpp:404
bool operator>=(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member greater or equal operator.
Definition: array.hpp:757
Persistent smart pointer.
Default non-const iterator which adds element to a transaction on every access.
Definition: contiguous_iterator.hpp:361