rcutils  master
C API providing common utilities and data structures.
array_list.h
Go to the documentation of this file.
1 // Copyright 2018-2019 Open Source Robotics Foundation, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef RCUTILS__TYPES__ARRAY_LIST_H_
16 #define RCUTILS__TYPES__ARRAY_LIST_H_
17 
18 #ifdef __cplusplus
19 extern "C"
20 {
21 #endif
22 
23 #include <string.h>
24 
25 #include "rcutils/allocator.h"
26 #include "rcutils/macros.h"
29 
30 struct rcutils_array_list_impl_t;
31 
33 {
34  struct rcutils_array_list_impl_t * impl;
36 
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 
51 
79 
81 
123  rcutils_array_list_t * array_list,
124  size_t initial_capacity,
125  size_t data_size,
126  const rcutils_allocator_t * allocator);
127 
129 
152 
154 
177 rcutils_array_list_add(rcutils_array_list_t * array_list, const void * data);
178 
180 
204 rcutils_array_list_set(rcutils_array_list_t * array_list, size_t index, const void * data);
205 
207 
229 rcutils_array_list_remove(rcutils_array_list_t * array_list, size_t index);
230 
232 
254 rcutils_array_list_get(const rcutils_array_list_t * array_list, size_t index, void * data);
255 
257 
278 rcutils_array_list_get_size(const rcutils_array_list_t * array_list, size_t * size);
279 
280 #ifdef __cplusplus
281 }
282 #endif
283 
284 #endif // RCUTILS__TYPES__ARRAY_LIST_H_
rcutils_ret_t rcutils_array_list_init(rcutils_array_list_t *array_list, size_t initial_capacity, size_t data_size, const rcutils_allocator_t *allocator)
Initialize an array list with a given initial capacity.
rcutils_array_list_t rcutils_get_zero_initialized_array_list(void)
Return an empty array_list struct.
Definition: array_list.h:32
rcutils_ret_t rcutils_array_list_add(rcutils_array_list_t *array_list, const void *data)
Adds an entry to the list.
int rcutils_ret_t
Definition: rcutils_ret.h:23
struct rcutils_array_list_impl_t * impl
Definition: array_list.h:34
struct rcutils_array_list_t rcutils_array_list_t
rcutils_ret_t rcutils_array_list_remove(rcutils_array_list_t *array_list, size_t index)
Removes an entry in the list at the provided index.
#define RCUTILS_PUBLIC_TYPE
Definition: visibility_control.h:51
Encapsulation of an allocator.
Definition: allocator.h:45
rcutils_ret_t rcutils_array_list_fini(rcutils_array_list_t *array_list)
Finalize an array list, reclaiming all resources.
rcutils_ret_t rcutils_array_list_get_size(const rcutils_array_list_t *array_list, size_t *size)
Retrieves the size of the provided array_list.
#define RCUTILS_WARN_UNUSED
Definition: macros.h:24
#define RCUTILS_PUBLIC
Definition: visibility_control.h:48
rcutils_ret_t rcutils_array_list_set(rcutils_array_list_t *array_list, size_t index, const void *data)
Sets an entry in the list to the provided data.
rcutils_ret_t rcutils_array_list_get(const rcutils_array_list_t *array_list, size_t index, void *data)
Retrieves an entry in the list at the provided index.