Skip to content

Commit e981a92

Browse files
committed
Fixup for PR.
1 parent 6eec102 commit e981a92

File tree

6 files changed

+247
-122
lines changed

6 files changed

+247
-122
lines changed

include/rcutils/types/array_list.h

+98-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2017 Open Source Robotics Foundation, Inc.
1+
// Copyright 2018-2019 Open Source Robotics Foundation, Inc.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -34,6 +34,19 @@ typedef struct RCUTILS_PUBLIC_TYPE rcutils_array_list_t
3434
struct rcutils_array_list_impl_t * impl;
3535
} rcutils_array_list_t;
3636

37+
/**
38+
* Validates that an rcutils_array_list_t* points to a valid array list.
39+
* \param array_list A pointer to an rcutils_array_list_t
40+
* \return RCUTILS_RET_INVALID_ARGUMENT if array_list is null
41+
* \return RCUTILS_RET_NOT_INITIALIZED if array_list is not initialized
42+
*/
43+
#define ARRAY_LIST_VALIDATE_ARRAY_LIST(array_list) \
44+
RCUTILS_CHECK_ARGUMENT_FOR_NULL(array_list, RCUTILS_RET_INVALID_ARGUMENT); \
45+
if (NULL == array_list->impl) { \
46+
RCUTILS_SET_ERROR_MSG("array_list is not initialized"); \
47+
return RCUTILS_RET_NOT_INITIALIZED; \
48+
}
49+
3750
/// Return an empty array_list struct.
3851
/**
3952
* This function returns an empty and zero initialized array_list struct.
@@ -42,6 +55,14 @@ typedef struct RCUTILS_PUBLIC_TYPE rcutils_array_list_t
4255
* Every instance of array_list_t has to either be zero_initialized with this
4356
* function or manually allocated.
4457
*
58+
* <hr>
59+
* Attribute | Adherence
60+
* ------------------ | -------------
61+
* Allocates Memory | No
62+
* Thread-Safe | Yes
63+
* Uses Atomics | No
64+
* Lock-Free | Yes
65+
*
4566
* Example:
4667
*
4768
* ```c
@@ -56,25 +77,36 @@ RCUTILS_PUBLIC
5677
rcutils_array_list_t
5778
rcutils_get_zero_initialized_array_list(void);
5879

59-
/// Initialize an array liast with a given initial capacity.
80+
/// Initialize an array list with a given initial capacity.
6081
/**
61-
* This function will initialize a given, zero initialized, string array to
82+
* This function will initialize a given, zero initialized, array_list to
6283
* a given size.
6384
*
64-
* Note that putting a string into the array gives owenship to the array.
85+
* <hr>
86+
* Attribute | Adherence
87+
* ------------------ | -------------
88+
* Allocates Memory | Yes
89+
* Thread-Safe | No
90+
* Uses Atomics | No
91+
* Lock-Free | Yes
6592
*
6693
* Example:
6794
*
6895
* ```c
6996
* rcutils_allocator_t allocator = rcutils_get_default_allocator();
7097
* rcutils_array_list_t array_list = rcutils_get_zero_initialized_array_list();
71-
* rcutils_ret_t ret = rcutils_array_list_init(&array_list, 2, &allocator);
98+
* rcutils_ret_t ret = rcutils_array_list_init(&array_list, 2, sizeof(int), &allocator);
7299
* if (ret != RCUTILS_RET_OK) {
73100
* // ... error handling
74101
* }
75-
* array_list.data[0] = rcutils_strdup("Hello", &allocator);
76-
* array_list.data[1] = rcutils_strdup("World", &allocator);
102+
* int data = 42;
103+
* int out_data = 0;
104+
* ret = rcutils_array_list_add(&array_list, &data);
105+
* data++;
106+
* ret = rcutils_array_list_get(&array_list, 0, &out_data);
107+
* assert(42 == out_data);
77108
* ret = rcutils_array_list_fini(&array_list);
109+
* ```
78110
*
79111
* \param[inout] array_list object to be initialized
80112
* \param[in] initial_capacity the initial capacity to allocate in the list
@@ -84,7 +116,6 @@ rcutils_get_zero_initialized_array_list(void);
84116
* \return `RCUTILS_RET_INVALID_ARGUMENT` for invalid arguments, or
85117
* \return `RCUTILS_RET_BAD_ALLOC` if memory allocation fails, or
86118
* \return `RCUTILS_RET_ERROR` if an unknown error occurs
87-
* ```
88119
*/
89120
RCUTILS_PUBLIC
90121
rcutils_ret_t
@@ -94,13 +125,20 @@ rcutils_array_list_init(
94125
size_t data_size,
95126
const rcutils_allocator_t * allocator);
96127

