|
1 | 1 | // SPDX-License-Identifier: BSD-3-Clause |
2 | | -/* Copyright 2020, Intel Corporation */ |
| 2 | +/* Copyright 2020-2021, Intel Corporation */ |
3 | 3 |
|
4 | 4 | /** |
5 | 5 | * @file |
@@ -30,6 +30,9 @@ namespace experimental |
30 | 30 | * This class serves similar purpose to pmem::obj::string, but |
31 | 31 | * keeps the data within the same allocation as inline_string itself. |
32 | 32 | * |
| 33 | + * Unlike other containers, it can be used on pmem and dram. Modifiers (like |
| 34 | + * assign()) can only be called if inline string is kept on pmem). |
| 35 | + * |
33 | 36 | * The data is always kept right after the inline_string structure. |
34 | 37 | * It means that creating an object of inline_string must be done |
35 | 38 | * as follows: |
@@ -97,50 +100,35 @@ using inline_u32string = basic_inline_string<char32_t>; |
97 | 100 |
|
98 | 101 | /** |
99 | 102 | * Constructs inline string from a string_view. |
100 | | - * |
101 | | - * @throw pool_error if inline_string doesn't reside on pmem. |
102 | 103 | */ |
103 | 104 | template <typename CharT, typename Traits> |
104 | 105 | basic_inline_string<CharT, Traits>::basic_inline_string( |
105 | 106 | basic_string_view<CharT, Traits> v) |
106 | 107 | : size_(v.size()), capacity_(v.size()) |
107 | 108 | { |
108 | | - if (nullptr == pmemobj_pool_by_ptr(this)) |
109 | | - throw pmem::pool_error("Invalid pool handle."); |
110 | | - |
111 | 109 | std::copy(v.data(), v.data() + static_cast<ptrdiff_t>(size_), data()); |
112 | 110 |
|
113 | 111 | data()[static_cast<ptrdiff_t>(size_)] = '\0'; |
114 | 112 | } |
115 | 113 |
|
116 | 114 | /** |
117 | 115 | * Constructs empty inline_string with specified capacity. |
118 | | - * |
119 | | - * @throw pool_error if inline_string doesn't reside on pmem. |
120 | 116 | */ |
121 | 117 | template <typename CharT, typename Traits> |
122 | 118 | basic_inline_string<CharT, Traits>::basic_inline_string(size_type capacity) |
123 | 119 | : size_(0), capacity_(capacity) |
124 | 120 | { |
125 | | - if (nullptr == pmemobj_pool_by_ptr(this)) |
126 | | - throw pmem::pool_error("Invalid pool handle."); |
127 | | - |
128 | 121 | data()[static_cast<ptrdiff_t>(size_)] = '\0'; |
129 | 122 | } |
130 | 123 |
|
131 | 124 | /** |
132 | 125 | * Copy constructor |
133 | | - * |
134 | | - * @throw pool_error if inline_string doesn't reside on pmem. |
135 | 126 | */ |
136 | 127 | template <typename CharT, typename Traits> |
137 | 128 | basic_inline_string<CharT, Traits>::basic_inline_string( |
138 | 129 | const basic_inline_string &rhs) |
139 | 130 | : size_(rhs.size()), capacity_(rhs.capacity()) |
140 | 131 | { |
141 | | - if (nullptr == pmemobj_pool_by_ptr(this)) |
142 | | - throw pmem::pool_error("Invalid pool handle."); |
143 | | - |
144 | 132 | std::copy(rhs.data(), rhs.data() + static_cast<ptrdiff_t>(size_), |
145 | 133 | data()); |
146 | 134 |
|
@@ -366,12 +354,17 @@ basic_inline_string<CharT, Traits>::snapshotted_data(size_t p, size_t n) |
366 | 354 | * Transactionally assign content of basic_string_view. |
367 | 355 | * |
368 | 356 | * @throw std::out_of_range if rhs is larger than capacity. |
| 357 | + * @throw pool_error if inline string is not on pmem. |
369 | 358 | */ |
370 | 359 | template <typename CharT, typename Traits> |
371 | 360 | basic_inline_string<CharT, Traits> & |
372 | 361 | basic_inline_string<CharT, Traits>::assign(basic_string_view<CharT, Traits> rhs) |
373 | 362 | { |
374 | | - auto pop = obj::pool_base(pmemobj_pool_by_ptr(this)); |
| 363 | + auto cpop = pmemobj_pool_by_ptr(this); |
| 364 | + if (nullptr == cpop) |
| 365 | + throw pmem::pool_error("Invalid pool handle."); |
| 366 | + |
| 367 | + auto pop = pool_base(cpop); |
375 | 368 |
|
376 | 369 | if (rhs.size() > capacity()) |
377 | 370 | throw std::out_of_range("inline_string capacity exceeded."); |
|
0 commit comments