Zephyr API Documentation 4.0.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
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 determining if variable type is numeric and fits in 32 bit word. */
92static inline int z_cbprintf_cxx_is_word_num(char)
93{
94 return 1;
95}
96
97static inline int z_cbprintf_cxx_is_word_num(unsigned char)
98{
99 return 1;
100}
101
102static inline int z_cbprintf_cxx_is_word_num(short)
103{
104 return 1;
105}
106
107static inline int z_cbprintf_cxx_is_word_num(unsigned short)
108{
109 return 1;
110}
111
112static inline int z_cbprintf_cxx_is_word_num(int)
113{
114 return 1;
115}
116
117static inline int z_cbprintf_cxx_is_word_num(unsigned int)
118{
119 return 1;
120}
121
122static inline int z_cbprintf_cxx_is_word_num(long)
123{
124 return (sizeof(long) <= sizeof(uint32_t)) ? 1 : 0;
125}
126
127static inline int z_cbprintf_cxx_is_word_num(unsigned long)
128{
129 return (sizeof(long) <= sizeof(uint32_t)) ? 1 : 0;
130}
131
132template < typename T >
133static inline int z_cbprintf_cxx_is_word_num(T arg)
134{
135 ARG_UNUSED(arg);
136 _Pragma("GCC diagnostic push")
137 _Pragma("GCC diagnostic ignored \"-Wpointer-arith\"")
138 return 0;
139 _Pragma("GCC diagnostic pop")
140}
141
142/* C++ version for determining if argument is a none character pointer. */
143static inline int z_cbprintf_cxx_is_none_char_ptr(char)
144{
145 return 0;
146}
147
148static inline int z_cbprintf_cxx_is_none_char_ptr(unsigned char)
149{
150 return 0;
151}
152
153static inline int z_cbprintf_cxx_is_none_char_ptr(short)
154{
155 return 0;
156}
157
158static inline int z_cbprintf_cxx_is_none_char_ptr(unsigned short)
159{
160 return 0;
161}
162
163static inline int z_cbprintf_cxx_is_none_char_ptr(int)
164{
165 return 0;
166}
167
168static inline int z_cbprintf_cxx_is_none_char_ptr(unsigned int)
169{
170 return 0;
171}
172
173static inline int z_cbprintf_cxx_is_none_char_ptr(long)
174{
175 return 0;
176}
177
178static inline int z_cbprintf_cxx_is_none_char_ptr(unsigned long)
179{
180 return 0;
181}
182
183static inline int z_cbprintf_cxx_is_none_char_ptr(long long)
184{
185 return 0;
186}
187
188static inline int z_cbprintf_cxx_is_none_char_ptr(unsigned long long)
189{
190 return 0;
191}
192
193static inline int z_cbprintf_cxx_is_none_char_ptr(float)
194{
195 return 0;
196}
197
198static inline int z_cbprintf_cxx_is_none_char_ptr(double)
199{
200 return 0;
201}
202
203static inline int z_cbprintf_cxx_is_none_char_ptr(char *)
204{
205 return 0;
206}
207
208static inline int z_cbprintf_cxx_is_none_char_ptr(volatile char *)
209{
210 return 0;
211}
212
213static inline int z_cbprintf_cxx_is_none_char_ptr(const char *)
214{
215 return 0;
216}
217
218static inline int z_cbprintf_cxx_is_none_char_ptr(const volatile char *)
219{
220 return 0;
221}
222
223static inline int z_cbprintf_cxx_is_none_char_ptr(unsigned char *)
224{
225 return 0;
226}
227
228static inline int z_cbprintf_cxx_is_none_char_ptr(volatile unsigned char *)
229{
230 return 0;
231}
232
233static inline int z_cbprintf_cxx_is_none_char_ptr(const unsigned char *)
234{
235 return 0;
236}
237
238static inline int z_cbprintf_cxx_is_none_char_ptr(const volatile unsigned char *)
239{
240 return 0;
241}
242
243template < typename T >
244static inline int z_cbprintf_cxx_is_none_char_ptr(T arg)
245{
246 ARG_UNUSED(arg);
247
248 return 1;
249}
250
251/* C++ version for calculating argument size. */
252static inline size_t z_cbprintf_cxx_arg_size(float f)
253{
254 ARG_UNUSED(f);
255
256 return sizeof(double);
257}
258
259template < typename T >
260static inline size_t z_cbprintf_cxx_arg_size(T arg)
261{
262 ARG_UNUSED(arg);
263
264 return MAX(sizeof(T), sizeof(int));
265}
266
267/* C++ version for storing arguments. */
268static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, float arg)
269{
270 double d = (double)arg;
271 void *p = &d;
272
273 z_cbprintf_wcpy((int *)dst, (int *)p, sizeof(d) / sizeof(int));
274}
275
276static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, void *p)
277{
278 z_cbprintf_wcpy((int *)dst, (int *)&p, sizeof(p) / sizeof(int));
279}
280
281static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, char arg)
282{
283 int tmp = arg + 0;
284
285 z_cbprintf_wcpy((int *)dst, &tmp, 1);
286}
287
288static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, unsigned char arg)
289{
290 int tmp = arg + 0;
291
292 z_cbprintf_wcpy((int *)dst, &tmp, 1);
293}
294
295static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, signed char arg)
296{
297 int tmp = arg + 0;
298
299 z_cbprintf_wcpy((int *)dst, &tmp, 1);
300}
301
302static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, short arg)
303{
304 int tmp = arg + 0;
305
306 z_cbprintf_wcpy((int *)dst, &tmp, 1);
307}
308
309static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, unsigned short arg)
310{
311 int tmp = arg + 0;
312
313 z_cbprintf_wcpy((int *)dst, &tmp, 1);
314}
315
316template < typename T >
317static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, T arg)
318{
319 size_t wlen = z_cbprintf_cxx_arg_size(arg) / sizeof(int);
320 void *p = &arg;
321
322 z_cbprintf_wcpy((int *)dst, (int *)p, wlen);
323}
324
325/* C++ version for long double detection. */
326static inline int z_cbprintf_cxx_is_longdouble(long double arg)
327{
328 ARG_UNUSED(arg);
329 return 1;
330}
331
332template < typename T >
333static inline int z_cbprintf_cxx_is_longdouble(T arg)
334{
335 ARG_UNUSED(arg);
336
337 return 0;
338}
339
340/* C++ version for calculating argument alignment. */
341static inline size_t z_cbprintf_cxx_alignment(float arg)
342{
343 ARG_UNUSED(arg);
344
345 return VA_STACK_ALIGN(double);
346}
347
348static inline size_t z_cbprintf_cxx_alignment(double arg)
349{
350 ARG_UNUSED(arg);
351
352 return VA_STACK_ALIGN(double);
353}
354
355static inline size_t z_cbprintf_cxx_alignment(long double arg)
356{
357 ARG_UNUSED(arg);
358
359 return VA_STACK_ALIGN(long double);
360}
361
362static inline size_t z_cbprintf_cxx_alignment(long long arg)
363{
364 ARG_UNUSED(arg);
365
366 return VA_STACK_ALIGN(long long);
367}
368
369static inline size_t z_cbprintf_cxx_alignment(unsigned long long arg)
370{
371 ARG_UNUSED(arg);
372
373 return VA_STACK_ALIGN(long long);
374}
375
376template < typename T >
377static inline size_t z_cbprintf_cxx_alignment(T arg)
378{
379 return MAX(__alignof__(arg), VA_STACK_MIN_ALIGN);
380}
381
382/* C++ version for checking if two arguments are same type */
383template < typename T1, typename T2 >
384struct z_cbprintf_cxx_is_same_type {
385 enum {
386 value = false
387 };
388};
389
390template < typename T >
391struct z_cbprintf_cxx_is_same_type < T, T > {
392 enum {
393 value = true
394 };
395};
396
397template < typename T >
398struct z_cbprintf_cxx_remove_reference {
399 typedef T type;
400};
401
402template < typename T >
403struct z_cbprintf_cxx_remove_reference < T & > {
404 typedef T type;
405};
406
407#if __cplusplus >= 201103L
408template < typename T >
409struct z_cbprintf_cxx_remove_reference < T && > {
410 typedef T type;
411};
412#endif
413
414template < typename T >
415struct z_cbprintf_cxx_remove_cv {
416 typedef T type;
417};
418
419template < typename T >
420struct z_cbprintf_cxx_remove_cv < const T > {
421 typedef T type;
422};
423
424template < typename T >
425struct z_cbprintf_cxx_remove_cv < volatile T > {
426 typedef T type;
427};
428
429template < typename T >
430struct z_cbprintf_cxx_remove_cv < const volatile T > {
431 typedef T type;
432};
433
434/* Determine if a type is an array */
435template < typename T >
436struct z_cbprintf_cxx_is_array {
437 enum {
438 value = false
439 };
440};
441
442template < typename T >
443struct z_cbprintf_cxx_is_array < T[] > {
444 enum {
445 value = true
446 };
447};
448
449template < typename T, size_t N >
450struct z_cbprintf_cxx_is_array < T[N] > {
451 enum {
452 value = true
453 };
454};
455
456/* Determine the type of elements in an array */
457template < typename T >
458struct z_cbprintf_cxx_remove_extent {
459 typedef T type;
460};
461
462template < typename T >
463struct z_cbprintf_cxx_remove_extent < T[] > {
464 typedef T type;
465};
466
467template < typename T, size_t N >
468struct z_cbprintf_cxx_remove_extent < T[N] > {
469 typedef T type;
470};
471
472#endif /* __cplusplus */
473#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:386
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88