Zephyr Project API  3.4.0
A Scalable Open Source RTOS
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
99static inline size_t z_cbprintf_cxx_arg_size(void *p)
100{
101 ARG_UNUSED(p);
102
103 return sizeof(void *);
104}
105
106template < typename T >
107static inline size_t z_cbprintf_cxx_arg_size(T arg)
108{
109 return sizeof(arg + 0);
110}
111
112/* C++ version for storing arguments. */
113static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, float arg)
114{
115 double d = (double)arg;
116 void *p = &d;
117
118 z_cbprintf_wcpy((int *)dst, (int *)p, sizeof(d) / sizeof(int));
119}
120
121static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, void *p)
122{
123 z_cbprintf_wcpy((int *)dst, (int *)&p, sizeof(p) / sizeof(int));
124}
125
126static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, char arg)
127{
128 int tmp = arg + 0;
129
130 z_cbprintf_wcpy((int *)dst, &tmp, 1);
131}
132
133static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, unsigned char arg)
134{
135 int tmp = arg + 0;
136
137 z_cbprintf_wcpy((int *)dst, &tmp, 1);
138}
139
140static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, signed char arg)
141{
142 int tmp = arg + 0;
143
144 z_cbprintf_wcpy((int *)dst, &tmp, 1);
145}
146
147static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, short arg)
148{
149 int tmp = arg + 0;
150
151 z_cbprintf_wcpy((int *)dst, &tmp, 1);
152}
153
154static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, unsigned short arg)
155{
156 int tmp = arg + 0;
157
158 z_cbprintf_wcpy((int *)dst, &tmp, 1);
159}
160
161template < typename T >
162static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, T arg)
163{
164 size_t wlen = z_cbprintf_cxx_arg_size(arg) / sizeof(int);
165 void *p = &arg;
166
167 z_cbprintf_wcpy((int *)dst, (int *)p, wlen);
168}
169
170/* C++ version for long double detection. */
171static inline int z_cbprintf_cxx_is_longdouble(long double arg)
172{
173 ARG_UNUSED(arg);
174 return 1;
175}
176
177template < typename T >
178static inline int z_cbprintf_cxx_is_longdouble(T arg)
179{
180 ARG_UNUSED(arg);
181
182 return 0;
183}
184
185/* C++ version for caluculating argument alignment. */
186static inline size_t z_cbprintf_cxx_alignment(float arg)
187{
188 ARG_UNUSED(arg);
189
190 return VA_STACK_ALIGN(double);
191}
192
193static inline size_t z_cbprintf_cxx_alignment(double arg)
194{
195 ARG_UNUSED(arg);
196
197 return VA_STACK_ALIGN(double);
198}
199
200static inline size_t z_cbprintf_cxx_alignment(long double arg)
201{
202 ARG_UNUSED(arg);
203
204 return VA_STACK_ALIGN(long double);
205}
206
207static inline size_t z_cbprintf_cxx_alignment(long long arg)
208{
209 ARG_UNUSED(arg);
210
211 return VA_STACK_ALIGN(long long);
212}
213
214static inline size_t z_cbprintf_cxx_alignment(unsigned long long arg)
215{
216 ARG_UNUSED(arg);
217
218 return VA_STACK_ALIGN(long long);
219}
220
221template < typename T >
222static inline size_t z_cbprintf_cxx_alignment(T arg)
223{
224 return MAX(__alignof__(arg), VA_STACK_MIN_ALIGN);
225}
226
227/* C++ version for checking if two arguments are same type */
228template < typename T1, typename T2 >
229struct z_cbprintf_cxx_is_same_type {
230 enum {
231 value = false
232 };
233};
234
235template < typename T >
236struct z_cbprintf_cxx_is_same_type < T, T > {
237 enum {
238 value = true
239 };
240};
241
242template < typename T >
243struct z_cbprintf_cxx_remove_reference {
244 typedef T type;
245};
246
247template < typename T >
248struct z_cbprintf_cxx_remove_reference < T & > {
249 typedef T type;
250};
251
252#if __cplusplus >= 201103L
253template < typename T >
254struct z_cbprintf_cxx_remove_reference < T && > {
255 typedef T type;
256};
257#endif
258
259template < typename T >
260struct z_cbprintf_cxx_remove_cv {
261 typedef T type;
262};
263
264template < typename T >
265struct z_cbprintf_cxx_remove_cv < const T > {
266 typedef T type;
267};
268
269template < typename T >
270struct z_cbprintf_cxx_remove_cv < volatile T > {
271 typedef T type;
272};
273
274template < typename T >
275struct z_cbprintf_cxx_remove_cv < const volatile T > {
276 typedef T type;
277};
278
279/* Determine if a type is an array */
280template < typename T >
281struct z_cbprintf_cxx_is_array {
282 enum {
283 value = false
284 };
285};
286
287template < typename T >
288struct z_cbprintf_cxx_is_array < T[] > {
289 enum {
290 value = true
291 };
292};
293
294template < typename T, size_t N >
295struct z_cbprintf_cxx_is_array < T[N] > {
296 enum {
297 value = true
298 };
299};
300
301/* Determine the type of elements in an array */
302template < typename T >
303struct z_cbprintf_cxx_remove_extent {
304 typedef T type;
305};
306
307template < typename T >
308struct z_cbprintf_cxx_remove_extent < T[] > {
309 typedef T type;
310};
311
312template < typename T, size_t N >
313struct z_cbprintf_cxx_remove_extent < T[N] > {
314 typedef T type;
315};
316
317#endif /* __cplusplus */
318#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:283
struct k_futex f
Definition: kobject.c:1330
struct k_pipe p
Definition: kobject.c:1322
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88