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 
16 
17 #ifndef RCUTILS__TYPES__ARRAY_LIST_H_
18 #define RCUTILS__TYPES__ARRAY_LIST_H_
19 
20 #ifdef __cplusplus
21 extern "C"
22 {
23 #endif
24 
25 #include <string.h>
26 
27 #include "rcutils/allocator.h"
28 #include "rcutils/macros.h"
31 
32 struct rcutils_array_list_impl_t;
33 
36 {
38  struct rcutils_array_list_impl_t * impl;
40 
47 #define ARRAY_LIST_VALIDATE_ARRAY_LIST(array_list) \
48  RCUTILS_CHECK_ARGUMENT_FOR_NULL(array_list, RCUTILS_RET_INVALID_ARGUMENT); \
49  if (NULL == array_list->impl) { \
50  RCUTILS_SET_ERROR_MSG("array_list is not initialized"); \
51  return RCUTILS_RET_NOT_INITIALIZED; \
52  }
53 
55 
83 
85 
127  rcutils_array_list_t * array_list,
128  size_t initial_capacity,
129  size_t data_size,
130  const rcutils_allocator_t * allocator);
131 
133 
156 
158 
181 rcutils_array_list_add(rcutils_array_list_t * array_list, const void * data);
182 
184 
208 rcutils_array_list_set(rcutils_array_list_t * array_list, size_t index, const void * data);
209 
211 
233 rcutils_array_list_remove(rcutils_array_list_t * array_list, size_t index);
234 
236 
258 rcutils_array_list_get(const rcutils_array_list_t * array_list, size_t index, void * data);
259 
261 
282 rcutils_array_list_get_size(const rcutils_array_list_t * array_list, size_t * size);
283 
284 #ifdef __cplusplus
285 }
286 #endif
287 
288 #endif // RCUTILS__TYPES__ARRAY_LIST_H_
rcutils_array_list_t
struct rcutils_array_list_t rcutils_array_list_t
The structure holding the metadata for an array list.
rcutils_array_list_get
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.
rcutils_array_list_t
The structure holding the metadata for an array list.
Definition: array_list.h:35
rcutils_array_list_set
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_array_list_get_size
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.
rcutils_array_list_add
rcutils_ret_t rcutils_array_list_add(rcutils_array_list_t *array_list, const void *data)
Adds an entry to the list.
macros.h
RCUTILS_PUBLIC_TYPE
#define RCUTILS_PUBLIC_TYPE
Definition: visibility_control.h:29
rcutils_array_list_init
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_ret_t
int rcutils_ret_t
The type that holds a return value for an rcutils operation.
Definition: rcutils_ret.h:26
RCUTILS_WARN_UNUSED
#define RCUTILS_WARN_UNUSED
A macro to make the compiler warn when the return value of a function is not used.
Definition: macros.h:27
rcutils_ret.h
rcutils_array_list_t::impl
struct rcutils_array_list_impl_t * impl
A pointer to the PIMPL implementation type.
Definition: array_list.h:38
visibility_control.h
rcutils_get_zero_initialized_array_list
rcutils_array_list_t rcutils_get_zero_initialized_array_list(void)
Return an empty array_list struct.
rcutils_allocator_t
Encapsulation of an allocator.
Definition: allocator.h:47
allocator.h
RCUTILS_PUBLIC
#define RCUTILS_PUBLIC
Definition: visibility_control.h:23
rcutils_array_list_fini
rcutils_ret_t rcutils_array_list_fini(rcutils_array_list_t *array_list)
Finalize an array list, reclaiming all resources.
rcutils_array_list_remove
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.