9 #ifndef LIBPMEMOBJ_CPP_INLINE_STRING_HPP 10 #define LIBPMEMOBJ_CPP_INLINE_STRING_HPP 25 namespace experimental
42 template <
typename CharT,
typename Traits = std::
char_traits<CharT>>
45 using traits_type = Traits;
46 using value_type = CharT;
47 using size_type = std::size_t;
48 using difference_type = std::ptrdiff_t;
49 using reference = value_type &;
50 using const_reference =
const value_type &;
51 using pointer = value_type *;
52 using const_pointer =
const value_type *;
66 size_type
size()
const noexcept;
69 pointer
data() noexcept;
70 const_pointer
data()
const noexcept;
93 template <
typename CharT,
typename Traits>
96 : size_(v.
size()), capacity_(v.
size())
98 if (
nullptr == pmemobj_pool_by_ptr(
this))
101 std::copy(v.
data(), v.
data() +
static_cast<ptrdiff_t
>(size_),
data());
103 data()[
static_cast<ptrdiff_t
>(size_)] =
'\0';
111 template <
typename CharT,
typename Traits>
113 : size_(0), capacity_(capacity)
115 if (
nullptr == pmemobj_pool_by_ptr(
this))
118 data()[
static_cast<ptrdiff_t
>(size_)] =
'\0';
126 template <
typename CharT,
typename Traits>
131 if (
nullptr == pmemobj_pool_by_ptr(
this))
134 std::copy(rhs.
data(), rhs.
data() +
static_cast<ptrdiff_t
>(size_),
137 data()[
static_cast<ptrdiff_t
>(size_)] =
'\0';
143 template <
typename CharT,
typename Traits>
156 template <
typename CharT,
typename Traits>
165 template <
typename CharT,
typename Traits>
173 template <
typename CharT,
typename Traits>
174 typename basic_inline_string<CharT, Traits>::size_type
187 template <
typename CharT,
typename Traits>
188 typename basic_inline_string<CharT, Traits>::size_type
195 template <
typename CharT,
typename Traits>
196 typename basic_inline_string<CharT, Traits>::pointer
199 return reinterpret_cast<CharT *
>(
this + 1);
203 template <
typename CharT,
typename Traits>
204 typename basic_inline_string<CharT, Traits>::const_pointer
207 return reinterpret_cast<const CharT *
>(
this + 1);
218 template <
typename CharT,
typename Traits>
231 template <
typename CharT,
typename Traits>
242 template <
typename CharT,
typename Traits>
249 throw std::out_of_range(
"inline_string capacity exceeded.");
251 auto initialized_mem =
252 (std::min)(rhs.
size(),
size()) + 1 ;
255 detail::conditional_add_to_tx(
data(), initialized_mem);
258 detail::conditional_add_to_tx(
259 data() + initialized_mem,
260 rhs.
size() - initialized_mem + 1,
261 POBJ_XADD_NO_SNAPSHOT);
263 std::copy(rhs.
data(),
264 rhs.
data() +
static_cast<ptrdiff_t
>(rhs.
size()),
268 data()[
static_cast<ptrdiff_t
>(size_)] =
'\0';
280 template <
typename T>
282 template <
typename... Args>
284 value(
const Args &... args)
297 template <
typename CharT,
typename Traits>
303 (s.
size() + 1 ) *
sizeof(CharT);
size_type size() const noexcept
Definition: inline_string.hpp:175
This class serves similar purpose to pmem::obj::string, but keeps the data within the same allocation...
Definition: inline_string.hpp:43
Persistent_ptr transactional allocation functions for objects.
The non-template pool base class.
Definition: pool.hpp:46
A helper trait which calculates required memory capacity (in bytes) for a type.
Definition: inline_string.hpp:281
pointer data() noexcept
Definition: inline_string.hpp:197
Custom pool error class.
Definition: pexceptions.hpp:45
CharT & operator[](size_type p) noexcept
Returns reference to a character at position.
Definition: inline_string.hpp:232
Volatile residing on pmem class.
Definition: v.hpp:42
C++ pmemobj transactions.
basic_inline_string & assign(basic_string_view< CharT, Traits > rhs)
Transactionally assign content of basic_string_view.
Definition: inline_string.hpp:244
size_type size() const noexcept
Returns count of characters stored in this pmem::obj::string_view data.
Definition: string_view.hpp:150
const CharT * data() const noexcept
Returns pointer to data stored in this pmem::obj::string_view.
Definition: string_view.hpp:137
basic_inline_string & operator=(const basic_inline_string &rhs)
Copy assignment operator.
Definition: inline_string.hpp:145
Our partial std::string_view implementation.
Persistent smart pointer.
Resides on pmem class.
Definition: p.hpp:35
Our partial std::string_view implementation.
Definition: string_view.hpp:43
size_type capacity() const noexcept
Definition: inline_string.hpp:189
basic_inline_string(basic_string_view< CharT, Traits > v)
Constructs inline string from a string_view.
Definition: inline_string.hpp:94
int compare(const basic_inline_string &rhs) const noexcept
Compares this inline_string with other.
Definition: inline_string.hpp:220
Persistent memory namespace.
Definition: allocation_flag.hpp:14
static void run(pool_base &pool, std::function< void()> tx, Locks &... locks)
Execute a closure-like transaction and lock locks.
Definition: transaction.hpp:406