rcutils  master
C API providing common utilities and data structures.
string_array.h
Go to the documentation of this file.
1 // Copyright 2017 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__STRING_ARRAY_H_
16 #define RCUTILS__TYPES__STRING_ARRAY_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/error_handling.h"
27 #include "rcutils/macros.h"
28 #include "rcutils/qsort.h"
31 
33 {
34  size_t size;
35  char ** data;
38 
40 
60 
62 
94  rcutils_string_array_t * string_array,
95  size_t size,
96  const rcutils_allocator_t * allocator);
97 
99 
115 
117 
134  const rcutils_string_array_t * lhs,
135  const rcutils_string_array_t * rhs,
136  int * res);
137 
139 
164  rcutils_string_array_t * string_array,
165  size_t new_size);
166 
168 
180 int
181 rcutils_string_array_sort_compare(const void * lhs, const void * rhs);
182 
184 
194 inline
198 {
200  string_array, "string_array is null", return RCUTILS_RET_INVALID_ARGUMENT);
201 
202  return rcutils_qsort(
203  string_array->data,
204  string_array->size,
205  sizeof(string_array->data[0]),
207 }
208 
209 #ifdef __cplusplus
210 }
211 #endif
212 
213 #endif // RCUTILS__TYPES__STRING_ARRAY_H_
rcutils_string_array_t::allocator
rcutils_allocator_t allocator
Definition: string_array.h:36
macros.h
rcutils_string_array_t
Definition: string_array.h:32
rcutils_string_array_sort_compare
int rcutils_string_array_sort_compare(const void *lhs, const void *rhs)
Lexicographic comparer for pointers to string pointers.
RCUTILS_PUBLIC_TYPE
#define RCUTILS_PUBLIC_TYPE
Definition: visibility_control.h:29
RCUTILS_RET_INVALID_ARGUMENT
#define RCUTILS_RET_INVALID_ARGUMENT
Invalid argument return code.
Definition: rcutils_ret.h:31
RCUTILS_CHECK_FOR_NULL_WITH_MSG
#define RCUTILS_CHECK_FOR_NULL_WITH_MSG(value, msg, error_statement)
Check a value for null, with an error message and error statement.
Definition: error_handling.h:185
rcutils_ret_t
int rcutils_ret_t
Definition: rcutils_ret.h:23
qsort.h
rcutils_string_array_sort
rcutils_ret_t rcutils_string_array_sort(rcutils_string_array_t *string_array)
Sort a string array according to lexicographical order.
Definition: string_array.h:197
rcutils_string_array_cmp
rcutils_ret_t rcutils_string_array_cmp(const rcutils_string_array_t *lhs, const rcutils_string_array_t *rhs, int *res)
Compare two string arrays.
RCUTILS_WARN_UNUSED
#define RCUTILS_WARN_UNUSED
Definition: macros.h:24
rcutils_ret.h
rcutils_string_array_fini
rcutils_ret_t rcutils_string_array_fini(rcutils_string_array_t *string_array)
Finalize a string array, reclaiming all resources.
visibility_control.h
error_handling.h
rcutils_allocator_t
Encapsulation of an allocator.
Definition: allocator.h:45
allocator.h
rcutils_get_zero_initialized_string_array
rcutils_string_array_t rcutils_get_zero_initialized_string_array(void)
Return an empty string array struct.
rcutils_string_array_resize
rcutils_ret_t rcutils_string_array_resize(rcutils_string_array_t *string_array, size_t new_size)
Resize a string array, reclaiming removed resources.
RCUTILS_PUBLIC
#define RCUTILS_PUBLIC
Definition: visibility_control.h:23
rcutils_string_array_init
rcutils_ret_t rcutils_string_array_init(rcutils_string_array_t *string_array, size_t size, const rcutils_allocator_t *allocator)
Initialize a string array with a given size.
rcutils_string_array_t
struct rcutils_string_array_t rcutils_string_array_t
rcutils_string_array_t::size
size_t size
Definition: string_array.h:34
rcutils_qsort
rcutils_ret_t rcutils_qsort(void *ptr, size_t count, size_t size, int(*comp)(const void *, const void *))
Interface to qsort with rcutils-style argument validation.
rcutils_string_array_t::data
char ** data
Definition: string_array.h:35