PMDK C++ bindings  1.6.1
This is the C++ bindings documentation for PMDK's libpmemobj.
basic_string.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2019, Intel Corporation
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  *
16  * * Neither the name of the copyright holder nor the names of its
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
38 #ifndef LIBPMEMOBJ_CPP_BASIC_STRING_HPP
39 #define LIBPMEMOBJ_CPP_BASIC_STRING_HPP
40 
41 #include <algorithm>
42 #include <limits>
43 #include <string>
44 
53 #include <libpmemobj++/pext.hpp>
55 
56 namespace pmem
57 {
58 
59 namespace obj
60 {
61 
62 namespace experimental
63 {
64 
71 template <typename CharT, typename Traits = std::char_traits<CharT>>
72 class basic_string {
73 public:
74  /* Member types */
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>;
87 
88  /* Number of characters which can be stored using sso */
89  static constexpr size_type sso_capacity = 64 - sizeof('\0');
90 
101  {
102  check_pmem_tx();
103 
104  initialize(0U, value_type('\0'));
105  }
106 
121  basic_string(size_type count, CharT ch)
122  {
123  check_pmem_tx();
124 
125  initialize(count, ch);
126  }
127 
145  basic_string(const basic_string &other, size_type pos,
146  size_type count = npos)
147  {
148  check_pmem_tx();
149 
150  if (pos > other.size())
151  throw std::out_of_range("Index out of range.");
152 
153  if (count == npos || pos + count > other.size())
154  count = other.size() - pos;
155 
156  auto first = static_cast<difference_type>(pos);
157  auto last = first + static_cast<difference_type>(count);
158 
159  initialize(other.cbegin() + first, other.cbegin() + last);
160  }
161 
177  basic_string(const CharT *s, size_type count)
178  {
179  check_pmem_tx();
180 
181  initialize(s, s + count);
182  }
183 
197  basic_string(const CharT *s)
198  {
199  check_pmem_tx();
200 
201  auto length = traits_type::length(s);
202 
203  initialize(s, s + length);
204  }
205 
222  template <
223  typename InputIt,
224  typename Enable = typename std::enable_if<
226  basic_string(InputIt first, InputIt last)
227  {
228  assert(std::distance(first, last) >= 0);
229 
230  check_pmem_tx();
231 
232  initialize(first, last);
233  }
234 
250  {
251  check_pmem_tx();
252 
253  initialize(other.cbegin(), other.cend());
254  }
255 
271  {
272  check_pmem_tx();
273 
274  initialize(std::move(other));
275 
276  if (other.is_sso_used())
277  other.initialize(0U, value_type('\0'));
278  }
279 
294  basic_string(std::initializer_list<CharT> ilist)
295  {
296  check_pmem_tx();
297 
298  initialize(ilist.begin(), ilist.end());
299  }
300 
307  {
308  if (!is_sso_used())
309  detail::destroy<non_sso_type>(data_large);
310  }
311 
321  basic_string &
322  operator=(const basic_string &other)
323  {
324  return assign(other);
325  }
326 
336  basic_string &
338  {
339  return assign(std::move(other));
340  }
341 
350  basic_string &
351  operator=(const CharT *s)
352  {
353  return assign(s);
354  }
355 
364  basic_string &
365  operator=(CharT ch)
366  {
367  return assign(1, ch);
368  }
369 
379  basic_string &
380  operator=(std::initializer_list<CharT> ilist)
381  {
382  return assign(ilist);
383  }
384 
395  basic_string &
396  assign(size_type count, CharT ch)
397  {
398  auto pop = get_pool();
399 
400  transaction::run(pop, [&] { replace(count, ch); });
401 
402  return *this;
403  }
404 
414  basic_string &
415  assign(const basic_string &other)
416  {
417  if (&other == this)
418  return *this;
419 
420  auto pop = get_pool();
421 
423  pop, [&] { replace(other.cbegin(), other.cend()); });
424 
425  return *this;
426  }
427 
440  basic_string &
441  assign(const basic_string &other, size_type pos, size_type count = npos)
442  {
443  if (pos > other.size())
444  throw std::out_of_range("Index out of range.");
445 
446  if (count == npos || pos + count > other.size())
447  count = other.size() - pos;
448 
449  auto pop = get_pool();
450  auto first = static_cast<difference_type>(pos);
451  auto last = first + static_cast<difference_type>(count);
452 
453  transaction::run(pop, [&] {
454  replace(other.cbegin() + first, other.cbegin() + last);
455  });
456 
457  return *this;
458  }
459 
470  basic_string &
471  assign(const CharT *s, size_type count)
472  {
473  auto pop = get_pool();
474 
475  transaction::run(pop, [&] { replace(s, s + count); });
476 
477  return *this;
478  }
479 
488  basic_string &
489  assign(const CharT *s)
490  {
491  auto pop = get_pool();
492 
493  auto length = traits_type::length(s);
494 
495  transaction::run(pop, [&] { replace(s, s + length); });
496 
497  return *this;
498  }
499 
511  template <typename InputIt,
512  typename Enable = typename pmem::detail::is_input_iterator<
513  InputIt>::type>
514  basic_string &
515  assign(InputIt first, InputIt last)
516  {
517  auto pop = get_pool();
518 
519  transaction::run(pop, [&] { replace(first, last); });
520 
521  return *this;
522  }
523 
533  basic_string &
535  {
536  if (&other == this)
537  return *this;
538 
539  auto pop = get_pool();
540 
541  transaction::run(pop, [&] {
542  replace(std::move(other));
543 
544  if (other.is_sso_used())
545  other.initialize(0U, value_type('\0'));
546  });
547 
548  return *this;
549  }
550 
560  basic_string &
561  assign(std::initializer_list<CharT> ilist)
562  {
563  return assign(ilist.begin(), ilist.end());
564  }
565 
571  iterator
573  {
574  return is_sso_used() ? iterator(&*data_sso.begin())
575  : iterator(&*data_large.begin());
576  }
577 
583  const_iterator
584  begin() const noexcept
585  {
586  return cbegin();
587  }
588 
594  const_iterator
595  cbegin() const noexcept
596  {
597  return is_sso_used() ? const_iterator(&*data_sso.cbegin())
598  : const_iterator(&*data_large.cbegin());
599  }
600 
606  iterator
607  end()
608  {
609  return begin() + static_cast<difference_type>(size());
610  }
611 
618  const_iterator
619  end() const noexcept
620  {
621  return cbegin() + static_cast<difference_type>(size());
622  }
623 
630  const_iterator
631  cend() const noexcept
632  {
633  return cbegin() + static_cast<difference_type>(size());
634  }
635 
642  reverse_iterator
644  {
645  return reverse_iterator(end());
646  }
647 
654  const_reverse_iterator
655  rbegin() const noexcept
656  {
657  return crbegin();
658  }
659 
666  const_reverse_iterator
667  crbegin() const noexcept
668  {
669  return const_reverse_iterator(cend());
670  }
671 
678  reverse_iterator
680  {
681  return reverse_iterator(begin());
682  }
683 
690  const_reverse_iterator
691  rend() const noexcept
692  {
693  return crend();
694  }
695 
702  const_reverse_iterator
703  crend() const noexcept
704  {
705  return const_reverse_iterator(cbegin());
706  }
707 
721  reference
722  at(size_type n)
723  {
724  if (n >= size())
725  throw std::out_of_range("string::at");
726 
727  return is_sso_used() ? data_sso[n] : data_large[n];
728  }
729 
740  const_reference
741  at(size_type n) const
742  {
743  return const_at(n);
744  }
745 
759  const_reference
760  const_at(size_type n) const
761  {
762  if (n >= size())
763  throw std::out_of_range("string::const_at");
764 
765  return is_sso_used()
766  ? static_cast<const sso_type &>(data_sso)[n]
767  : static_cast<const non_sso_type &>(data_large)[n];
768  }
769 
781  reference operator[](size_type n)
782  {
783  return is_sso_used() ? data_sso[n] : data_large[n];
784  }
785 
793  const_reference operator[](size_type n) const
794  {
795  return is_sso_used() ? data_sso[n] : data_large[n];
796  }
797 
807  CharT &
809  {
810  return (*this)[0];
811  }
812 
818  const CharT &
819  front() const
820  {
821  return cfront();
822  }
823 
832  const CharT &
833  cfront() const
834  {
835  return static_cast<const basic_string &>(*this)[0];
836  }
837 
847  CharT &
849  {
850  return (*this)[size() - 1];
851  }
852 
858  const CharT &
859  back() const
860  {
861  return cback();
862  }
863 
872  const CharT &
873  cback() const
874  {
875  return static_cast<const basic_string &>(*this)[size() - 1];
876  }
877 
881  size_type
882  size() const noexcept
883  {
884  if (is_sso_used())
885  return _size;
886  else if (data_large.size() == 0)
887  return 0;
888  else
889  return data_large.size() - sizeof('\0');
890  }
891 
898  CharT *
900  {
901  return is_sso_used()
902  ? data_sso.range(0, size() + sizeof('\0')).begin()
903  : data_large.data();
904  }
905 
923  int
924  compare(size_type pos, size_type count1, const CharT *s,
925  size_type count2) const
926  {
927  if (pos > size())
928  throw std::out_of_range("Index out of range.");
929 
930  if (count1 > size() - pos)
931  count1 = size() - pos;
932 
933  auto ret = traits_type::compare(
934  cdata() + pos, s, std::min<size_type>(count1, count2));
935 
936  if (ret != 0)
937  return ret;
938 
939  if (count1 < count2)
940  return -1;
941  else if (count1 == count2)
942  return 0;
943  else
944  return 1;
945  }
946 
955  int
956  compare(const basic_string &other) const
957  {
958  return compare(0, size(), other.cdata(), other.size());
959  }
960 
974  int
975  compare(size_type pos, size_type count, const basic_string &other) const
976  {
977  return compare(pos, count, other.cdata(), other.size());
978  }
979 
998  int
999  compare(size_type pos1, size_type count1, const basic_string &other,
1000  size_type pos2, size_type count2 = npos) const
1001  {
1002  if (pos2 > other.size())
1003  throw std::out_of_range("Index out of range.");
1004 
1005  if (count2 > other.size() - pos2)
1006  count2 = other.size() - pos2;
1007 
1008  return compare(pos1, count1, other.cdata() + pos2, count2);
1009  }
1010 
1019  int
1020  compare(const CharT *s) const
1021  {
1022  return compare(0, size(), s, traits_type::length(s));
1023  }
1024 
1038  int
1039  compare(size_type pos, size_type count, const CharT *s) const
1040  {
1041  return compare(pos, count, s, traits_type::length(s));
1042  }
1043 
1047  const CharT *
1048  cdata() const noexcept
1049  {
1050  return is_sso_used() ? data_sso.cdata() : data_large.cdata();
1051  }
1052 
1056  const CharT *
1057  data() const noexcept
1058  {
1059  return cdata();
1060  }
1061 
1065  const CharT *
1066  c_str() const noexcept
1067  {
1068  return cdata();
1069  }
1070 
1074  size_type
1075  length() const noexcept
1076  {
1077  return size();
1078  }
1079 
1083  size_type
1084  max_size() const noexcept
1085  {
1086  return PMEMOBJ_MAX_ALLOC_SIZE / sizeof(CharT) - 1;
1087  }
1088 
1093  size_type
1094  capacity() const noexcept
1095  {
1096  return is_sso_used() ? sso_capacity
1097  : data_large.capacity() - sizeof('\0');
1098  }
1099 
1103  bool
1104  empty() const noexcept
1105  {
1106  return size() == 0;
1107  }
1108 
1109  /* Special value. The exact meaning depends on the context. */
1110  static const size_type npos = static_cast<size_type>(-1);
1111 
1112 private:
1113  using sso_type = array<value_type, sso_capacity + sizeof('\0')>;
1114  using non_sso_type = vector<value_type>;
1115 
1121  union {
1122  sso_type data_sso;
1123 
1124  non_sso_type data_large;
1125  };
1126 
1127  /* Holds size if sso is used, std::numeric_limits<size_type>::max()
1128  * otherwise */
1129  p<size_type> _size;
1130 
1131  bool
1132  is_sso_used() const
1133  {
1134  assert(_size <= sso_capacity ||
1135  _size == std::numeric_limits<size_type>::max());
1136 
1137  return _size <= sso_capacity;
1138  }
1139 
1140  void
1141  destroy_data()
1142  {
1143  assert(pmemobj_tx_stage() == TX_STAGE_WORK);
1144 
1145  /*
1146  * XXX: this can be optimized - only snapshot length() elements.
1147  */
1148 #if LIBPMEMOBJ_CPP_VG_MEMCHECK_ENABLED
1149  VALGRIND_MAKE_MEM_DEFINED(&data_sso, sizeof(data_sso));
1150 #endif
1151 
1152  if (is_sso_used()) {
1153  data_sso.data();
1154  /* data_sso constructor does not have to be called */
1155  } else {
1156  data_large.free_data();
1157  detail::destroy<decltype(data_large)>(data_large);
1158  }
1159  }
1160 
1167  template <
1168  typename InputIt,
1169  typename Enable = typename std::enable_if<
1171  size_type
1172  get_size(InputIt first, InputIt last) const
1173  {
1174  return static_cast<size_type>(std::distance(first, last));
1175  }
1176 
1183  size_type
1184  get_size(size_type count, value_type ch) const
1185  {
1186  return count;
1187  }
1188 
1195  size_type
1196  get_size(const basic_string &other) const
1197  {
1198  return other.size();
1199  }
1200 
1208  template <typename... Args>
1209  pointer
1210  replace(Args &&... args)
1211  {
1212  assert(pmemobj_tx_stage() == TX_STAGE_WORK);
1213 
1214  auto new_size = get_size(std::forward<Args>(args)...);
1215 
1216  /* If data_large is used and there is enough capacity */
1217  if (!is_sso_used() && new_size <= capacity())
1218  return assign_large_data(std::forward<Args>(args)...);
1219 
1220  destroy_data();
1221 
1222  return initialize(std::forward<Args>(args)...);
1223  }
1224 
1235  template <typename... Args>
1236  pointer
1237  initialize(Args &&... args)
1238  {
1239  assert(pmemobj_tx_stage() == TX_STAGE_WORK);
1240 
1241  auto new_size = get_size(std::forward<Args>(args)...);
1242 
1243  if (new_size <= sso_capacity)
1244  _size = new_size;
1245  else
1246  _size = std::numeric_limits<size_type>::max();
1247 
1248  if (is_sso_used()) {
1249  /*
1250  * array is aggregate type so it's not required to call
1251  * a constructor.
1252  */
1253  return assign_sso_data(std::forward<Args>(args)...);
1254  } else {
1255  detail::create<decltype(data_large)>(&data_large);
1256  return assign_large_data(std::forward<Args>(args)...);
1257  }
1258  }
1259 
1263  template <
1264  typename InputIt,
1265  typename Enable = typename std::enable_if<
1267  pointer
1268  assign_sso_data(InputIt first, InputIt last)
1269  {
1270  auto size = static_cast<size_type>(std::distance(first, last));
1271 
1272  assert(pmemobj_tx_stage() == TX_STAGE_WORK);
1273  assert(size <= sso_capacity);
1274 
1275  auto dest = data_sso.range(0, size + sizeof('\0')).begin();
1276  std::copy(first, last, dest);
1277 
1278  dest[size] = value_type('\0');
1279 
1280  return dest;
1281  }
1282 
1286  pointer
1287  assign_sso_data(size_type count, value_type ch)
1288  {
1289  assert(pmemobj_tx_stage() == TX_STAGE_WORK);
1290  assert(count <= sso_capacity);
1291 
1292  auto dest = data_sso.range(0, count + sizeof('\0')).begin();
1293  traits_type::assign(dest, count, ch);
1294 
1295  dest[count] = value_type('\0');
1296 
1297  return dest;
1298  }
1299 
1303  pointer
1305  {
1306  assert(pmemobj_tx_stage() == TX_STAGE_WORK);
1307 
1308  return assign_sso_data(other.cbegin(), other.cend());
1309  }
1310 
1315  template <
1316  typename InputIt,
1317  typename Enable = typename std::enable_if<
1319  pointer
1320  assign_large_data(InputIt first, InputIt last)
1321  {
1322  assert(pmemobj_tx_stage() == TX_STAGE_WORK);
1323 
1324  auto size = static_cast<size_type>(std::distance(first, last));
1325 
1326  data_large.reserve(size + sizeof('\0'));
1327  data_large.assign(first, last);
1328  data_large.push_back(value_type('\0'));
1329 
1330  return data_large.data();
1331  }
1332 
1337  pointer
1338  assign_large_data(size_type count, value_type ch)
1339  {
1340  assert(pmemobj_tx_stage() == TX_STAGE_WORK);
1341 
1342  data_large.reserve(count + sizeof('\0'));
1343  data_large.assign(count, ch);
1344  data_large.push_back(value_type('\0'));
1345 
1346  return data_large.data();
1347  }
1348 
1353  pointer
1355  {
1356  assert(pmemobj_tx_stage() == TX_STAGE_WORK);
1357 
1358  if (other.is_sso_used())
1359  return assign_large_data(other.cbegin(), other.cend());
1360 
1361  data_large = std::move(other.data_large);
1362 
1363  return data_large.data();
1364  }
1365 
1369  pool_base
1370  get_pool() const
1371  {
1372  auto pop = pmemobj_pool_by_ptr(this);
1373  assert(pop != nullptr);
1374 
1375  return pool_base(pop);
1376  }
1377 
1381  void
1382  check_pmem() const
1383  {
1384  if (pmemobj_pool_by_ptr(this) == nullptr)
1385  throw pool_error("Object is not on pmem.");
1386  }
1387 
1391  void
1393  {
1394  if (pmemobj_tx_stage() != TX_STAGE_WORK)
1395  throw transaction_error(
1396  "Call made out of transaction scope.");
1397  }
1398 
1403  void
1405  {
1406  check_pmem();
1408  }
1409 };
1410 
1414 template <class CharT, class Traits>
1415 bool
1417  const basic_string<CharT, Traits> &rhs)
1418 {
1419  return lhs.compare(rhs) == 0;
1420 }
1421 
1425 template <class CharT, class Traits>
1426 bool
1428  const basic_string<CharT, Traits> &rhs)
1429 {
1430  return lhs.compare(rhs) != 0;
1431 }
1432 
1436 template <class CharT, class Traits>
1437 bool
1439  const basic_string<CharT, Traits> &rhs)
1440 {
1441  return lhs.compare(rhs) < 0;
1442 }
1443 
1447 template <class CharT, class Traits>
1448 bool
1450  const basic_string<CharT, Traits> &rhs)
1451 {
1452  return lhs.compare(rhs) <= 0;
1453 }
1454 
1458 template <class CharT, class Traits>
1459 bool
1461  const basic_string<CharT, Traits> &rhs)
1462 {
1463  return lhs.compare(rhs) > 0;
1464 }
1465 
1469 template <class CharT, class Traits>
1470 bool
1472  const basic_string<CharT, Traits> &rhs)
1473 {
1474  return lhs.compare(rhs) >= 0;
1475 }
1476 
1480 template <class CharT, class Traits>
1481 bool
1482 operator==(const CharT *lhs, const basic_string<CharT, Traits> &rhs)
1483 {
1484  return rhs.compare(lhs) == 0;
1485 }
1486 
1490 template <class CharT, class Traits>
1491 bool
1492 operator!=(const CharT *lhs, const basic_string<CharT, Traits> &rhs)
1493 {
1494  return rhs.compare(lhs) != 0;
1495 }
1496 
1500 template <class CharT, class Traits>
1501 bool
1502 operator<(const CharT *lhs, const basic_string<CharT, Traits> &rhs)
1503 {
1504  return rhs.compare(lhs) > 0;
1505 }
1506 
1510 template <class CharT, class Traits>
1511 bool
1512 operator<=(const CharT *lhs, const basic_string<CharT, Traits> &rhs)
1513 {
1514  return rhs.compare(lhs) >= 0;
1515 }
1516 
1520 template <class CharT, class Traits>
1521 bool
1522 operator>(const CharT *lhs, const basic_string<CharT, Traits> &rhs)
1523 {
1524  return rhs.compare(lhs) < 0;
1525 }
1526 
1530 template <class CharT, class Traits>
1531 bool
1532 operator>=(const CharT *lhs, const basic_string<CharT, Traits> &rhs)
1533 {
1534  return rhs.compare(lhs) <= 0;
1535 }
1536 
1540 template <class CharT, class Traits>
1541 bool
1542 operator==(const basic_string<CharT, Traits> &lhs, const CharT *rhs)
1543 {
1544  return lhs.compare(rhs) == 0;
1545 }
1546 
1550 template <class CharT, class Traits>
1551 bool
1552 operator!=(const basic_string<CharT, Traits> &lhs, const CharT *rhs)
1553 {
1554  return lhs.compare(rhs) != 0;
1555 }
1556 
1560 template <class CharT, class Traits>
1561 bool
1562 operator<(const basic_string<CharT, Traits> &lhs, const CharT *rhs)
1563 {
1564  return lhs.compare(rhs) < 0;
1565 }
1566 
1570 template <class CharT, class Traits>
1571 bool
1572 operator<=(const basic_string<CharT, Traits> &lhs, const CharT *rhs)
1573 {
1574  return lhs.compare(rhs) <= 0;
1575 }
1576 
1580 template <class CharT, class Traits>
1581 bool
1582 operator>(const basic_string<CharT, Traits> &lhs, const CharT *rhs)
1583 {
1584  return lhs.compare(rhs) > 0;
1585 }
1586 
1590 template <class CharT, class Traits>
1591 bool
1592 operator>=(const basic_string<CharT, Traits> &lhs, const CharT *rhs)
1593 {
1594  return lhs.compare(rhs) >= 0;
1595 }
1596 
1597 } /* namespace experimental */
1598 
1599 } /* namespace obj */
1600 
1601 } /* namespace pmem */
1602 
1603 #endif /* LIBPMEMOBJ_CPP_BASIC_STRING_HPP */
pmem::obj::experimental::basic_string::rbegin
const_reverse_iterator rbegin() const noexcept
Return a const reverse iterator to the beginning.
Definition: basic_string.hpp:655
pmem::obj::experimental::vector::size
size_type size() const noexcept
Definition: vector.hpp:1347
pmem::obj::experimental::basic_string::max_size
size_type max_size() const noexcept
Definition: basic_string.hpp:1084
iterator_traits.hpp
Common iterator traits.
pmem::obj::experimental::basic_string::const_at
const_reference const_at(size_type n) const
Access element at specific index with bounds checking.
Definition: basic_string.hpp:760
pmem::obj::experimental::vector::push_back
void push_back(const T &value)
Appends the given element value to the end of the container transactionally.
Definition: vector.hpp:1886
pmem::obj::experimental::vector::free_data
void free_data()
Clears the content of a vector and frees all allocated persistent memory for data transactionally.
Definition: vector.hpp:1458
pmem::obj::experimental::vector< value_type >
pmem::obj::experimental::vector::cbegin
const_iterator cbegin() const noexcept
Returns const iterator to the beginning.
Definition: vector.hpp:1106
pmem::obj::experimental::basic_string::rend
const_reverse_iterator rend() const noexcept
Return a const reverse iterator to the end.
Definition: basic_string.hpp:691
pmem::obj::experimental::basic_string::rbegin
reverse_iterator rbegin()
Return a reverse iterator to the beginning.
Definition: basic_string.hpp:643
pmem::obj::experimental::array::data
T * data()
Returns raw pointer to the underlying data and adds entire array to a transaction.
Definition: array.hpp:265
pmem::obj::experimental::basic_string::assign
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.hpp
Vector container with std::vector compatible interface.
pmem::obj::experimental::basic_string::end
const_iterator end() const noexcept
Return const iterator to past the end.
Definition: basic_string.hpp:619
pmem::obj::experimental::basic_string::crend
const_reverse_iterator crend() const noexcept
Return a const reverse iterator to the end.
Definition: basic_string.hpp:703
pmem::obj::experimental::vector::data
value_type * data()
Returns raw pointer to the underlying data and adds entire array to a transaction.
Definition: vector.hpp:1040
pmem::pool_error
Custom pool error class.
Definition: pexceptions.hpp:53
pmem::transaction_error
Custom transaction error class.
Definition: pexceptions.hpp:63
pmem::obj::experimental::basic_string::data
const CharT * data() const noexcept
Definition: basic_string.hpp:1057
pmem::obj::experimental::basic_string::front
const CharT & front() const
Access first element.
Definition: basic_string.hpp:819
pmem::obj::experimental::basic_string::basic_string
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
pmem::obj::experimental::basic_string::~basic_string
~basic_string()
Destructor.
Definition: basic_string.hpp:306
pmem::obj::experimental::basic_string::assign_large_data
pointer assign_large_data(InputIt first, InputIt last)
Initialize data_large - call constructor of data_large.
Definition: basic_string.hpp:1320
common.hpp
Commonly used functionality.
pmem::obj::experimental::vector::begin
iterator begin()
Returns an iterator to the beginning.
Definition: vector.hpp:1080
pmem::obj::experimental::basic_string::replace
pointer replace(Args &&... args)
Generic function which replaces current content based on provided parameters.
Definition: basic_string.hpp:1210
pmem::obj::experimental::basic_string::front
CharT & front()
Access first element and snapshot it if there is an active transaction.
Definition: basic_string.hpp:808
pmem::obj::experimental::basic_string::cdata
const CharT * cdata() const noexcept
Definition: basic_string.hpp:1048
array.hpp
Array container with std::array compatible interface.
pmem::obj::experimental::basic_string::initialize
pointer initialize(Args &&... args)
Generic function which initializes memory based on provided parameters - forwards parameters to initi...
Definition: basic_string.hpp:1237
pmem::obj::experimental::basic_string::cend
const_iterator cend() const noexcept
Return const iterator to past the end.
Definition: basic_string.hpp:631
pmem::obj::experimental::basic_string::at
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
pmem::obj::experimental::basic_string::rend
reverse_iterator rend()
Return a reverse iterator to the end.
Definition: basic_string.hpp:679
pmem::obj::experimental::basic_string::assign
basic_string & assign(const basic_string &other)
Replace the string with the copy of the contents of other transactionally.
Definition: basic_string.hpp:415
pmem::obj::experimental::basic_string::check_tx_stage_work
void check_tx_stage_work() const
Definition: basic_string.hpp:1392
pmem::obj::experimental::array::begin
iterator begin()
Returns an iterator to the beginning.
Definition: array.hpp:296
pmem::obj::p< size_type >
pmem::obj::experimental::basic_string::capacity
size_type capacity() const noexcept
Definition: basic_string.hpp:1094
pmem::obj::experimental::basic_string::get_size
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
pmem::obj::experimental::basic_string::operator[]
const_reference operator[](size_type n) const
Access element at specific index.
Definition: basic_string.hpp:793
pmem::obj::experimental::basic_string::operator=
basic_string & operator=(const basic_string &other)
Copy assignment operator.
Definition: basic_string.hpp:322
pmem::obj::operator!=
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
pmem::obj::experimental::basic_string::data
CharT * data()
Definition: basic_string.hpp:899
pmem::obj::experimental::basic_string::cfront
const CharT & cfront() const
Access first element.
Definition: basic_string.hpp:833
pmem::obj::experimental::array::cdata
const T * cdata() const noexcept
Returns const raw pointer to the underlying data.
Definition: array.hpp:284
pmem::obj::experimental::basic_string::back
CharT & back()
Access last element and snapshot it if there is an active transaction.
Definition: basic_string.hpp:848
slice.hpp
Iterface to access sequence of objects.
pmem::obj::transaction::run
static void run(pool_base &pool, std::function< void()> tx, Locks &... locks)
Execute a closure-like transaction and lock locks.
Definition: transaction.hpp:398
pmem::obj::experimental::basic_string::get_pool
pool_base get_pool() const
Return pool_base instance and assert that object is on pmem.
Definition: basic_string.hpp:1370
pmem::obj::experimental::basic_string::compare
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
pmem::obj::experimental::basic_string::assign
basic_string & assign(basic_string &&other)
Replace the string with the contents of other using move semantics transactionally.
Definition: basic_string.hpp:534
contiguous_iterator.hpp
Iterators for pmem::obj::array.
transaction.hpp
C++ pmemobj transactions.
pmem::obj::experimental::basic_string::begin
iterator begin()
Return an iterator to the beginning.
Definition: basic_string.hpp:572
pmem::obj::experimental::basic_string::operator=
basic_string & operator=(CharT ch)
Replace the contents with character ch transactionally.
Definition: basic_string.hpp:365
pmem::detail::is_input_iterator
Type trait to determine if a given parameter type satisfies requirements of InputIterator.
Definition: iterator_traits.hpp:76
pmem::obj::experimental::basic_string::assign_large_data
pointer assign_large_data(size_type count, value_type ch)
Initialize data_large - call constructor of data_large.
Definition: basic_string.hpp:1338
pmem::obj::experimental::basic_string::basic_string
basic_string(const CharT *s)
Construct the string with the contents of s.
Definition: basic_string.hpp:197
pmem::obj::experimental::basic_string::empty
bool empty() const noexcept
Definition: basic_string.hpp:1104
pmem::obj::experimental::basic_string::crbegin
const_reverse_iterator crbegin() const noexcept
Return a const reverse iterator to the beginning.
Definition: basic_string.hpp:667
pmem::obj::experimental::basic_string::c_str
const CharT * c_str() const noexcept
Definition: basic_string.hpp:1066
pmem::obj::experimental::operator>
bool operator>(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member greater than operator.
Definition: array.hpp:747
pmem::obj::experimental::basic_string::compare
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
pmem::obj::experimental::basic_string::assign
basic_string & assign(const CharT *s)
Replace the contents with copy of C-style string s transactionally.
Definition: basic_string.hpp:489
pmem::obj::experimental::basic_string::basic_string
basic_string()
Default constructor.
Definition: basic_string.hpp:100
pmem::obj::experimental::basic_string::check_pmem
void check_pmem() const
Definition: basic_string.hpp:1382
pmem::obj::experimental::basic_string::basic_string
basic_string(basic_string &&other)
Move constructor.
Definition: basic_string.hpp:270
pmem::obj::experimental::basic_string::assign
basic_string & assign(std::initializer_list< CharT > ilist)
Replaces the contents with those of the initializer list ilist transactionally.
Definition: basic_string.hpp:561
pmem::obj::experimental::basic_string::check_pmem_tx
void check_pmem_tx() const
Definition: basic_string.hpp:1404
pmem::obj::experimental::operator<
bool operator<(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member less than operator.
Definition: array.hpp:736
pmem::obj::experimental::basic_string::basic_string
basic_string(std::initializer_list< CharT > ilist)
Construct the container with the contents of the initializer list init.
Definition: basic_string.hpp:294
pmem::obj::experimental::basic_string::basic_string
basic_string(const basic_string &other)
Copy constructor.
Definition: basic_string.hpp:249
pmem::obj::experimental::basic_string::assign_sso_data
pointer assign_sso_data(size_type count, value_type ch)
Initialize sso data.
Definition: basic_string.hpp:1287
pmem::obj::experimental::array::cbegin
const_iterator cbegin() const noexcept
Returns const iterator to the beginning.
Definition: array.hpp:326
pmem::obj::experimental::basic_string::length
size_type length() const noexcept
Definition: basic_string.hpp:1075
pmem::obj::experimental::basic_string::operator[]
reference operator[](size_type n)
Access element at specific index and snapshot it if there is an active transaction.
Definition: basic_string.hpp:781
pmem::obj::experimental::basic_string::assign_sso_data
pointer assign_sso_data(InputIt first, InputIt last)
Initialize sso data.
Definition: basic_string.hpp:1268
pmem::obj::experimental::basic_string::operator=
basic_string & operator=(const CharT *s)
Replace the contents with copy of C-style string s transactionally.
Definition: basic_string.hpp:351
pmem::obj::experimental::basic_string::at
const_reference at(size_type n) const
Access element at specific index with bounds checking.
Definition: basic_string.hpp:741
pmem::obj::experimental::basic_string::basic_string
basic_string(InputIt first, InputIt last)
Construct the string with the contents of the range [first, last).
Definition: basic_string.hpp:226
pmem::obj::experimental::basic_string::get_size
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
pext.hpp
Convenience extensions for the resides on pmem property template.
pmem::obj::experimental::array::range
slice< pointer > range(size_type start, size_type n)
Returns slice and snapshots requested range.
Definition: array.hpp:483
pmem::obj::operator==
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::basic_string::size
size_type size() const noexcept
Definition: basic_string.hpp:882
pmem::obj::experimental::basic_string::cbegin
const_iterator cbegin() const noexcept
Return const iterator to the beginning.
Definition: basic_string.hpp:595
life.hpp
Functions for destroying arrays.
pmem::obj::experimental::basic_string::basic_string
basic_string(size_type count, CharT ch)
Construct the container with count copies of elements with value ch.
Definition: basic_string.hpp:121
pmem::obj::experimental::basic_string::operator=
basic_string & operator=(basic_string &&other)
Move assignment operator.
Definition: basic_string.hpp:337
pmem::obj::experimental::array< value_type, sso_capacity+sizeof('\0')>
pmem::obj::experimental::operator<=
bool operator<=(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member less or equal operator.
Definition: array.hpp:767
pmem::obj::experimental::basic_string::assign
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
pmem::obj::experimental::vector::capacity
size_type capacity() const noexcept
Definition: vector.hpp:1397
pmem::obj::experimental::basic_string::assign_sso_data
pointer assign_sso_data(basic_string &&other)
Initialize sso data.
Definition: basic_string.hpp:1304
pmem::obj::experimental::basic_string::basic_string
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
pmem::obj::experimental::basic_string::compare
int compare(const basic_string &other) const
Compares this string to other.
Definition: basic_string.hpp:956
pmem::obj::experimental::basic_string::compare
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
pmem::obj::experimental::basic_string::assign_large_data
pointer assign_large_data(basic_string &&other)
Initialize data_large - call constructor of data_large.
Definition: basic_string.hpp:1354
pmem::obj::experimental::basic_string::get_size
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::basic_string
pmem::obj::experimental::string - EXPERIMENTAL persistent container with std::basic_string compatible...
Definition: basic_string.hpp:72
pmem::obj::experimental::basic_string::begin
const_iterator begin() const noexcept
Return const iterator to the beginning.
Definition: basic_string.hpp:584
pmem::obj::experimental::basic_string::cback
const CharT & cback() const
Access last element.
Definition: basic_string.hpp:873
pmem::obj::pool_base
The non-template pool base class.
Definition: pool.hpp:67
pmem::obj::experimental::vector::cdata
const value_type * cdata() const noexcept
Returns const raw pointer to the underlying data.
Definition: vector.hpp:1068
pmem::obj::experimental::operator>=
bool operator>=(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member greater or equal operator.
Definition: array.hpp:757
pmem::obj::experimental::basic_string::assign
basic_string & assign(size_type count, CharT ch)
Replace the contents with count copies of character ch transactionally.
Definition: basic_string.hpp:396
persistent_ptr.hpp
Persistent smart pointer.
pmem::obj::experimental::vector::reserve
void reserve(size_type capacity_new)
Increases the capacity of the vector to capacity_new transactionally.
Definition: vector.hpp:1383
pmem::obj::experimental::basic_string::back
const CharT & back() const
Access last element.
Definition: basic_string.hpp:859
pmem::obj::experimental::basic_string::end
iterator end()
Return an iterator to past the end.
Definition: basic_string.hpp:607
pmem::obj::experimental::basic_string::operator=
basic_string & operator=(std::initializer_list< CharT > ilist)
Replace the contents with those of the initializer list ilist transactionally.
Definition: basic_string.hpp:380
pmem::obj::experimental::basic_string::compare
int compare(const CharT *s) const
Compares this string to s.
Definition: basic_string.hpp:1020
pmem::obj::experimental::basic_string::assign
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
pmem::obj::experimental::basic_contiguous_iterator
Default non-const iterator which adds element to a transaction on every access.
Definition: contiguous_iterator.hpp:361
pmem::obj::experimental::basic_string::compare
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