Skip to content

Commit 81dbd03

Browse files
authored
Merge pull request #5392 from pan-/improve-ble-docs
Improve ble docs
2 parents eb5d3ff + 3dc28ce commit 81dbd03

27 files changed

+5628
-2630
lines changed

features/FEATURE_BLE/ble/ArrayView.h

Lines changed: 139 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,72 +20,141 @@
2020
#include <stddef.h>
2121
#include <stdint.h>
2222

23+
/**
24+
* @addtogroup ble
25+
* @{
26+
* @addtogroup common
27+
* @{
28+
*/
29+
30+
/**
31+
* @file
32+
*/
33+
2334
namespace ble {
2435

2536
/**
2637
* Immutable view to an array.
38+
*
39+
* Array views encapsulate the pointer to an array and its size into a single
40+
* object; however, it does not manage the lifetime of the array viewed.
41+
* You can use instances of ArrayView to replace the traditional pair of pointer
42+
* and size arguments in function calls.
43+
*
44+
* You can use the size member function to query the number of elements present
45+
* in the array, and overloads of the subscript operator allow code using
46+
* this object to access to the content of the array viewed.
47+
*
48+
* @note You can create ArrayView instances with the help of the function
49+
* template make_ArrayView() and make_const_ArrayView().
50+
*
51+
* @tparam T type of objects held by the array.
2752
*/
2853
template<typename T>
2954
struct ArrayView {
3055

3156
/**
32-
* construct an array view to an empty array
57+
* Construct a view to an empty array.
58+
*
59+
* @post a call to size() will return 0, and data() will return NULL.
3360
*/
3461
ArrayView() : _array(0), _size(0) { }
3562

3663
/**
37-
* construct an array view from a pointer.
38-
* and its size.
64+
* Construct an array view from a pointer to a buffer and its size.
65+
*
66+
* @param array_ptr Pointer to the array data
67+
* @param array_size Number of elements of T present in the array.
68+
*
69+
* @post a call to size() will return array_size and data() will return
70+
* array_tpr.
3971
*/
4072
ArrayView(T* array_ptr, size_t array_size) :
4173
_array(array_ptr), _size(array_size) { }
4274

4375
/**
4476
* Construct an array view from the reference to an array.
77+
*
78+
* @param elements Reference to the array viewed.
79+
*
80+
* @tparam Size Number of elements of T presents in the array.
81+
*
82+
* @post a call to size() will return Size, and data() will return
83+
* a pointer to elements.
4584
*/
4685
template<size_t Size>
4786
ArrayView(T (&elements)[Size]):
4887
_array(elements), _size(Size) { }
4988

5089
/**
5190
* Return the size of the array viewed.
91+
*
92+
* @return The number of elements present in the array viewed.
5293
*/
53-
size_t size() const {
94+
size_t size() const
95+
{
5496
return _size;
5597
}
5698

5799
/**
58100
* Access to a mutable element of the array.
101+
*
102+
* @param index Element index to access.
103+
*
104+
* @return A reference to the element at the index specified in input.
105+
*
106+
* @pre index shall be less than size().
59107
*/
60-
T& operator[](size_t index) {
108+
T& operator[](size_t index)
109+
{
61110
return _array[index];
62111
}
63112

64113
/**
65114
* Access to an immutable element of the array.
115+
*
116+
* @param index Element index to access.
117+
*
118+
* @return A const reference to the element at the index specified in input.
119+
*
120+
* @pre index shall be less than size().
66121
*/
67-
const T& operator[](size_t index) const {
122+
const T& operator[](size_t index) const
123+
{
68124
return _array[index];
69125
}
70126

71127
/**
72-
* Get the pointer to the array
128+
* Get the raw pointer to the array.
129+
*
130+
* @return The raw pointer to the array.
73131
*/
74-
T* data() {
132+
T* data()
133+
{
75134
return _array;
76135
}
77136

78137
/**
79-
* Get the pointer to the const array
138+
* Get the raw const pointer to the array.
139+
*
140+
* @return The raw pointer to the array.
80141
*/
81-
const T* data() const {
142+
const T* data() const
143+
{
82144
return _array;
83145
}
84146

85147
/**
86-
* Equality operator
148+
* Equality operator.
149+
*
150+
* @param lhs Left hand side of the binary operation.
151+
* @param rhs Right hand side of the binary operation.
152+
*
153+
* @return True if arrays in input have the same size and the same content
154+
* and false otherwise.
87155
*/
88-
friend bool operator==(const ArrayView& lhs, const ArrayView& rhs) {
156+
friend bool operator==(const ArrayView& lhs, const ArrayView& rhs)
157+
{
89158
if (lhs.size() != rhs.size()) {
90159
return false;
91160
}
@@ -99,8 +168,15 @@ struct ArrayView {
99168

100169
/**
101170
* Not equal operator
171+
*
172+
* @param lhs Left hand side of the binary operation.
173+
* @param rhs Right hand side of the binary operation.
174+
*
175+
* @return True if arrays in input do not have the same size or the same
176+
* content and false otherwise.
102177
*/
103-
friend bool operator!=(const ArrayView& lhs, const ArrayView& rhs) {
178+
friend bool operator!=(const ArrayView& lhs, const ArrayView& rhs)
179+
{
104180
return !(lhs == rhs);
105181
}
106182

@@ -111,55 +187,86 @@ struct ArrayView {
111187

112188

113189
/**
114-
* Generate an array view from a C/C++ array.
115-
* This helper avoid the typing of template parameter when ArrayView are
190+
* Generate an array view from a reference to a C/C++ array.
191+
*
192+
* @tparam T Type of elements held in elements.
193+
* @tparam Size Number of items held in elements.
194+
*
195+
* @param elements The reference to the array viewed.
196+
*
197+
* @return The ArrayView to elements.
198+
*
199+
* @note This helper avoids the typing of template parameter when ArrayView is
116200
* created 'inline'.
117-
* @param elements The array viewed.
118-
* @return The array_view to elements.
119201
*/
120202
template<typename T, size_t Size>
121-
ArrayView<T> make_ArrayView(T (&elements)[Size]) {
203+
ArrayView<T> make_ArrayView(T (&elements)[Size])
204+
{
122205
return ArrayView<T>(elements);
123206
}
124207

125208
/**
126209
* Generate an array view from a C/C++ pointer and the size of the array.
127-
* This helper avoid the typing of template parameter when ArrayView are
210+
*
211+
* @tparam T Type of elements held in array_ptr.
212+
*
213+
* @param array_ptr The pointer to the array to viewed.
214+
* @param array_size The number of T elements in the array.
215+
*
216+
* @return The ArrayView to array_ptr with a size of array_size.
217+
*
218+
* @note This helper avoids the typing of template parameter when ArrayView is
128219
* created 'inline'.
129-
* @param array_ptr The pointer to the array to view.
130-
* @param array_size The size of the array.
131-
* @return The array_view to array_ptr with a size of array_size.
132220
*/
133221
template<typename T>
134-
ArrayView<T> make_ArrayView(T* array_ptr, size_t array_size) {
222+
ArrayView<T> make_ArrayView(T* array_ptr, size_t array_size)
223+
{
135224
return ArrayView<T>(array_ptr, array_size);
136225
}
137226

138227
/**
139-
* Generate a const array view from a C/C++ array.
140-
* This helper avoid the typing of template parameter when ArrayView are
141-
* created 'inline'.
228+
* Generate a const array view from a reference to a C/C++ array.
229+
*
230+
* @tparam T Type of elements held in elements.
231+
* @tparam Size Number of items held in elements.
232+
*
142233
* @param elements The array viewed.
143234
* @return The ArrayView to elements.
235+
*
236+
* @note This helper avoids the typing of template parameter when ArrayView is
237+
* created 'inline'.
144238
*/
145239
template<typename T, size_t Size>
146-
ArrayView<const T> make_const_ArrayView(T (&elements)[Size]) {
240+
ArrayView<const T> make_const_ArrayView(T (&elements)[Size])
241+
{
147242
return ArrayView<const T>(elements);
148243
}
149244

150245
/**
151246
* Generate a const array view from a C/C++ pointer and the size of the array.
152-
* This helper avoid the typing of template parameter when ArrayView are
153-
* created 'inline'.
154-
* @param array_ptr The pointer to the array to view.
155-
* @param array_size The size of the array.
247+
*
248+
* @tparam T Type of elements held in array_ptr.
249+
*
250+
* @param array_ptr The pointer to the array to viewed.
251+
* @param array_size The number of T elements in the array.
252+
*
156253
* @return The ArrayView to array_ptr with a size of array_size.
254+
*
255+
* @note This helper avoids the typing of template parameter when ArrayView is
256+
* created 'inline'.
157257
*/
158258
template<typename T>
159-
ArrayView<const T> make_const_ArrayView(T* array_ptr, size_t array_size) {
259+
ArrayView<const T> make_const_ArrayView(T* array_ptr, size_t array_size)
260+
{
160261
return ArrayView<const T>(array_ptr, array_size);
161262
}
162263

163264
} // namespace ble
164265

266+
/**
267+
* @}
268+
* @}
269+
*/
270+
271+
165272
#endif /* BLE_ARRAY_VIEW_H_ */

0 commit comments

Comments
 (0)