PMDK C++ bindings
1.6.1
This is the C++ bindings documentation for PMDK's libpmemobj.
|
Go to the documentation of this file.
38 #ifndef LIBPMEMOBJ_CPP_BASIC_STRING_HPP
39 #define LIBPMEMOBJ_CPP_BASIC_STRING_HPP
62 namespace experimental
71 template <
typename CharT,
typename Traits = std::
char_traits<CharT>>
75 using traits_type = Traits;
76 using value_type = CharT;
77 using size_type = std::size_t;
78 using difference_type = std::ptrdiff_t;
79 using reference = value_type &;
80 using const_reference =
const value_type &;
81 using pointer = value_type *;
82 using const_pointer =
const value_type *;
84 using const_iterator = const_pointer;
85 using reverse_iterator = std::reverse_iterator<iterator>;
86 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
89 static constexpr size_type sso_capacity = 64 -
sizeof(
'\0');
146 size_type count = npos)
150 if (pos > other.
size())
151 throw std::out_of_range(
"Index out of range.");
153 if (count == npos || pos + count > other.
size())
154 count = other.
size() - pos;
156 auto first =
static_cast<difference_type
>(pos);
157 auto last = first +
static_cast<difference_type
>(count);
201 auto length = traits_type::length(s);
224 typename Enable =
typename std::enable_if<
228 assert(std::distance(first, last) >= 0);
276 if (other.is_sso_used())
277 other.initialize(0U, value_type(
'\0'));
309 detail::destroy<non_sso_type>(data_large);
339 return assign(std::move(other));
443 if (pos > other.
size())
444 throw std::out_of_range(
"Index out of range.");
446 if (count == npos || pos + count > other.
size())
447 count = other.
size() - pos;
450 auto first =
static_cast<difference_type
>(pos);
451 auto last = first +
static_cast<difference_type
>(count);
493 auto length = traits_type::length(s);
511 template <
typename InputIt,
544 if (other.is_sso_used())
545 other.initialize(0U, value_type(
'\0'));
561 assign(std::initializer_list<CharT> ilist)
563 return assign(ilist.begin(), ilist.end());
597 return is_sso_used() ? const_iterator(&*data_sso.
cbegin())
598 : const_iterator(&*data_large.
cbegin());
609 return begin() +
static_cast<difference_type
>(
size());
621 return cbegin() +
static_cast<difference_type
>(
size());
633 return cbegin() +
static_cast<difference_type
>(
size());
645 return reverse_iterator(
end());
654 const_reverse_iterator
666 const_reverse_iterator
669 return const_reverse_iterator(
cend());
681 return reverse_iterator(
begin());
690 const_reverse_iterator
702 const_reverse_iterator
705 return const_reverse_iterator(
cbegin());
725 throw std::out_of_range(
"string::at");
727 return is_sso_used() ? data_sso[n] : data_large[n];
741 at(size_type n)
const
763 throw std::out_of_range(
"string::const_at");
766 ?
static_cast<const sso_type &
>(data_sso)[n]
783 return is_sso_used() ? data_sso[n] : data_large[n];
795 return is_sso_used() ? data_sso[n] : data_large[n];
850 return (*
this)[
size() - 1];
886 else if (data_large.
size() == 0)
889 return data_large.
size() -
sizeof(
'\0');
902 ? data_sso.
range(0,
size() +
sizeof(
'\0')).begin()
924 compare(size_type pos, size_type count1,
const CharT *s,
925 size_type count2)
const
928 throw std::out_of_range(
"Index out of range.");
930 if (count1 >
size() - pos)
931 count1 =
size() - pos;
933 auto ret = traits_type::compare(
934 cdata() + pos, s, std::min<size_type>(count1, count2));
941 else if (count1 == count2)
1000 size_type pos2, size_type count2 = npos)
const
1002 if (pos2 > other.
size())
1003 throw std::out_of_range(
"Index out of range.");
1005 if (count2 > other.
size() - pos2)
1006 count2 = other.
size() - pos2;
1008 return compare(pos1, count1, other.
cdata() + pos2, count2);
1022 return compare(0,
size(), s, traits_type::length(s));
1039 compare(size_type pos, size_type count,
const CharT *s)
const
1041 return compare(pos, count, s, traits_type::length(s));
1050 return is_sso_used() ? data_sso.
cdata() : data_large.
cdata();
1086 return PMEMOBJ_MAX_ALLOC_SIZE /
sizeof(CharT) - 1;
1096 return is_sso_used() ? sso_capacity
1097 : data_large.
capacity() -
sizeof(
'\0');
1110 static const size_type npos =
static_cast<size_type
>(-1);
1113 using sso_type =
array<value_type, sso_capacity +
sizeof(
'\0')>;
1124 non_sso_type data_large;
1134 assert(_size <= sso_capacity ||
1135 _size == std::numeric_limits<size_type>::max());
1137 return _size <= sso_capacity;
1143 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
1148 #if LIBPMEMOBJ_CPP_VG_MEMCHECK_ENABLED
1149 VALGRIND_MAKE_MEM_DEFINED(&data_sso,
sizeof(data_sso));
1152 if (is_sso_used()) {
1157 detail::destroy<decltype(data_large)>(data_large);
1169 typename Enable =
typename std::enable_if<
1174 return static_cast<size_type
>(std::distance(first, last));
1198 return other.
size();
1208 template <
typename... Args>
1212 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
1214 auto new_size =
get_size(std::forward<Args>(args)...);
1217 if (!is_sso_used() && new_size <=
capacity())
1222 return initialize(std::forward<Args>(args)...);
1235 template <
typename... Args>
1239 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
1241 auto new_size =
get_size(std::forward<Args>(args)...);
1243 if (new_size <= sso_capacity)
1246 _size = std::numeric_limits<size_type>::max();
1248 if (is_sso_used()) {
1255 detail::create<decltype(data_large)>(&data_large);
1265 typename Enable =
typename std::enable_if<
1270 auto size =
static_cast<size_type
>(std::distance(first, last));
1272 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
1273 assert(
size <= sso_capacity);
1275 auto dest = data_sso.
range(0,
size +
sizeof(
'\0')).begin();
1276 std::copy(first, last, dest);
1278 dest[
size] = value_type(
'\0');
1289 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
1290 assert(count <= sso_capacity);
1292 auto dest = data_sso.
range(0, count +
sizeof(
'\0')).begin();
1293 traits_type::assign(dest, count, ch);
1295 dest[count] = value_type(
'\0');
1306 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
1317 typename Enable =
typename std::enable_if<
1322 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
1324 auto size =
static_cast<size_type
>(std::distance(first, last));
1327 data_large.assign(first, last);
1330 return data_large.
data();
1340 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
1342 data_large.
reserve(count +
sizeof(
'\0'));
1343 data_large.assign(count, ch);
1346 return data_large.
data();
1356 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
1358 if (other.is_sso_used())
1361 data_large = std::move(other.data_large);
1363 return data_large.
data();
1372 auto pop = pmemobj_pool_by_ptr(
this);
1373 assert(pop !=
nullptr);
1384 if (pmemobj_pool_by_ptr(
this) ==
nullptr)
1394 if (pmemobj_tx_stage() != TX_STAGE_WORK)
1396 "Call made out of transaction scope.");
1414 template <
class CharT,
class Traits>
1425 template <
class CharT,
class Traits>
1436 template <
class CharT,
class Traits>
1447 template <
class CharT,
class Traits>
1458 template <
class CharT,
class Traits>
1469 template <
class CharT,
class Traits>
1480 template <
class CharT,
class Traits>
1490 template <
class CharT,
class Traits>
1500 template <
class CharT,
class Traits>
1510 template <
class CharT,
class Traits>
1520 template <
class CharT,
class Traits>
1530 template <
class CharT,
class Traits>
1540 template <
class CharT,
class Traits>
1550 template <
class CharT,
class Traits>
1560 template <
class CharT,
class Traits>
1570 template <
class CharT,
class Traits>
1580 template <
class CharT,
class Traits>
1590 template <
class CharT,
class Traits>
const_reverse_iterator rbegin() const noexcept
Return a const reverse iterator to the beginning.
Definition: basic_string.hpp:655
size_type size() const noexcept
Definition: vector.hpp:1347
size_type max_size() const noexcept
Definition: basic_string.hpp:1084
const_reference const_at(size_type n) const
Access element at specific index with bounds checking.
Definition: basic_string.hpp:760
void push_back(const T &value)
Appends the given element value to the end of the container transactionally.
Definition: vector.hpp:1886
void free_data()
Clears the content of a vector and frees all allocated persistent memory for data transactionally.
Definition: vector.hpp:1458
const_iterator cbegin() const noexcept
Returns const iterator to the beginning.
Definition: vector.hpp:1106
const_reverse_iterator rend() const noexcept
Return a const reverse iterator to the end.
Definition: basic_string.hpp:691
reverse_iterator rbegin()
Return a reverse iterator to the beginning.
Definition: basic_string.hpp:643
T * data()
Returns raw pointer to the underlying data and adds entire array to a transaction.
Definition: array.hpp:265
basic_string & assign(const CharT *s, size_type count)
Replace the contents with the first count elements of C-style string s transactionally.
Definition: basic_string.hpp:471
Vector container with std::vector compatible interface.
const_iterator end() const noexcept
Return const iterator to past the end.
Definition: basic_string.hpp:619
const_reverse_iterator crend() const noexcept
Return a const reverse iterator to the end.
Definition: basic_string.hpp:703
value_type * data()
Returns raw pointer to the underlying data and adds entire array to a transaction.
Definition: vector.hpp:1040
Custom pool error class.
Definition: pexceptions.hpp:53
Custom transaction error class.
Definition: pexceptions.hpp:63
const CharT * data() const noexcept
Definition: basic_string.hpp:1057
const CharT & front() const
Access first element.
Definition: basic_string.hpp:819
basic_string(const basic_string &other, size_type pos, size_type count=npos)
Construct the string with a substring [pos, min(pos+count, other.size()) of other.
Definition: basic_string.hpp:145
~basic_string()
Destructor.
Definition: basic_string.hpp:306
pointer assign_large_data(InputIt first, InputIt last)
Initialize data_large - call constructor of data_large.
Definition: basic_string.hpp:1320
Commonly used functionality.
iterator begin()
Returns an iterator to the beginning.
Definition: vector.hpp:1080
pointer replace(Args &&... args)
Generic function which replaces current content based on provided parameters.
Definition: basic_string.hpp:1210
CharT & front()
Access first element and snapshot it if there is an active transaction.
Definition: basic_string.hpp:808
const CharT * cdata() const noexcept
Definition: basic_string.hpp:1048
Array container with std::array compatible interface.
pointer initialize(Args &&... args)
Generic function which initializes memory based on provided parameters - forwards parameters to initi...
Definition: basic_string.hpp:1237
const_iterator cend() const noexcept
Return const iterator to past the end.
Definition: basic_string.hpp:631
reference at(size_type n)
Access element at specific index with bounds checking and snapshot it if there is an active transacti...
Definition: basic_string.hpp:722
reverse_iterator rend()
Return a reverse iterator to the end.
Definition: basic_string.hpp:679
basic_string & assign(const basic_string &other)
Replace the string with the copy of the contents of other transactionally.
Definition: basic_string.hpp:415
void check_tx_stage_work() const
Definition: basic_string.hpp:1392
iterator begin()
Returns an iterator to the beginning.
Definition: array.hpp:296
size_type capacity() const noexcept
Definition: basic_string.hpp:1094
size_type get_size(InputIt first, InputIt last) const
Overload of generic get_size method used to calculate size based on provided parameters.
Definition: basic_string.hpp:1172
const_reference operator[](size_type n) const
Access element at specific index.
Definition: basic_string.hpp:793
basic_string & operator=(const basic_string &other)
Copy assignment operator.
Definition: basic_string.hpp:322
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
CharT * data()
Definition: basic_string.hpp:899
const CharT & cfront() const
Access first element.
Definition: basic_string.hpp:833
const T * cdata() const noexcept
Returns const raw pointer to the underlying data.
Definition: array.hpp:284
CharT & back()
Access last element and snapshot it if there is an active transaction.
Definition: basic_string.hpp:848
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
pool_base get_pool() const
Return pool_base instance and assert that object is on pmem.
Definition: basic_string.hpp:1370
int compare(size_type pos, size_type count, const CharT *s) const
Compares [pos, pos + count) substring of this to s.
Definition: basic_string.hpp:1039
basic_string & assign(basic_string &&other)
Replace the string with the contents of other using move semantics transactionally.
Definition: basic_string.hpp:534
Iterators for pmem::obj::array.
C++ pmemobj transactions.
iterator begin()
Return an iterator to the beginning.
Definition: basic_string.hpp:572
basic_string & operator=(CharT ch)
Replace the contents with character ch transactionally.
Definition: basic_string.hpp:365
pointer assign_large_data(size_type count, value_type ch)
Initialize data_large - call constructor of data_large.
Definition: basic_string.hpp:1338
basic_string(const CharT *s)
Construct the string with the contents of s.
Definition: basic_string.hpp:197
bool empty() const noexcept
Definition: basic_string.hpp:1104
const_reverse_iterator crbegin() const noexcept
Return a const reverse iterator to the beginning.
Definition: basic_string.hpp:667
const CharT * c_str() const noexcept
Definition: basic_string.hpp:1066
bool operator>(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member greater than operator.
Definition: array.hpp:747
int compare(size_type pos, size_type count, const basic_string &other) const
Compares [pos, pos + count) substring of this to other.
Definition: basic_string.hpp:975
basic_string & assign(const CharT *s)
Replace the contents with copy of C-style string s transactionally.
Definition: basic_string.hpp:489
basic_string()
Default constructor.
Definition: basic_string.hpp:100
void check_pmem() const
Definition: basic_string.hpp:1382
basic_string(basic_string &&other)
Move constructor.
Definition: basic_string.hpp:270
basic_string & assign(std::initializer_list< CharT > ilist)
Replaces the contents with those of the initializer list ilist transactionally.
Definition: basic_string.hpp:561
void check_pmem_tx() const
Definition: basic_string.hpp:1404
bool operator<(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member less than operator.
Definition: array.hpp:736
basic_string(std::initializer_list< CharT > ilist)
Construct the container with the contents of the initializer list init.
Definition: basic_string.hpp:294
basic_string(const basic_string &other)
Copy constructor.
Definition: basic_string.hpp:249
pointer assign_sso_data(size_type count, value_type ch)
Initialize sso data.
Definition: basic_string.hpp:1287
const_iterator cbegin() const noexcept
Returns const iterator to the beginning.
Definition: array.hpp:326
size_type length() const noexcept
Definition: basic_string.hpp:1075
reference operator[](size_type n)
Access element at specific index and snapshot it if there is an active transaction.
Definition: basic_string.hpp:781
pointer assign_sso_data(InputIt first, InputIt last)
Initialize sso data.
Definition: basic_string.hpp:1268
basic_string & operator=(const CharT *s)
Replace the contents with copy of C-style string s transactionally.
Definition: basic_string.hpp:351
const_reference at(size_type n) const
Access element at specific index with bounds checking.
Definition: basic_string.hpp:741
basic_string(InputIt first, InputIt last)
Construct the string with the contents of the range [first, last).
Definition: basic_string.hpp:226
size_type get_size(const basic_string &other) const
Overload of generic get_size method used to calculate size based on provided parameters.
Definition: basic_string.hpp:1196
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
size_type size() const noexcept
Definition: basic_string.hpp:882
const_iterator cbegin() const noexcept
Return const iterator to the beginning.
Definition: basic_string.hpp:595
Functions for destroying arrays.
basic_string(size_type count, CharT ch)
Construct the container with count copies of elements with value ch.
Definition: basic_string.hpp:121
basic_string & operator=(basic_string &&other)
Move assignment operator.
Definition: basic_string.hpp:337
bool operator<=(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member less or equal operator.
Definition: array.hpp:767
basic_string & assign(const basic_string &other, size_type pos, size_type count=npos)
Replace the contents with a substring [pos, std::min(pos+count, other.size()) of other transactionall...
Definition: basic_string.hpp:441
size_type capacity() const noexcept
Definition: vector.hpp:1397
pointer assign_sso_data(basic_string &&other)
Initialize sso data.
Definition: basic_string.hpp:1304
basic_string(const CharT *s, size_type count)
Construct the string with the first count elements of C-style string s.
Definition: basic_string.hpp:177
int compare(const basic_string &other) const
Compares this string to other.
Definition: basic_string.hpp:956
int compare(size_type pos1, size_type count1, const basic_string &other, size_type pos2, size_type count2=npos) const
Compares [pos1, pos1 + count1) substring of this to [pos2, pos2 + count2) substring of other.
Definition: basic_string.hpp:999
pointer assign_large_data(basic_string &&other)
Initialize data_large - call constructor of data_large.
Definition: basic_string.hpp:1354
size_type get_size(size_type count, value_type ch) const
Overload of generic get_size method used to calculate size based on provided parameters.
Definition: basic_string.hpp:1184
pmem::obj::experimental::string - EXPERIMENTAL persistent container with std::basic_string compatible...
Definition: basic_string.hpp:72
const_iterator begin() const noexcept
Return const iterator to the beginning.
Definition: basic_string.hpp:584
const CharT & cback() const
Access last element.
Definition: basic_string.hpp:873
The non-template pool base class.
Definition: pool.hpp:67
const value_type * cdata() const noexcept
Returns const raw pointer to the underlying data.
Definition: vector.hpp:1068
bool operator>=(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member greater or equal operator.
Definition: array.hpp:757
basic_string & assign(size_type count, CharT ch)
Replace the contents with count copies of character ch transactionally.
Definition: basic_string.hpp:396
Persistent smart pointer.
void reserve(size_type capacity_new)
Increases the capacity of the vector to capacity_new transactionally.
Definition: vector.hpp:1383
const CharT & back() const
Access last element.
Definition: basic_string.hpp:859
iterator end()
Return an iterator to past the end.
Definition: basic_string.hpp:607
basic_string & operator=(std::initializer_list< CharT > ilist)
Replace the contents with those of the initializer list ilist transactionally.
Definition: basic_string.hpp:380
int compare(const CharT *s) const
Compares this string to s.
Definition: basic_string.hpp:1020
basic_string & assign(InputIt first, InputIt last)
Replace the contents with copies of elements in the range [first, last) transactionally.
Definition: basic_string.hpp:515
Default non-const iterator which adds element to a transaction on every access.
Definition: contiguous_iterator.hpp:361
int compare(size_type pos, size_type count1, const CharT *s, size_type count2) const
Compares [pos, pos + count1) substring of this to [s, s + count2) substring of s.
Definition: basic_string.hpp:924