Zephyr Project API  3.2.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
252template < typename T >
253struct z_cbprintf_cxx_remove_reference < T && > {
254 typedef T type;
255};
256
257template < typename T >
258struct z_cbprintf_cxx_remove_cv {
259 typedef T type;
260};
261
262template < typename T >
263struct z_cbprintf_cxx_remove_cv < const T > {
264 typedef T type;
265};
266
267template < typename T >
268struct z_cbprintf_cxx_remove_cv < volatile T > {
269 typedef T type;
270};
271
272template < typename T >
273struct z_cbprintf_cxx_remove_cv < const volatile T > {
274 typedef T type;
275};
276
277/* Determine if a type is an array */
278template < typename T >
279struct z_cbprintf_cxx_is_array {
280 enum {
281 value = false
282 };
283};
284
285template < typename T >
286struct z_cbprintf_cxx_is_array < T[] > {
287 enum {
288 value = true
289 };
290};
291
292template < typename T, size_t N >
293struct z_cbprintf_cxx_is_array < T[N] > {
294 enum {
295 value = true
296 };
297};
298
299/* Determine the type of elements in an array */
300template < typename T >
301struct z_cbprintf_cxx_remove_extent {
302 typedef T type;
303};
304
305template < typename T >
306struct z_cbprintf_cxx_remove_extent < T[] > {
307 typedef T type;
308};
309
310template < typename T, size_t N >
311struct z_cbprintf_cxx_remove_extent < T[N] > {
312 typedef T type;
313};
314
315#endif /* __cplusplus */
316#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:45
#define VA_STACK_ALIGN(type)
Definition: cbprintf_internal.h:49
#define MAX(a, b)
Obtain the maximum of two values.
Definition: util.h:252
struct k_futex f
Definition: kobject.c:1330
struct k_pipe p
Definition: kobject.c:1322
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88