Skip to content
This repository was archived by the owner on Mar 22, 2023. It is now read-only.

Commit 5b4a041

Browse files
docs: extend docs for Data View group and its classes
1 parent 58b7ce7 commit 5b4a041

File tree

8 files changed

+94
-33
lines changed

8 files changed

+94
-33
lines changed

doc/groups_definitions.dox

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,14 @@
183183
* @snippet inline_string/inline_string.cpp inline_string_example
184184
*/
185185

186-
/** @defgroup data_view Data View*/
186+
/** @defgroup data_view Data View
187+
* Various views of persistent objects
188+
*
189+
* Classes listed on this page provide (often simplified) views of persistent data.
190+
* They are delivered to ease the usage or for better performance. Please,
191+
* take a look at description of each class to get the details of their behavior.
192+
*/
193+
187194
/** @defgroup synchronization Synchronization Primitives*/
188195
/** @defgroup primitives Primitives*/
189196
/** @defgroup exceptions Exceptions

include/libpmemobj++/container/array.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ struct array {
487487
* @param[in] start start index of requested range.
488488
* @param[in] n number of elements in range.
489489
*
490-
* @return slice from start to start + n.
490+
* @return pmem::obj::slice from start to start + n.
491491
*
492492
* @throw std::out_of_range if any element of the range would be
493493
* outside of the array.
@@ -515,7 +515,7 @@ struct array {
515515
* added to a transaction. If value is equal to 0 no snapshotting
516516
* happens.
517517
*
518-
* @return slice from start to start + n.
518+
* @return pmem::obj::slice from start to start + n.
519519
*
520520
* @throw std::out_of_range if any element of the range would be
521521
* outside of the array.
@@ -543,7 +543,7 @@ struct array {
543543
* @param[in] start start index of requested range.
544544
* @param[in] n number of elements in range.
545545
*
546-
* @return slice from start to start + n.
546+
* @return pmem::obj::slice from start to start + n.
547547
*
548548
* @throw std::out_of_range if any element of the range would be
549549
* outside of the array.
@@ -564,7 +564,7 @@ struct array {
564564
* @param[in] start start index of requested range.
565565
* @param[in] n number of elements in range.
566566
*
567-
* @return slice from start to start + n.
567+
* @return pmem::obj::slice from start to start + n.
568568
*
569569
* @throw std::out_of_range if any element of the range would be
570570
* outside of the array.

include/libpmemobj++/container/basic_string.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,7 @@ typename basic_string<CharT, Traits>::const_reference
13971397
* @param[in] start start index of requested range.
13981398
* @param[in] n number of elements in range.
13991399
*
1400-
* @return slice containing elements from <start, start + n).
1400+
* @return pmem::obj::slice containing elements from <start, start + n).
14011401
*
14021402
* @throw std::out_of_range if any element of the range would be outside of the
14031403
* string.
@@ -1424,7 +1424,7 @@ basic_string<CharT, Traits>::range(size_type start, size_type n)
14241424
* entire range is added to a transaction. If value is equal to 0 no
14251425
* snapshotting happens.
14261426
*
1427-
* @return slice containing elements from <start, start + n).
1427+
* @return pmem::obj::slice containing elements from <start, start + n).
14281428
*
14291429
* @throw std::out_of_range if any element of the range would be outside of the
14301430
* string.
@@ -1451,7 +1451,7 @@ basic_string<CharT, Traits>::range(size_type start, size_type n,
14511451
* @param[in] start start index of requested range.
14521452
* @param[in] n number of elements in range.
14531453
*
1454-
* @return slice containing elements from <start, start + n).
1454+
* @return pmem::obj::slice containing elements from <start, start + n).
14551455
*
14561456
* @throw std::out_of_range if any element of the range would be outside of the
14571457
* string.
@@ -1469,7 +1469,7 @@ basic_string<CharT, Traits>::range(size_type start, size_type n) const
14691469
* @param[in] start start index of requested range.
14701470
* @param[in] n number of elements in range.
14711471
*
1472-
* @return slice containing elements from <start, start + n).
1472+
* @return pmem::obj::slice containing elements from <start, start + n).
14731473
*
14741474
* @throw std::out_of_range if any element of the range would be outside of the
14751475
* string.

include/libpmemobj++/container/segment_vector.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,7 @@ segment_vector<T, Policy>::crend() const noexcept
16441644
* @param[in] start start index of requested range.
16451645
* @param[in] n number of elements in range.
16461646
*
1647-
* @return slice from start to start + n.
1647+
* @return pmem::obj::slice from start to start + n.
16481648
*
16491649
* @throw std::out_of_range if any element of the range would be outside
16501650
* of the segment_vector.
@@ -1668,7 +1668,7 @@ segment_vector<T, Policy>::range(size_type start, size_type n)
16681668
* @param[in] start start index of requested range.
16691669
* @param[in] n number of elements in range.
16701670
*
1671-
* @return slice from start to start + n.
1671+
* @return pmem::obj::slice from start to start + n.
16721672
*
16731673
* @throw std::out_of_range if any element of the range would be outside
16741674
* of the segment_vector.
@@ -1689,7 +1689,7 @@ segment_vector<T, Policy>::range(size_type start, size_type n) const
16891689
* @param[in] start start index of requested range.
16901690
* @param[in] n number of elements in range.
16911691
*
1692-
* @return slice from start to start + n.
1692+
* @return pmem::obj::slice from start to start + n.
16931693
*
16941694
* @throw std::out_of_range if any element of the range would be outside
16951695
* of the segment_vector.

include/libpmemobj++/container/vector.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ vector<T>::crend() const noexcept
12341234
* @param[in] start start index of requested range.
12351235
* @param[in] n number of elements in range.
12361236
*
1237-
* @return slice from start to start + n.
1237+
* @return pmem::obj::slice from start to start + n.
12381238
*
12391239
* @throw std::out_of_range if any element of the range would be outside of the
12401240
* vector.
@@ -1263,7 +1263,7 @@ vector<T>::range(size_type start, size_type n)
12631263
* entire range is added to a transaction. If value is equal to 0 no
12641264
* snapshotting happens.
12651265
*
1266-
* @return slice from start to start + n.
1266+
* @return pmem::obj::slice from start to start + n.
12671267
*
12681268
* @throw std::out_of_range if any element of the range would be outside of the
12691269
* vector.
@@ -1292,7 +1292,7 @@ vector<T>::range(size_type start, size_type n, size_type snapshot_size)
12921292
* @param[in] start start index of requested range.
12931293
* @param[in] n number of elements in range.
12941294
*
1295-
* @return slice from start to start + n.
1295+
* @return pmem::obj::slice from start to start + n.
12961296
*
12971297
* @throw std::out_of_range if any element of the range would be outside of the
12981298
* vector.
@@ -1314,7 +1314,7 @@ vector<T>::range(size_type start, size_type n) const
13141314
* @param[in] start start index of requested range.
13151315
* @param[in] n number of elements in range.
13161316
*
1317-
* @return slice from start to start + n.
1317+
* @return pmem::obj::slice from start to start + n.
13181318
*
13191319
* @throw std::out_of_range if any element of the range would be outside of the
13201320
* vector.

include/libpmemobj++/experimental/inline_string.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ basic_inline_string_base<CharT, Traits>::at(size_type p) const
478478
* @param[in] start start index of requested range.
479479
* @param[in] n number of elements in range.
480480
*
481-
* @return slice from start to start + n.
481+
* @return pmem::obj::slice from start to start + n.
482482
*
483483
* @throw std::out_of_range if any element of the range would be outside of the
484484
* container.

include/libpmemobj++/slice.hpp

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,18 @@ namespace obj
4343
{
4444

4545
/**
46-
* pmem::obj::slice - provides interface to access
47-
* sequence of objects.
46+
* Provides interface to access sequence of objects.
47+
*
48+
* It provides the view of any sequence of objects and it simplifies the
49+
* access to that sequence, with the help of iterators. It's used e.g. in
50+
* several data structures to deliver `range` methods. As an example slice
51+
* usage please see: pmem::obj::vector::range() .
52+
*
53+
* Slice can be used with any iterator type that supports:
54+
* - indexing of elements - operator[],
55+
* - subtraction of two iterators - operator-(),
56+
* - pre-decrementing the iterator - operator--().
57+
*
4858
* @ingroup data_view
4959
*/
5060
template <typename Iterator>
@@ -56,8 +66,10 @@ class slice {
5666
using reference = typename std::iterator_traits<iterator>::reference;
5767

5868
/**
59-
* Constructor taking two iterators (iterators should support:
60-
* operator[], operator-(), operator--()) which define a range.
69+
* Constructor taking two iterators, which define a range.
70+
*
71+
* @note These iterators have to support: operator[], operator-(), and
72+
* operator--()
6173
*
6274
* @throw std::out_of_range if it_end < it_begin.
6375
*/
@@ -85,7 +97,7 @@ class slice {
8597
slice &operator=(const slice &other) noexcept = default;
8698

8799
/**
88-
* Returns iterator to the beginning of the range.
100+
* @return iterator to the beginning of the slice's range.
89101
*/
90102
iterator
91103
begin() const noexcept
@@ -94,7 +106,7 @@ class slice {
94106
}
95107

96108
/**
97-
* Returns iterator to the end of the range.
109+
* @return iterator to the end of the slice's range.
98110
*/
99111
iterator
100112
end() const noexcept
@@ -103,27 +115,39 @@ class slice {
103115
}
104116

105117
/**
106-
* Returns reverse iterator to the end.
118+
* Returns a reverse_iterator to the last element in the range. Reverse
119+
* iterators iterate backwards: increasing them moves them towards the
120+
* beginning of the range.
121+
*
122+
* @return reverse_iterator to the reverse beginning of the slice's
123+
* range.
107124
*/
108125
reverse_iterator
109-
rend() const noexcept
126+
rbegin() const noexcept
110127
{
111-
return reverse_iterator(it_begin);
128+
return reverse_iterator(it_end);
112129
}
113130

114131
/**
115-
* Returns reverse iterator to the beginning.
132+
* Returns a reverse_iterator to the first element in the range. Reverse
133+
* iterators iterate backwards: increasing them moves them towards the
134+
* beginning of the range.
135+
*
136+
* @return reverse_iterator to the reverse end of the slice's range.
116137
*/
117138
reverse_iterator
118-
rbegin() const noexcept
139+
rend() const noexcept
119140
{
120-
return reverse_iterator(it_end);
141+
return reverse_iterator(it_begin);
121142
}
122143

123144
/**
124-
* Element access operator.
145+
* Access operator for a single element of slice.
146+
*
147+
* @param idx index of selected element.
125148
*
126149
* @throw std::out_of_range if idx is greater or equal to size.
150+
* @return reference to a selected object.
127151
*/
128152
reference
129153
at(size_type idx)
@@ -136,15 +160,25 @@ class slice {
136160
}
137161

138162
/**
139-
* Element access operator.
140-
* No bounds checking is performed.
163+
* Subscript operator, providing access to a single element of the
164+
* slice. It internally increments from begin iterator, @param idx
165+
* positions forward.
166+
*
167+
* @note No bounds checking is performed, so the iterator may become
168+
* invalid.
169+
* @return reference to a selected object.
141170
*/
142171
reference operator[](size_type idx)
143172
{
144173
return it_begin[static_cast<typename std::iterator_traits<
145174
Iterator>::difference_type>(idx)];
146175
}
147176

177+
/**
178+
* Returns total number of elements within slice's range.
179+
*
180+
* @return size_type count of all elements.
181+
*/
148182
size_type
149183
size() const
150184
{

include/libpmemobj++/string_view.hpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ using u32string_view = std::basic_string_view<char32_t>;
4040
* Our partial std::string_view implementation.
4141
*
4242
* If C++17's std::string_view implementation is not available, this one
43-
* is used to avoid unnecessary string copying.
43+
* is used to avoid unnecessary string copying. It's compatible with
44+
* the std API, but it does not cover all functionalities.
4445
* @ingroup data_view
4546
*/
4647
template <typename CharT, typename Traits = std::char_traits<CharT>>
@@ -161,9 +162,28 @@ class basic_string_view {
161162
size_type size_;
162163
};
163164

165+
/**
166+
* The most typical string_view usage - the char specialization.
167+
* @ingroup data_view
168+
*/
164169
using string_view = basic_string_view<char>;
170+
171+
/**
172+
* The wide char specialization.
173+
* @ingroup data_view
174+
*/
165175
using wstring_view = basic_string_view<wchar_t>;
176+
177+
/**
178+
* The char16 specialization.
179+
* @ingroup data_view
180+
*/
166181
using u16string_view = basic_string_view<char16_t>;
182+
183+
/**
184+
* The char32 specialization.
185+
* @ingroup data_view
186+
*/
167187
using u32string_view = basic_string_view<char32_t>;
168188

169189
/**

0 commit comments

Comments
 (0)