PMDK C++ bindings
1.12-git53.g67ba2be4
This is the C++ bindings documentation for PMDK's libpmemobj.
|
Go to the documentation of this file.
9 #ifndef LIBPMEMOBJ_CPP_INLINE_STRING_HPP
10 #define LIBPMEMOBJ_CPP_INLINE_STRING_HPP
26 namespace experimental
43 template <
typename CharT,
typename Traits = std::
char_traits<CharT>>
46 using traits_type = Traits;
47 using value_type = CharT;
48 using size_type = std::size_t;
49 using difference_type = std::ptrdiff_t;
50 using reference = value_type &;
51 using const_reference =
const value_type &;
52 using pointer = value_type *;
53 using const_pointer =
const value_type *;
67 size_type
size()
const noexcept;
71 const_pointer
data()
const noexcept;
72 const_pointer
cdata()
const noexcept;
77 const_reference
operator[](size_type
p)
const noexcept;
79 reference
at(size_type
p);
80 const_reference
at(size_type
p)
const;
103 template <
typename CharT,
typename Traits>
106 : size_(
v.size()), capacity_(
v.size())
108 if (
nullptr == pmemobj_pool_by_ptr(
this))
111 std::copy(
v.data(),
v.data() +
static_cast<ptrdiff_t
>(size_),
data());
113 data()[
static_cast<ptrdiff_t
>(size_)] =
'\0';
121 template <
typename CharT,
typename Traits>
123 : size_(0), capacity_(capacity)
125 if (
nullptr == pmemobj_pool_by_ptr(
this))
128 data()[
static_cast<ptrdiff_t
>(size_)] =
'\0';
136 template <
typename CharT,
typename Traits>
139 : size_(rhs.size()), capacity_(rhs.capacity())
141 if (
nullptr == pmemobj_pool_by_ptr(
this))
144 std::copy(rhs.
data(), rhs.
data() +
static_cast<ptrdiff_t
>(size_),
147 data()[
static_cast<ptrdiff_t
>(size_)] =
'\0';
153 template <
typename CharT,
typename Traits>
166 template <
typename CharT,
typename Traits>
175 template <
typename CharT,
typename Traits>
179 return {data(), size()};
183 template <
typename CharT,
typename Traits>
184 typename basic_inline_string<CharT, Traits>::size_type
197 template <
typename CharT,
typename Traits>
198 typename basic_inline_string<CharT, Traits>::size_type
213 template <
typename CharT,
typename Traits>
214 typename basic_inline_string<CharT, Traits>::pointer
217 return snapshotted_data(0, size_);
221 template <
typename CharT,
typename Traits>
222 typename basic_inline_string<CharT, Traits>::const_pointer
235 template <
typename CharT,
typename Traits>
236 typename basic_inline_string<CharT, Traits>::const_pointer
239 return reinterpret_cast<const CharT *
>(
this + 1);
250 template <
typename CharT,
typename Traits>
266 template <
typename CharT,
typename Traits>
267 typename basic_inline_string<CharT, Traits>::reference
270 return snapshotted_data(
p, 1)[0];
279 template <
typename CharT,
typename Traits>
280 typename basic_inline_string<CharT, Traits>::const_reference
296 template <
typename CharT,
typename Traits>
297 typename basic_inline_string<CharT, Traits>::reference
301 throw std::out_of_range(
"basic_inline_string::at");
303 return snapshotted_data(
p, 1)[0];
314 template <
typename CharT,
typename Traits>
315 typename basic_inline_string<CharT, Traits>::const_reference
319 throw std::out_of_range(
"basic_inline_string::at");
337 template <
typename CharT,
typename Traits>
341 if (start + n > size())
342 throw std::out_of_range(
"basic_inline_string::range");
344 auto data = snapshotted_data(start, n);
346 return {data, data + n};
353 template <
typename CharT,
typename Traits>
354 typename basic_inline_string<CharT, Traits>::pointer
357 assert(
p + n <= size());
359 detail::conditional_add_to_tx(
reinterpret_cast<CharT *
>(
this + 1) +
p,
360 n, POBJ_XADD_ASSUME_INITIALIZED);
362 return reinterpret_cast<CharT *
>(
this + 1) +
p;
370 template <
typename CharT,
typename Traits>
376 if (rhs.
size() > capacity())
377 throw std::out_of_range(
"inline_string capacity exceeded.");
379 auto initialized_mem =
380 (std::min)(rhs.
size(), size()) + 1 ;
383 detail::conditional_add_to_tx(data(), initialized_mem);
385 if (rhs.
size() > size())
386 detail::conditional_add_to_tx(
387 data() + initialized_mem,
388 rhs.
size() - initialized_mem + 1,
389 POBJ_XADD_NO_SNAPSHOT);
391 std::copy(rhs.
data(),
392 rhs.
data() +
static_cast<ptrdiff_t
>(rhs.
size()),
396 data()[
static_cast<ptrdiff_t
>(size_)] =
'\0';
408 template <
typename T>
410 template <
typename... Args>
412 value(
const Args &... args)
425 template <
typename CharT,
typename Traits>
431 (s.
size() + 1 ) *
sizeof(CharT);
441 struct is_inline_string : std::false_type {
444 template <
typename CharT,
typename Traits>
445 struct is_inline_string<obj::experimental::basic_inline_string<CharT, Traits>>
Our partial std::string_view implementation.
Definition: string_view.hpp:46
Custom pool error class.
Definition: pexceptions.hpp:45
size_type capacity() const noexcept
Definition: inline_string.hpp:199
Our partial std::string_view implementation.
Persistent memory namespace.
Definition: allocation_flag.hpp:15
int compare(const basic_inline_string &rhs) const noexcept
Compares this inline_string with other.
Definition: inline_string.hpp:252
basic_inline_string & operator=(const basic_inline_string &rhs)
Copy assignment operator.
Definition: inline_string.hpp:155
constexpr size_type size() const noexcept
Returns count of characters stored in this pmem::obj::string_view data.
Definition: string_view.hpp:334
Resides on pmem class.
Definition: p.hpp:35
A helper trait which calculates required memory capacity (in bytes) for a type.
Definition: inline_string.hpp:409
This class serves similar purpose to pmem::obj::string, but keeps the data within the same allocation...
Definition: inline_string.hpp:44
Persistent_ptr transactional allocation functions for objects.
Interface to access sequence of objects.
int compare(size_type pos1, size_type n1, basic_string_view sv) const
Compares two character sequences.
Definition: string_view.hpp:1018
C++ pmemobj transactions.
pointer data()
Returns pointer to the underlying data and if there is an active transaction add entire data to a tra...
Definition: inline_string.hpp:215
basic_inline_string(basic_string_view< CharT, Traits > v)
Constructs inline string from a string_view.
Definition: inline_string.hpp:104
reference at(size_type p)
Returns reference to a character at position.
Definition: inline_string.hpp:298
slice< pointer > range(size_type p, size_type count)
Returns slice and snapshots (if there is an active transaction) requested range.
Definition: inline_string.hpp:339
pmem::obj::slice - provides interface to access sequence of objects.
Definition: slice.hpp:50
pointer snapshotted_data(size_t p, size_t n)
Return pointer to data at position p and if there is an active transaction snapshot elements from p t...
Definition: inline_string.hpp:355
size_type size() const noexcept
Definition: inline_string.hpp:185
basic_inline_string & assign(basic_string_view< CharT, Traits > rhs)
Transactionally assign content of basic_string_view.
Definition: inline_string.hpp:372
constexpr const CharT * data() const noexcept
Returns pointer to data stored in this pmem::obj::string_view.
Definition: string_view.hpp:296
Volatile residing on pmem class.
Definition: v.hpp:42
const_pointer cdata() const noexcept
Returns const pointer to the underlying data.
Definition: inline_string.hpp:237
reference operator[](size_type p)
Returns reference to a character at position.
Definition: inline_string.hpp:268
The non-template pool base class.
Definition: pool.hpp:46
Persistent smart pointer.
static void run(obj::pool_base &pool, std::function< void()> tx, Locks &... locks)
Execute a closure-like transaction and lock locks.
Definition: transaction.hpp:817