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