Zephyr API Documentation  3.5.0
A Scalable Open Source RTOS
3.5.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
cbprintf_cxx.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_SYS_CBPRINTF_CXX_H_
8#define ZEPHYR_INCLUDE_SYS_CBPRINTF_CXX_H_
9#ifdef __cplusplus
10
11/* C++ version for detecting a pointer to a string. */
12static inline int z_cbprintf_cxx_is_pchar(char *, bool const_as_fixed)
13{
14 ARG_UNUSED(const_as_fixed);
15 return 1;
16}
17
18static inline int z_cbprintf_cxx_is_pchar(const char *, bool const_as_fixed)
19{
20 return const_as_fixed ? 0 : 1;
21}
22
23static inline int z_cbprintf_cxx_is_pchar(volatile char *, bool const_as_fixed)
24{
25 ARG_UNUSED(const_as_fixed);
26 return 1;
27}
28
29static inline int z_cbprintf_cxx_is_pchar(const volatile char *, bool const_as_fixed)
30{
31 ARG_UNUSED(const_as_fixed);
32 return 1;
33}
34
35static inline int z_cbprintf_cxx_is_pchar(unsigned char *, bool const_as_fixed)
36{
37 ARG_UNUSED(const_as_fixed);
38 return 1;
39}
40
41static inline int z_cbprintf_cxx_is_pchar(const unsigned char *, bool const_as_fixed)
42{
43 return const_as_fixed ? 0 : 1;
44}
45
46static inline int z_cbprintf_cxx_is_pchar(volatile unsigned char *, bool const_as_fixed)
47{
48 ARG_UNUSED(const_as_fixed);
49 return 1;
50}
51
52static inline int z_cbprintf_cxx_is_pchar(const volatile unsigned char *, bool const_as_fixed)
53{
54 ARG_UNUSED(const_as_fixed);
55 return 1;
56}
57static inline int z_cbprintf_cxx_is_pchar(wchar_t *, bool const_as_fixed)
58{
59 ARG_UNUSED(const_as_fixed);
60 return 1;
61}
62
63static inline int z_cbprintf_cxx_is_pchar(const wchar_t *, bool const_as_fixed)
64{
65 return const_as_fixed ? 0 : 1;
66}
67
68static inline int z_cbprintf_cxx_is_pchar(volatile wchar_t *, bool const_as_fixed)
69{
70 ARG_UNUSED(const_as_fixed);
71 return 1;
72}
73
74static inline int z_cbprintf_cxx_is_pchar(const volatile wchar_t *, bool const_as_fixed)
75{
76 ARG_UNUSED(const_as_fixed);
77 return 1;
78}
79
80template < typename T >
81static inline int z_cbprintf_cxx_is_pchar(T arg, bool const_as_fixed)
82{
83 ARG_UNUSED(arg);
84 _Pragma("GCC diagnostic push")
85 _Pragma("GCC diagnostic ignored \"-Wpointer-arith\"")
86 ARG_UNUSED(const_as_fixed);
87 return 0;
88 _Pragma("GCC diagnostic pop")
89}
90
91/* C++ version for calculating argument size. */
92static inline size_t z_cbprintf_cxx_arg_size(float f)
93{
94 ARG_UNUSED(f);
95
96 return sizeof(double);
97}
98
99template < typename T >
100static inline size_t z_cbprintf_cxx_arg_size(T arg)
101{
102 ARG_UNUSED(arg);
103
104 return MAX(sizeof(T), sizeof(int));
105}
106
107/* C++ version for storing arguments. */
108static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, float arg)
109{
110 double d = (double)arg;
111 void *p = &d;
112
113 z_cbprintf_wcpy((int *)dst, (int *)p, sizeof(d) / sizeof(int));
114}
115
116static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, void *p)
117{
118 z_cbprintf_wcpy((int *)dst, (int *)&p, sizeof(p) / sizeof(int));
119}
120
121static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, char arg)
122{
123 int tmp = arg + 0;
124
125 z_cbprintf_wcpy((int *)dst, &tmp, 1);
126}
127
128static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, unsigned char arg)
129{
130 int tmp = arg + 0;
131
132 z_cbprintf_wcpy((int *)dst, &tmp, 1);
133}
134
135static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, signed char arg)
136{
137 int tmp = arg + 0;
138
139 z_cbprintf_wcpy((int *)dst, &tmp, 1);
140}
141
142static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, short arg)
143{
144 int tmp = arg + 0;
145
146 z_cbprintf_wcpy((int *)dst, &tmp, 1);
147}
148
149static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, unsigned short arg)
150{
151 int tmp = arg + 0;
152
153 z_cbprintf_wcpy((int *)dst, &tmp, 1);
154}
155
156template < typename T >
157static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, T arg)
158{
159 size_t wlen = z_cbprintf_cxx_arg_size(arg) / sizeof(int);
160 void *p = &arg;
161
162 z_cbprintf_wcpy((int *)dst, (int *)p, wlen);
163}
164
165/* C++ version for long double detection. */
166static inline int z_cbprintf_cxx_is_longdouble(long double arg)
167{
168 ARG_UNUSED(arg);
169 return 1;
170}
171
172template < typename T >
173static inline int z_cbprintf_cxx_is_longdouble(T arg)
174{
175 ARG_UNUSED(arg);
176
177 return 0;
178}
179
180/* C++ version for caluculating argument alignment. */
181static inline size_t z_cbprintf_cxx_alignment(float arg)
182{
183 ARG_UNUSED(arg);
184
185 return VA_STACK_ALIGN(double);
186}
187
188static inline size_t z_cbprintf_cxx_alignment(double arg)
189{
190 ARG_UNUSED(arg);
191
192 return VA_STACK_ALIGN(double);
193}
194
195static inline size_t z_cbprintf_cxx_alignment(long double arg)
196{
197 ARG_UNUSED(arg);
198
199 return VA_STACK_ALIGN(long double);
200}
201
202static inline size_t z_cbprintf_cxx_alignment(long long arg)
203{
204 ARG_UNUSED(arg);
205
206 return VA_STACK_ALIGN(long long);
207}
208
209static inline size_t z_cbprintf_cxx_alignment(unsigned long long arg)
210{
211 ARG_UNUSED(arg);
212
213 return VA_STACK_ALIGN(long long);
214}
215
216template < typename T >
217static inline size_t z_cbprintf_cxx_alignment(T arg)
218{
219 return MAX(__alignof__(arg), VA_STACK_MIN_ALIGN);
220}
221
222/* C++ version for checking if two arguments are same type */
223template < typename T1, typename T2 >
224struct z_cbprintf_cxx_is_same_type {
225 enum {
226 value = false
227 };
228};
229
230template < typename T >
231struct z_cbprintf_cxx_is_same_type < T, T > {
232 enum {
233 value = true
234 };
235};
236
237template < typename T >
238struct z_cbprintf_cxx_remove_reference {
239 typedef T type;
240};
241
242template < typename T >
243struct z_cbprintf_cxx_remove_reference < T & > {
244 typedef T type;
245};
246
247#if __cplusplus >= 201103L
248template < typename T >
249struct z_cbprintf_cxx_remove_reference < T && > {
250 typedef T type;
251};
252#endif
253
254template < typename T >
255struct z_cbprintf_cxx_remove_cv {
256 typedef T type;
257};
258
259template < typename T >
260struct z_cbprintf_cxx_remove_cv < const T > {
261 typedef T type;
262};
263
264template < typename T >
265struct z_cbprintf_cxx_remove_cv < volatile T > {
266 typedef T type;
267};
268
269template < typename T >
270struct z_cbprintf_cxx_remove_cv < const volatile T > {
271 typedef T type;
272};
273
274/* Determine if a type is an array */
275template < typename T >
276struct z_cbprintf_cxx_is_array {
277 enum {
278 value = false
279 };
280};
281
282template < typename T >
283struct z_cbprintf_cxx_is_array < T[] > {
284 enum {
285 value = true
286 };
287};
288
289template < typename T, size_t N >
290struct z_cbprintf_cxx_is_array < T[N] > {
291 enum {
292 value = true
293 };
294};
295
296/* Determine the type of elements in an array */
297template < typename T >
298struct z_cbprintf_cxx_remove_extent {
299 typedef T type;
300};
301
302template < typename T >
303struct z_cbprintf_cxx_remove_extent < T[] > {
304 typedef T type;
305};
306
307template < typename T, size_t N >
308struct z_cbprintf_cxx_remove_extent < T[N] > {
309 typedef T type;
310};
311
312#endif /* __cplusplus */
313#endif /* ZEPHYR_INCLUDE_SYS_CBPRINTF_CXX_H_ */
irp nz macro MOVR cc d
Definition: asm-macro-32-bit-gnu.h:11
#define VA_STACK_MIN_ALIGN
Definition: cbprintf_internal.h:48
#define VA_STACK_ALIGN(type)
Definition: cbprintf_internal.h:52
#define MAX(a, b)
Obtain the maximum of two values.
Definition: util.h:326
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88