rosidl_runtime_c  master
Generate the rosidl interfaces in C.
string_functions.h
Go to the documentation of this file.
1 // Copyright 2015 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 ROSIDL_RUNTIME_C__STRING_FUNCTIONS_H_
16 #define ROSIDL_RUNTIME_C__STRING_FUNCTIONS_H_
17 
18 #include <stddef.h>
19 
22 
23 #ifdef __cplusplus
24 extern "C"
25 {
26 #endif
27 
29 /*
30  * The contents of rosidl_runtime_c__String are initialized to a single null character ('\0').
31  * The string initially has size 0 and capacity 1.
32  * Size represents the size of the contents of the string, while capacity represents the overall
33  * storage of the string (counting the null terminator).
34  * All strings must be null-terminated.
35  * The rosidl_runtime_c__String structure should be deallocated using the given function
36  * rosidl_runtime_c__String__fini() when it is no longer needed.
37  * Calling this function with an already initialized U16 string sequence structure will leak
38  * memory.
39  *
40  * \param[inout] str a pointer to a rosidl_runtime_c__String structure
41  * \return true if successful, false if the passed string pointer is null
42  * or the memory allocation failed
43  */
45 bool
47 
49 /*
50 * Calling the function with an already deallocated sequence is a no-op.
51 *
52 * \param[inout] str a pointer to a rosidl_runtime_c__String structure to be finalized
53 */
55 void
57 
59 /*
60  * \param[inout] str a pointer to a string structure
61  * \param[in] value c string pointer to be assigned
62  * \param[in] n size of the value string
63  * \return true if successful, false if the passed string pointer is null
64  * or if the passed value pointer is null or if the size is higher than SIZE_MAX
65  * or if the memory reallocation failed.
66  */
68 bool
70  rosidl_runtime_c__String * str, const char * value, size_t n);
71 
73 /*
74  *
75  * This function is identical to rosidl_runtime_c__String__assignn() except the length of the
76  * c string does not have to be given and therefore the c string must be null terminated.
77  *
78  * \see rosidl_runtime_c__String__assignn()
79  *
80  * \param[inout] str a pointer to a rosidl_runtime_c__String structure
81  * \param[in] value c string pointer to be assigned
82  * \return true if successful, false if the passed string pointer is null
83  * or if the passed value pointer is null or if the size is higher than SIZE_MAX
84  * or if the memory reallocation failed.
85  */
87 bool
89  rosidl_runtime_c__String * str, const char * value);
90 
92 /*
93  * The rosidl_runtime_c__String__Sequence is initialized with the size passed to the function.
94  * The rosidl_runtime_c__String__Sequence structure should be deallocated using the given function
95  * rosidl_runtime_c__String__Sequence__fini() when it is no longer needed.
96  * Calling this function with an already initialized U16 string sequence structure will leak
97  * memory.
98  *
99  * \param[inout] sequence a pointer to a string sequence
100  * \param[in] size represents the size of the string sequence
101  * \return true if successful, false if the passed string pointer is null
102  * or the memory allocation failed
103  */
105 bool
107  rosidl_runtime_c__String__Sequence * sequence, size_t size);
108 
110 /*
111  * Calling the function with an already deallocated sequence is a no-op.
112  *
113  * \param[inout] sequence a pointer to a string sequence to be finalized
114  */
116 void
118  rosidl_runtime_c__String__Sequence * sequence);
119 
121 /*
122  * The string sequence initially has size and capacity equal to the size argument passed to the
123  * function.
124  * The rosidl_runtime_c__String__Sequence structure should be deallocated using the given function
125  * rosidl_runtime_c__String__Sequence__destroy() when it is no longer needed.
126  *
127  * \param[in] size of the desired string sequence
128  * \return a string sequence if initialization was successfully, otherwise NULL.
129  */
131 rosidl_runtime_c__String__Sequence *
133 
135 /*
136  * Calling the function with an already deallocated sequence is a no-op.
137  *
138  * \param[inout] sequence a pointer to a string sequence to be finalized
139  */
141 void
143  rosidl_runtime_c__String__Sequence * sequence);
144 
145 #ifdef __cplusplus
146 }
147 #endif
148 
149 #endif // ROSIDL_RUNTIME_C__STRING_FUNCTIONS_H_
rosidl_runtime_c__String__fini
void rosidl_runtime_c__String__fini(rosidl_runtime_c__String *str)
Deallocate the memory of the rosidl_runtime_c__String structure.
rosidl_runtime_c__String__Sequence__destroy
void rosidl_runtime_c__String__Sequence__destroy(rosidl_runtime_c__String__Sequence *sequence)
Destroy a rosidl_runtime_c__String__Sequence structure.
string.h
rosidl_runtime_c__String
An array of 8-bit characters terminated by a null byte.
Definition: string.h:23
rosidl_runtime_c__String__assign
bool rosidl_runtime_c__String__assign(rosidl_runtime_c__String *str, const char *value)
Assign the c string pointer to the rosidl_runtime_c__String structure.
rosidl_runtime_c__String__init
bool rosidl_runtime_c__String__init(rosidl_runtime_c__String *str)
Initialize a rosidl_runtime_c__String structure.
rosidl_runtime_c__String__Sequence__init
bool rosidl_runtime_c__String__Sequence__init(rosidl_runtime_c__String__Sequence *sequence, size_t size)
Initialize a rosidl_runtime_c__String__Sequence__init structure.
rosidl_runtime_c__String__Sequence__create
rosidl_runtime_c__String__Sequence * rosidl_runtime_c__String__Sequence__create(size_t size)
Create a rosidl_runtime_c__String__Sequence structure with a specific size.
visibility_control.h
rosidl_runtime_c__String__Sequence__fini
void rosidl_runtime_c__String__Sequence__fini(rosidl_runtime_c__String__Sequence *sequence)
Deallocate the memory of the string sequence structure.
rosidl_runtime_c__String__assignn
bool rosidl_runtime_c__String__assignn(rosidl_runtime_c__String *str, const char *value, size_t n)
Assign the c string pointer of n characters to the rosidl_runtime_c__String structure.
ROSIDL_GENERATOR_C_PUBLIC
#define ROSIDL_GENERATOR_C_PUBLIC
Definition: visibility_control.h:48