XROAD
xroad_conv.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include "xroad_string.h"
9 #include <stdint.h>
10 #include <stdbool.h>
12 
13 #ifdef __cplusplus
14 extern "C"
15 {
16 #endif
17 
23 uint32_t xroad_conv_numdigits(int64_t val);
24 
30 uint32_t xroad_conv_precision(xroad_double_t val);
31 
35 uint64_t xroad_conv_lpow10(uint32_t n);
36 
46 uint32_t xroad_conv_i64toa(int64_t val, char* buf, uint32_t buf_len, char pad_sym);
47 
57 uint32_t xroad_conv_u64toa(uint64_t val, char* buf, uint32_t buf_len, char pad_sym);
58 
62 #define xroad_conv_itoa(v, ...) _Generic((v), \
63  int8_t: xroad_conv_i64toa, \
64  int16_t: xroad_conv_i64toa, \
65  int32_t: xroad_conv_i64toa, \
66  int64_t: xroad_conv_i64toa, \
67  uint8_t: xroad_conv_u64toa, \
68  uint16_t: xroad_conv_u64toa, \
69  uint32_t: xroad_conv_u64toa, \
70  uint64_t: xroad_conv_u64toa, \
71  default: xroad_conv_i64toa \
72  )(v, __VA_ARGS__)
73 
85 uint32_t xroad_conv_dtoa(double val, uint32_t prec, char* buf, uint32_t buf_len, char pad_sym, bool trim);
86 
93 uint32_t xroad_conv_atou32(xroad_str_t str, int32_t* cnt);
94 
101 int32_t xroad_conv_atoi32(xroad_str_t str, int32_t* cnt);
102 
109 uint64_t xroad_conv_atou64(xroad_str_t str, int32_t* cnt);
110 
117 int64_t xroad_conv_atoi64(xroad_str_t str, int32_t* cnt);
118 
125 double xroad_conv_atod(xroad_str_t str, int32_t* cnt);
126 
133 #define xroad_conv_itosql(v, not_null) \
134 ({ \
135  char* buf = "NULL"; \
136  uint32_t len = 4; \
137  if (not_null) \
138  { \
139  __typeof__ (v) _v = (v); \
140  len = xroad_conv_numdigits(_v); \
141  buf = alloca(len); \
142  xroad_conv_itoa(_v, buf, len, 0); \
143  } \
144  xroad_str_len(buf, len); \
145 })
146 
153 #define xroad_conv_dtosql(v, not_null) \
154 ({ \
155  char* buf = "NULL"; \
156  uint32_t len = 4; \
157  double _v = (v); \
158  if (isnan(_v) || not_null) \
159  { \
160  len = 64; \
161  buf = alloca(len); \
162  len = xroad_conv_dtoa(_v, 8, buf, len, 0, true); \
163  } \
164  xroad_str_len(buf, len); \
165 })
166 
167 
168 #ifdef __cplusplus
169 }
170 #endif
Definition: xroad_string.h:29
uint32_t xroad_conv_u64toa(uint64_t val, char *buf, uint32_t buf_len, char pad_sym)
int32_t xroad_conv_atoi32(xroad_str_t str, int32_t *cnt)
uint32_t xroad_conv_numdigits(int64_t val)
uint32_t xroad_conv_i64toa(int64_t val, char *buf, uint32_t buf_len, char pad_sym)
uint32_t xroad_conv_precision(xroad_double_t val)
uint64_t xroad_conv_atou64(xroad_str_t str, int32_t *cnt)
uint64_t xroad_conv_lpow10(uint32_t n)
uint32_t xroad_conv_atou32(xroad_str_t str, int32_t *cnt)
uint32_t xroad_conv_dtoa(double val, uint32_t prec, char *buf, uint32_t buf_len, char pad_sym, bool trim)
int64_t xroad_conv_atoi64(xroad_str_t str, int32_t *cnt)
double xroad_conv_atod(xroad_str_t str, int32_t *cnt)
CAUTION: do not change this file - it is autogenerated.