97-
/// Finalize a string array, reclaiming all resources.
128+
/// Finalize an array list, reclaiming all resources.
98129
/**
99-
* This function reclaims any memory owned by the string array, including the
100-
* strings it references.
130+
* This function reclaims any memory owned by the array list.
101131
*
102-
* The allocator used to initialize the string array is used to deallocate each
103-
* string in the array and the array of strings itself.
132+
* The allocator used to initialize the array list is used to deallocate each
133+
* entry in the list and the list itself.
134+
*
135+
* <hr>
136+
* Attribute | Adherence
137+
* ------------------ | -------------
138+
* Allocates Memory | No
139+
* Thread-Safe | No
140+
* Uses Atomics | No
141+
* Lock-Free | Yes
104142
*
105143
* \param[inout] array_list object to be finalized
106144
* \return `RCUTILS_RET_OK` if successful, or
@@ -114,10 +152,17 @@ rcutils_array_list_fini(rcutils_array_list_t * array_list);
114152

115153
/// Adds an entry to the list
116154
/**
117-
* This functions adds the provided data to the end of the list. A copy of
155+
* This function adds the provided data to the end of the list. A shallow copy of
118156
* the provided data is made to store in the list instead of just storing
119157
* the pointer to the provided data.
120158
*
159+
* <hr>
160+
* Attribute | Adherence
161+
* ------------------ | -------------
162+
* Allocates Memory | Yes
163+
* Thread-Safe | No
164+
* Uses Atomics | No
165+
* Lock-Free | Yes
121166
*
122167
* \param[in] array_list to add the data to
123168
* \param[in] data a pointer to the data to add to the list
@@ -133,16 +178,24 @@ rcutils_array_list_add(rcutils_array_list_t * array_list, const void * data);
133178

134179
/// Sets an entry in the list to the provided data
135180
/**
136-
* This functions sets the provided data at the specified index in the list. A copy of
137-
* the provided data is made to store in the list instead of just storing
138-
* the pointer to the provided data.
181+
* This function sets the provided data at the specified index in the list.
182+
* A shallow copy of the provided data is made to store in the list instead
183+
* of just storing the pointer to the provided data.
139184
*
185+
* <hr>
186+
* Attribute | Adherence
187+
* ------------------ | -------------
188+
* Allocates Memory | No
189+
* Thread-Safe | No
190+
* Uses Atomics | No
191+
* Lock-Free | Yes
140192
*
141193
* \param[in] array_list to add the data to
142194
* \param[in] index the position in the list to set the data
143195
* \param[in] data a pointer to the data that will be set in the list
144196
* \return `RCUTILS_RET_OK` if successful, or
145197
* \return `RCUTILS_RET_INVALID_ARGUMENT` for invalid arguments, or
198+
* \return `RCUTILS_RET_INVALID_ARGUMENT` if index out of bounds, or
146199
* \return `RCUTILS_RET_BAD_ALLOC` if memory allocation fails, or
147200
* \return `RCUTILS_RET_ERROR` if an unknown error occurs
148201
*/
@@ -153,12 +206,21 @@ rcutils_array_list_set(rcutils_array_list_t * array_list, size_t index, const vo
153206

154207
/// Removes an entry in the list at the provided index
155208
/**
156-
* This functions removes data from the list at the specified index.
209+
* This function removes data from the list at the specified index. The capacity
210+
* of the list will never decrease when entries are removed.
157211
*
212+
* <hr>
213+
* Attribute | Adherence
214+
* ------------------ | -------------
215+
* Allocates Memory | No
216+
* Thread-Safe | No
217+
* Uses Atomics | No
218+
* Lock-Free | Yes
158219
*
159220
* \param[in] array_list to add the data to
160221
* \return `RCUTILS_RET_OK` if successful, or
161222
* \return `RCUTILS_RET_INVALID_ARGUMENT` for invalid arguments, or
223+
* \return `RCUTILS_RET_INVALID_ARGUMENT` if index out of bounds, or
162224
* \return `RCUTILS_RET_BAD_ALLOC` if memory allocation fails, or
163225
* \return `RCUTILS_RET_ERROR` if an unknown error occurs
164226
*/
@@ -169,7 +231,15 @@ rcutils_array_list_remove(rcutils_array_list_t * array_list, size_t index);
169231

170232
/// Retrieves an entry in the list at the provided index
171233
/**
172-
* This functions retrieves a copy of the data stored in the list.
234+
* This function retrieves a copy of the data stored in the list at the provided index.
235+
*
236+
* <hr>
237+
* Attribute | Adherence
238+
* ------------------ | -------------
239+
* Allocates Memory | No
240+
* Thread-Safe | No
241+
* Uses Atomics | No
242+
* Lock-Free | Yes
173243
*
174244
*
175245
* \param[in] array_list to add the data to
@@ -187,7 +257,15 @@ rcutils_array_list_get(const rcutils_array_list_t * array_list, size_t index, vo
187257

188258
/// Retrieves the size of the provided array_list
189259
/**
190-
* This functions retrieves the size of the provided array list
260+
* This function retrieves the number of items in the provided array list
261+
*
262+
* <hr>
263+
* Attribute | Adherence
264+
* ------------------ | -------------
265+
* Allocates Memory | No
266+
* Thread-Safe | No
267+
* Uses Atomics | No
268+
* Lock-Free | Yes
191269
*
192270
*
193271
* \param[in] array_list list to get the size of

0 commit comments

Comments
 (0)