FARGOS/VISTA Object Management Environment Core  ..
FARGOS/VISTA Object Management Environment Core Table of Contents
text2int.h
Go to the documentation of this file.
1 #ifndef _TEXT2INT_H_
2 #define _TEXT2INT_H_ "$Id: text2int.h 463 2020-07-24 17:42:01Z geoff $"
4 
6 /* Copyright (C) 2010 - 2020 FARGOS Development, LLC
7  * Author: Geoff Carpenter -- http://www.fargos.net/gcc.html
8  */
9 
10 
11 #include <stdint.h>
12 #include <memory.h>
13 #include <math.h>
16 #ifndef _WIN32
17 #include <netinet/in.h>
18 #endif
19 
41 /* The "trick" here is that we add 0 to the value defined OR the keywords.
42  * Assuming nothing is defined (WIN32), we end up with __BIG_ENDIAN0 and
43  * __BYTE_ORDER0. If the values are defined, we end up with 43210 and
44  * either 43210, 12340 or 34120 (for the DEC PDP case).
45  */
47 #define __BIG_ENDIAN0 43210
48 #define __BYTE_ORDER0 99990
49 #define __BYTE_ORDER_APPEND2(x,y) x ## y
50 #define __BYTE_ORDER_APPEND1(x,y) __BYTE_ORDER_APPEND2(x,y)
51 #define _BE_PATTERN __BYTE_ORDER_APPEND1(__BIG_ENDIAN,0)
52 #define _HB_PATTERN __BYTE_ORDER_APPEND1(__BYTE_ORDER,0)
53 
54 #define __PERMIT_UNALIGNED_READS 1 /* since we are running on x86_64, unaligned reads are permitted */
55 
56 #define _ENABLE_TABLE_PREFETCH_ 0
57 
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62 
63 #pragma GCC diagnostic push
64 #pragma GCC diagnostic ignored "-Wsuggest-attribute=pure"
65 
66 extern uint_fast32_t text2uint32(const char *textString, uint_fast8_t text_len) NONNULL_PARAMETERS(1) OME_ALWAYS_INLINE OME_ALWAYS_OPTIMIZE("-O3");
79 inline uint_fast32_t text2uint32(const char *textString, uint_fast8_t text_len)
80 {
81 
82  /* we want to read from the string, but don't intend to use it again */
83  OME_PREFETCH(textString, 0, 0);
84  /* The following all reference addresses determined at link time. */
85  enum { baseOffset = '0' * 10 * sizeof(uint32_t) }; /* offset of first row */
86 
87 #if _ENABLE_TABLE_PREFETCH_ == 1
88  /* We want to read from the conversion table and will be using it
89  * again, so keep it cached if possible. The table is intentionally
90  * laid out so as to keep the interesting section densely packed.
91  *
92  * 10 digits, max 10 characters in length, 4 bytes per digit =
93  * 400 bytes total.
94  * Precache 4 lines to cover up to 6 digits.
95  */
96  OME_PREFETCH(((const char *) text2int_table) + baseOffset + 3 * CACHE_LINE_LENGTH, 0, 3);
97  OME_PREFETCH(((const char *) text2int_table) + baseOffset + 2 * CACHE_LINE_LENGTH, 0, 3);
98  OME_PREFETCH(((const char *) text2int_table) + baseOffset + CACHE_LINE_LENGTH, 0, 3);
99  OME_PREFETCH(((const char *) text2int_table) + baseOffset, 0, 3);
100 #endif
101  const unsigned char *text = (const unsigned char *) textString;
102  uint_fast32_t result = 0;
103  switch (text_len) {
104  case 10:
105  result += text2int_table[text[text_len - 10]][9];
106  case 9:
107  result += text2int_table[text[text_len - 9]][8];
108  case 8:
109  result += text2int_table[text[text_len - 8]][7];
110  case 7:
111  result += text2int_table[text[text_len - 7]][6];
112  case 6:
113  result += text2int_table[text[text_len - 6]][5];
114  case 5:
115  result += text2int_table[text[text_len - 5]][4];
116  case 4:
117  result += text2int_table[text[text_len - 4]][3];
118  case 3:
119  result += text2int_table[text[text_len - 3]][2];
120  case 2:
121  result += text2int_table[text[text_len - 2]][1];
122  case 1:
123  result += text2int_table[text[text_len - 1]][0];
124  default:
125  break;
126  }
127  return (result);
128 }
129 
130 extern int_fast32_t text2int32(const char *textString, uint_fast8_t text_len) NONNULL_PARAMETERS(1) OME_ALWAYS_OPTIMIZE("-O3");
135 inline int_fast32_t text2int32(const char *textString, uint_fast8_t text_len)
136 {
137  OME_PREFETCH(textString, 0, 0);
138  bool isNegative = false;
139  /* find first digit, "-" or "+" */
140  unsigned int i = 0;
141  do { /* for performance, we assume a non-null string */
142  char c = textString[i];
143  /* Note: could use isdigit(), but it would read from
144  * main memory at a minimum; as written, the test is done
145  * against immediate constants.
146  * space, "+", and "-" all precede the digits in the ASCII
147  * character set, so we test against '0' first as it has
148  * the highest probability of failing.
149  */
150  if (OME_EXPECT_TRUE((c >= '0') && (c <= '9'))) { /* have a digit */
151  break;
152  }
153  /* If not a digit, then a "-" is the next most probable
154  * special character we would expect to encounter
155  */
156  if (c == '-') {
157  i += 1; /* skip "-" */
158  isNegative = true;
159  break;
160  }
161  /* Rare, but possible: a leading "+" is simply ignored. */
162  if (c == '+') {
163  i += 1; /* skip "+" */
164  break;
165  }
166  i += 1; /* look at next character (we're assuming whitespace) */
167  }
168  while (i < text_len);
169  uint32_t val = text2uint32(textString + i, text_len - i);
170  /* most of the time, we have positive numbers */
171  if (OME_EXPECT_TRUE(isNegative == false)) {
172  return (static_cast<int_fast32_t>(val));
173  }
174  return (0 - static_cast<int_fast32_t>(val));
175 }
176 
177 extern uint64_t text2uint64(const char *textString, uint_fast8_t text_len) NONNULL_PARAMETERS(1) OME_ALWAYS_INLINE OME_ALWAYS_OPTIMIZE("-O3");
182 inline uint64_t text2uint64(const char *textString, uint_fast8_t text_len)
183 {
184  /* we want to read from the string, but don't intend to use it again */
185  OME_PREFETCH(textString, 0, 0);
186  /* The following all reference addresses determined at link time. */
187  enum { baseOffset = '0' * 20 * sizeof(uint64_t) }; /* offset of first row */
188 #if _ENABLE_TABLE_PREFETCH_ == 1
189  /* We want to read from the conversion table and will be using it
190  * again, so keep it cached if possible. The table is intentionally
191  * laid out so as to keep the interesting section densely packed.
192  * 10 digits, max 20 characters in length, 8 bytes per digit =
193  * 1600 bytes total.
194  * Precache 10 lines to cover up to 8 digits.
195  */
196  OME_PREFETCH(((const char *) text2int64_table) + baseOffset + 9 * CACHE_LINE_LENGTH, 0, 3);
197  OME_PREFETCH(((const char *) text2int64_table) + baseOffset + 8 * CACHE_LINE_LENGTH, 0, 3);
198  OME_PREFETCH(((const char *) text2int64_table) + baseOffset + 7 * CACHE_LINE_LENGTH, 0, 3);
199  OME_PREFETCH(((const char *) text2int64_table) + baseOffset + 6 * CACHE_LINE_LENGTH, 0, 3);
200  OME_PREFETCH(((const char *) text2int64_table) + baseOffset + 5 * CACHE_LINE_LENGTH, 0, 3);
201  OME_PREFETCH(((const char *) text2int64_table) + baseOffset + 4 * CACHE_LINE_LENGTH, 0, 3);
202  OME_PREFETCH(((const char *) text2int64_table) + baseOffset + 3 * CACHE_LINE_LENGTH, 0, 3);
203  OME_PREFETCH(((const char *) text2int64_table) + baseOffset + 2 * CACHE_LINE_LENGTH, 0, 3);
204  OME_PREFETCH(((const char *) text2int64_table) + baseOffset + CACHE_LINE_LENGTH, 0, 3);
205  OME_PREFETCH(((const char *) text2int64_table) + baseOffset, 0, 3);
206 #endif
207  const unsigned char *text = (const unsigned char *) textString;
208  uint64_t result = 0;
209  switch (text_len) {
210  case 20:
211  result += text2int64_table[text[text_len - 20]][19];
212  case 19:
213  result += text2int64_table[text[text_len - 19]][18];
214  case 18:
215  result += text2int64_table[text[text_len - 18]][17];
216  case 17:
217  result += text2int64_table[text[text_len - 17]][16];
218  case 16:
219  result += text2int64_table[text[text_len - 16]][15];
220  case 15:
221  result += text2int64_table[text[text_len - 15]][14];
222  case 14:
223  result += text2int64_table[text[text_len - 14]][13];
224  case 13:
225  result += text2int64_table[text[text_len - 13]][12];
226  case 12:
227  result += text2int64_table[text[text_len - 12]][11];
228  case 11:
229  result += text2int64_table[text[text_len - 11]][10];
230  case 10:
231  result += text2int64_table[text[text_len - 10]][9];
232  case 9:
233  result += text2int64_table[text[text_len - 9]][8];
234  case 8:
235  result += text2int64_table[text[text_len - 8]][7];
236  case 7:
237  result += text2int64_table[text[text_len - 7]][6];
238  case 6:
239  result += text2int64_table[text[text_len - 6]][5];
240  case 5:
241  result += text2int64_table[text[text_len - 5]][4];
242  case 4:
243  result += text2int64_table[text[text_len - 4]][3];
244  case 3:
245  result += text2int64_table[text[text_len - 3]][2];
246  case 2:
247  result += text2int64_table[text[text_len - 2]][1];
248  case 1:
249  result += text2int64_table[text[text_len - 1]][0];
250  default:
251  break;
252  }
253  return (result);
254 }
255 
256 extern int64_t text2int64(const char *textString, uint_fast8_t text_len) NONNULL_PARAMETERS(1) OME_ALWAYS_OPTIMIZE("-O3");
265 inline int64_t text2int64(const char *textString, uint_fast8_t text_len)
266 {
267  OME_PREFETCH(textString, 0, 0);
268  bool isNegative = false;
269  /* find first digit, "-" or "+" */
270  unsigned int i = 0;
271  do { /* for performance, we assume a non-null string */
272  char c = textString[i];
273  if (OME_EXPECT_TRUE((c >= '0') && (c <= '9'))) { /* have a digit */
274  break;
275  }
276  if (c == '-') {
277  i += 1; /* skip "-" */
278  isNegative = true;
279  break;
280  }
281  if (c == '+') {
282  i += 1; /* skip "+" */
283  break;
284  }
285  i += 1; /* look at next character */
286  }
287  while (i < text_len);
288  uint64_t val = text2uint64(textString + i, text_len - i);
289  /* most of the time, we have positive numbers */
290  if (OME_EXPECT_TRUE(isNegative == false)) {
291  return (static_cast<int64_t>(val));
292  }
293  return (0 - static_cast<int64_t>(val));
294 }
295 
296 
297 extern uint32_t n2to_uint32(const void *byteData) NONNULL_PARAMETERS(1) OME_ALWAYS_INLINE OME_ALWAYS_OPTIMIZE("-O3");
300 inline uint32_t n2to_uint32(const void *byteData)
301 {
302  const unsigned char *bytes = reinterpret_cast<const unsigned char *>(byteData);
303 
304  uint32_t result;
305 #if (__PERMIT_UNALIGNED_READS == 1) && defined(__GNUC__)
306  const uint16_t *u16p = reinterpret_cast<const uint16_t *>(bytes);
307 #if _HB_PATTERN == _BE_PATTERN
308  result = *u16p;
309 #else
310  result = __builtin_bswap16(*u16p);
311 #endif
312 #else // unaligned reads not permitted or not gcc
313  result = bytes[0] * 0x100 + bytes[1];
314 #endif
315  return (result);
316 }
317 
318 extern uint32_t n4to_uint32(const void *byteData) NONNULL_PARAMETERS(1) OME_ALWAYS_INLINE OME_ALWAYS_OPTIMIZE("-O3");
321 inline uint32_t n4to_uint32(const void *byteData)
322 {
323  const unsigned char *bytes = reinterpret_cast<const unsigned char *>(byteData);
324  uint32_t result;
325 #if (__PERMIT_UNALIGNED_READS == 1) && defined(__GNUC__)
326  const uint32_t *u32p = reinterpret_cast<const uint32_t *>(bytes);
327 #if _HB_PATTERN == _BE_PATTERN
328  result = *u32p;
329 #else
330  result = __builtin_bswap32(*u32p);
331 #endif
332 #else // unaligned reads not permitted or not gcc
333  result = bytes[0] * static_cast<uint32_t>(0x1000000) +
334  bytes[1] * static_cast<uint32_t>(0x10000) +
335  bytes[2] * static_cast<uint32_t>(0x100) +
336  bytes[3];
337 #endif
338  return (result);
339 }
340 
341 extern uint64_t n8to_uint64(const void *byteData) NONNULL_PARAMETERS(1) OME_ALWAYS_INLINE OME_ALWAYS_OPTIMIZE("-O3");
344 inline uint64_t n8to_uint64(const void *byteData)
345 {
346  const unsigned char *bytes = reinterpret_cast<const unsigned char *>(byteData);
347  uint64_t result;
348 #if (__PERMIT_UNALIGNED_READS == 1) && defined(__GNUC__)
349  const uint64_t *u64p = reinterpret_cast<const uint64_t *>(bytes);
350 #if _HB_PATTERN == _BE_PATTERN
351  result = *u64p;
352 #else
353  result = __builtin_bswap64(*u64p);
354 #endif
355 #else // unaligned reads not permitted or not gcc
356  result = bytes[0] * static_cast<uint64_t>(0x100000000000000) +
357  bytes[1] * static_cast<uint64_t>(0x1000000000000) +
358  bytes[2] * static_cast<uint64_t>(0x10000000000) +
359  bytes[3] * static_cast<uint64_t>(0x100000000) +
360  bytes[4] * static_cast<uint64_t>(0x1000000) +
361  bytes[5] * static_cast<uint64_t>(0x10000) +
362  bytes[6] * static_cast<uint64_t>(0x100) +
363  bytes[7];
364 #endif
365  return (result);
366 }
367 
368 /* We only handle big-endian and little endian, not DEC PDP order.
369  * For the time being, we assume if not known to be big endian...it's little
370  * endian.
371  * These functions are evaluated at COMPILE time, not runtime,
372  * so we don't care about any specialized support from the target CPU,
373  * like a swap instruction.
374  * Typical usage is with switch-statement case labels to make decisions
375  * based on PDU types encoded in network byte order without first needing
376  * to do any byte-order manipulation.
377  */
379 extern CONSTEXPR uint16_t const_uint16_ton2(const uint16_t arg) OME_ALWAYS_INLINE OME_PURE_FUNCTION OME_ALWAYS_OPTIMIZE("-O3");
381 extern CONSTEXPR uint32_t const_uint32_ton4(const uint32_t arg) OME_ALWAYS_INLINE OME_PURE_FUNCTION OME_ALWAYS_OPTIMIZE("-O3");
383 extern CONSTEXPR uint64_t const_uint64_ton8(const uint64_t arg) OME_ALWAYS_INLINE OME_PURE_FUNCTION OME_ALWAYS_OPTIMIZE("-O3");
384 #if _HB_PATTERN == _BE_PATTERN
385 /* we believe host byte order is big endian, so same as network byte order */
386 inline CONSTEXPR uint16_t const_uint16_ton2(const uint16_t arg)
387 {
388  return (arg);
389 }
390 
391 inline CONSTEXPR uint32_t const_uint32_ton4(const uint32_t arg)
392 {
393  return (arg);
394 }
395 
396 inline CONSTEXPR uint64_t const_uint64_ton8(const uint64_t arg)
397 {
398  return (arg);
399 }
400 #else
401 /* we assume host byte order is little endian */
402 inline CONSTEXPR uint16_t const_uint16_ton2(const uint16_t arg)
403 {
404  return (((arg & 0xff) << 8) | ((arg >> 8) & 0xff));
405 }
406 
407 inline CONSTEXPR uint32_t const_uint32_ton4(const uint32_t arg)
408 {
409  return (((arg & 0xff) << 24) |
410  (((arg >> 8) & 0xff) << 16) |
411  (((arg >> 16) & 0xff) << 8) |
412  ((arg >> 24) & 0xff));
413 }
414 
415 inline CONSTEXPR uint64_t const_uint64_ton8(const uint64_t arg)
416 {
417  return (((arg & 0xff) << 56) |
418  (((arg >> 8) & 0xff) << 48) |
419  (((arg >> 16) & 0xff) << 40) |
420  (((arg >> 24) & 0xff) << 32) |
421  (((arg >> 32) & 0xff) << 24) |
422  (((arg >> 40) & 0xff) << 16) |
423  (((arg >> 48) & 0xff) << 8) |
424  ((arg >> 56) & 0xff));
425 }
426 #endif
427 
450 extern char *uint_to_ascii(uint32_t workBfr[], uint_fast8_t bfrLen,
451  uint64_t value, uint_fast8_t *retStrLen = nullptr) NONNULL_RETURN;
452 
458 extern char *int_to_ascii(uint32_t workBfr[], uint_fast8_t bfrLen,
459  int64_t value, uint_fast8_t *retStrLen = nullptr) NONNULL_RETURN;
460 
467 #define CONVERT_UINT_TO_TEXT(varName, sourceVal) uint32_t _workBfr_ ## varName [6]; char *varName = uint_to_ascii(_workBfr_ ## varName, sizeof(_workBfr_ ## varName), sourceVal)
468 
476 #define CONVERT_INT_TO_TEXT(varName, sourceVal) uint32_t _workBfr_ ## varName [6]; char *varName = int_to_ascii(_workBfr_ ## varName, sizeof(_workBfr_ ## varName), sourceVal);
477 
497 extern char *uint_to_ascii_right_justified(uint32_t workBfr[], uint_fast8_t bfrLen,
498  uint64_t value, uint_fast8_t fieldWidth, char fillChar = ' ') NONNULL_RETURN;
499 
519 extern char *fixedpoint_to_ascii(char *resultBfr, uint_fast8_t bfrLen,
520  int64_t value, uint_fast8_t decimals, uint_fast8_t *retStrLen = nullptr,
521  int_fast8_t outputPrecision = -2) NONNULL_RETURN;
522 
526 // NOTE: this is suitable for C usage
528  int64_t value;
529  int_fast8_t precision;
530 };
531 
546  uint_fast8_t len = 0, int_fast8_t desiredPrecision = -2) NONNULL_PARAMETERS(1);
547 
565 extern int64_t ascii_to_fixedpoint(
566  const char *str, uint_fast8_t *resultPrecision = nullptr,
567  uint_fast8_t len = 0, int_fast8_t desiredPrecision = -2) NONNULL_PARAMETERS(1) OME_ALWAYS_INLINE;
568 
569 inline int64_t ascii_to_fixedpoint(const char *str,
570  uint_fast8_t *resultPrecision, uint_fast8_t len,
571  int_fast8_t desiredPrecision)
572 {
574  desiredPrecision);
575  if (resultPrecision != nullptr) {
576  *resultPrecision = static_cast<uint_fast8_t>(result.precision);
577  }
578  return (result.value);
579 }
580 
581 
593 extern double text2double(const char *str, uint_fast8_t len = 0) NONNULL_PARAMETERS(1);
594 
595 
617 extern char *float_to_ascii(char *resultBfr, uint_fast8_t bfrLen,
618  double value, uint_fast8_t *retStrLen = nullptr,
619  int_fast8_t outputPrecision = -2,
620  bool roundValue = false) NONNULL_PARAMETERS(1) NONNULL_RETURN;
621 
622 extern uint_fast8_t bytesInUTFcharacter(const char val) OME_PURE_FUNCTION OME_ALWAYS_INLINE OME_ALWAYS_OPTIMIZE("-O3");
623 
627 inline uint_fast8_t bytesInUTFcharacter(const char val)
628 {
629  if (OME_EXPECT_TRUE((val & 0x80) == 0)) {
630  return (1);
631  }
632  if ((val & 0xe0) == 0xc0) {
633  return (2);
634  }
635  if ((val & 0xf0) == 0xe0) {
636  return (3);
637  }
638  if ((val & 0xf8) == 0xf0) {
639  return (4);
640  }
641  if ((val & 0xfc) == 0xf8) {
642  return (5);
643  }
644  // assume...
645  return (6);
646 }
647 
648 extern uint_fast8_t bytesInUTFchar(const void *s) NONNULL_PARAMETERS(1) OME_ALWAYS_INLINE OME_ALWAYS_OPTIMIZE("-O3");
649 
653 inline uint_fast8_t bytesInUTFchar(const void *s)
654 {
655  const char *ptr = (const char *) s;
656  return (bytesInUTFcharacter(*ptr));
657 }
658 
659 #pragma GCC diagnostic pop
660 
661 #ifdef __cplusplus
662 }; /* close extern "C" scope */
663 #endif
664 
665 #ifdef __cplusplus
666 /* NOTE: this C++ template cannot be used in C source and must be outside
667  * the extern "C" scope
668  */
669 
670 template <unsigned int EXPONENT> extern CONSTEXPR uint64_t powerOf10Constant() OME_CONST_FUNCTION OME_ALWAYS_INLINE;
671 
678 template <unsigned int EXPONENT> inline CONSTEXPR uint64_t powerOf10Constant()
679 {
680  return (powerOf10Constant < EXPONENT - 1 > () * 10);
681 }
682 
684 // specialization of powerOf10Constant<>() to stop recursion at 0
685 template <> inline CONSTEXPR uint64_t powerOf10Constant<0>()
686 {
687  return (static_cast<uint64_t>(1));
688 }
690 
691 #pragma GCC diagnostic push
692 #pragma GCC diagnostic ignored "-Wmissing-attributes"
693 
694 // declare to permit attributes to be assigned
695 template <unsigned int LEN> extern uint_fast32_t right_padded_strlen(const char *s, const char PADDING_CHAR = ' ') NONNULL_PARAMETERS(1) OME_ALWAYS_INLINE OME_ALWAYS_OPTIMIZE("-O3");
696 
714 template <unsigned int LEN> inline uint_fast32_t right_padded_strlen(const char *s, const char PADDING_CHAR)
715 {
716  return ((s[LEN - 1] != PADDING_CHAR) ? LEN : right_padded_strlen < LEN - 1 > (s, PADDING_CHAR));
717 }
718 
719 template <> inline uint_fast32_t right_padded_strlen<0>(const char *s, const char PADDING_CHAR) NONNULL_PARAMETERS(1);
721 template <> inline uint_fast32_t right_padded_strlen<0>(const char *s, const char PADDING_CHAR)
722 {
723  return (0);
724 }
725 
747 template <uint_fast8_t FIELD_LEN> inline uint64_t textField2uint(const char *field)
748 {
749  return ( ((field[0] - '0') * powerOf10Constant<FIELD_LEN - 1>()) +
750  textField2uint<FIELD_LEN - 1>(field + 1) );
751 
752 }
753 
755 // specialization for single character string
756 template<> inline uint64_t textField2uint<1>(const char *field)
757 {
758  return (field[0] - '0');
759 }
760 
761 // specialization for a null string
762 template<> inline uint64_t textField2uint<0>(const char *field)
763 {
764  return (0);
765 }
767 
782 template <uint_fast8_t FIELD_LEN> int64_t textField2int(const char *field)
783 {
784  return ((field[0] == '-') ?
785  (0 - static_cast<int64_t>(textField2uint<FIELD_LEN - 1>(field + 1))) :
786  ((field[0] == '+') ? static_cast<int64_t>(textField2uint<FIELD_LEN - 1>(field + 1)) :
787  ((field[0] == ' ') ? textField2int<FIELD_LEN - 1>(field + 1) :
788  static_cast<int64_t>(textField2uint<FIELD_LEN>(field))) ));
789 }
790 
792 // specialization for a null string
793 template<> inline int64_t textField2int<0>(const char *field)
794 {
795  return (0);
796 }
797 
798 inline int64_t fastTextField2int(const char *field, uint_fast8_t len=0) OME_ALWAYS_INLINE OME_ALWAYS_OPTIMIZE("-O3");
812 inline int64_t fastTextField2int(const char *field, uint_fast8_t len)
813 {
814  if (len == 0) {
815  len = strlen(field);
816  }
817  switch (len) {
818  case 20:
819  return (textField2int<20>(field));
820  case 19:
821  return (textField2int<19>(field));
822  case 18:
823  return (textField2int<18>(field));
824  case 17:
825  return (textField2int<17>(field));
826  case 16:
827  return (textField2int<16>(field));
828  case 15:
829  return (textField2int<15>(field));
830  case 14:
831  return (textField2int<14>(field));
832  case 13:
833  return (textField2int<13>(field));
834  case 12:
835  return (textField2int<12>(field));
836  case 11:
837  return (textField2int<11>(field));
838  case 10:
839  return (textField2int<10>(field));
840  case 9:
841  return (textField2int<9>(field));
842  case 8:
843  return (textField2int<8>(field));
844  case 7:
845  return (textField2int<7>(field));
846  case 6:
847  return (textField2int<6>(field));
848  case 5:
849  return (textField2int<5>(field));
850  case 4:
851  return (textField2int<4>(field));
852  case 3:
853  return (textField2int<3>(field));
854  case 2:
855  return (textField2int<2>(field));
856  case 1:
857  return (textField2int<1>(field));
858  default:
859  return (0);
860  } // end switch len
861 }
863 
864 #pragma GCC diagnostic pop
865 
866 extern CONSTEXPR double cleanedNumericValue(double v, double maxResolution) OME_ALWAYS_INLINE OME_ALWAYS_OPTIMIZE("-O3");
875 inline CONSTEXPR double cleanedNumericValue(double v, double minPrecision)
876 {
877  // would use fabs(v) but it is not constexpr on all platforms
878  return ((((v >= 0) ? v : -v) >= minPrecision) ? v : 0);
879 }
880 
881 extern CONSTEXPR double cleanedPositiveNumericValue(double v, double maxResolution) OME_ALWAYS_INLINE OME_ALWAYS_OPTIMIZE("-O3");
890 inline CONSTEXPR double cleanedPositiveNumericValue(double v, double minPrecision)
891 {
892  return ((v >= minPrecision) ? v : 0);
893 }
894 
895 template <typename STREAMTYPE> STREAMTYPE &operator<<(STREAMTYPE &os, const VariableFixedPointValue arg)
896 {
897  char bfr[64];
898  os << fixedpoint_to_ascii(bfr, sizeof(bfr), arg.value, arg.precision);
899  return (os);
900 }
901 
902 
903 #endif /* end C++-specific functions */
904 
908 #endif
909 /* vim: set expandtab shiftwidth=4 tabstop=4: */
chProtocol
CHAR chProtocol
Definition: sockspx.c:216
safe_strcpy
#define safe_strcpy(d, s, l)
Safe strcpy() routine that will not copy more than l bytes and always ensures that a null is present ...
Definition: compiler_hints.h:696
REC_BYTES
#define REC_BYTES
Definition: test_malloc.c:143
MAX_CALL_DEPTH
#define MAX_CALL_DEPTH
Definition: test_malloc.c:69
text2int32
int_fast32_t text2int32(const char *textString, uint_fast8_t text_len) NONNULL_PARAMETERS(1) OME_ALWAYS_OPTIMIZE("-O3")
Convert a sequence of text characters into a 32-bit signed integer as quickly as possible....
Definition: text2int.h:135
MAX_RANGES
#define MAX_RANGES
Definition: test_malloc.c:97
REC_ALLOC_FILENAME
#define REC_ALLOC_FILENAME
Definition: test_malloc.c:149
right_padded_strlen
uint_fast32_t right_padded_strlen(const char *s, const char PADDING_CHAR=' ') NONNULL_PARAMETERS(1) OME_ALWAYS_INLINE OME_ALWAYS_OPTIMIZE("-O3")
Templated convenience routine to return the length of a possibly padded string. The assumption is tha...
Definition: text2int.h:714
l
Ïúíþ ð Ø ˜ ˜ __text __TEXT € __apple_names __DWARF __apple_objc __DWARF __apple_namespac__DWARF H X __apple_types __DWARF l
Definition: tmp3.o.cpp:1
sock
SOCKET sock
Definition: sockspx.c:203
Usage
void __stdcall Usage(CHAR *pszProgramName)
Definition: sockspx.c:1001
s
const char s[]
Definition: t.cpp:4
newCallLine
int newCallLine[MAX_CALL_DEPTH]
Definition: test_malloc.c:72
main
int main(int argc, char *argv[])
Definition: testIf.cpp:37
OMEfunctions.h
OME utility functions.
unlockMEM
#define unlockMEM()
Definition: test_malloc.c:9
stdout
#define stdout
Definition: tmp.o.cpp:3117
REC_LENGTH
#define REC_LENGTH
Definition: test_malloc.c:142
BLOCK_ALIGNMENT
#define BLOCK_ALIGNMENT
Definition: test_malloc.c:68
dump_malloc_blocks
void dump_malloc_blocks(int age, int resetDumpTime)
Definition: test_malloc.c:199
pamConvFunc
int pamConvFunc(int numMess, const struct pam_message *msg[], struct pam_response **pam_resp, void *appData)
Definition: t.c:10
byteAsLowercaseHexadecimal
const char byteAsLowercaseHexadecimal[256][3]
Table of uppercase hexadecimal characters for each byte value.
Definition: text2int.cpp:38
uint_to_ascii_right_justified
char * uint_to_ascii_right_justified(uint32_t resultBfr[], uint_fast8_t bfrLen, uint64_t value, uint_fast8_t fieldLen, char fillChar)
Convert a binary integer into right-justified ASCII decimal text and pad on the left with a specified...
Definition: text2int.cpp:2718
realloc
char * realloc(char *block, unsigned int size)
Definition: test_malloc.c:618
Aligned4Chars::lastThreeDigits
struct Aligned4Chars::@4 lastThreeDigits
main
int main(int argc, const char *argv[])
Definition: t.cpp:46
stderr
#define stderr
Definition: tmp.o.cpp:3115
calloc
char * calloc(unsigned int nelem, unsigned int elsize)
Definition: test_malloc.c:687
arrayTest
void arrayTest()
Definition: test.cpp:122
OMEtype
Fundamental ANY type for FARGOS/VISTA Object Management Environment.
Definition: OMEbaseType.h:250
ReceiveDatagarm
INT __stdcall ReceiveDatagarm(SOCKET s, CHAR *pchBuffer, SOCKADDR_IPX *psa, INT *pcb)
Definition: sockspx.c:835
setTest
void setTest()
Definition: test.cpp:92
powersOf10_64bit
const uint64_t powersOf10_64bit[16]
Table of powers-of-10 constants as 64-bit unsigned integers.
Definition: text2int_tbl.h:46
Aligned4Chars
Table of word-aligned 4-character groups representing 0000-9999.
Definition: text2int_tbl.h:708
numberAs4Digits
const union Aligned4Chars numberAs4Digits[10000]
Definition: text2int.cpp:124
REC_TIME
#define REC_TIME
Definition: test_malloc.c:145
newCallFile
char * newCallFile[MAX_CALL_DEPTH]
Definition: test_malloc.c:73
OMEarrayStorage
Reference-counted maintainer of a sparse array.
Definition: OMEarray.h:23
OME_ALWAYS_OPTIMIZE
#define OME_ALWAYS_OPTIMIZE(level)
Mark a function to be compiled with a specific level of optimization.
Definition: compiler_hints.h:406
PrintIpxAddress
void __stdcall PrintIpxAddress(CHAR *lpsNetnum, CHAR *lpsNodenum)
Definition: sockspx.c:1046
REC_ALLOC_NEXT
#define REC_ALLOC_NEXT
Definition: test_malloc.c:146
fServer
BOOL fServer
Definition: sockspx.c:194
__GNUC__
#define __GNUC__
Definition: tmp.o.cpp:2554
ascii_to_fixedpoint
int64_t ascii_to_fixedpoint(const char *str, uint_fast8_t *resultPrecision=nullptr, uint_fast8_t len=0, int_fast8_t desiredPrecision=-2) NONNULL_PARAMETERS(1) OME_ALWAYS_INLINE
Convert ASCII decimal text string to fixed point representation.
Definition: text2int.h:569
FillIpxAddress
void _stdcall FillIpxAddress(SOCKADDR_IPX *psa, LPSTR lpsAddress, LPSTR lpsEndpoint)
Definition: sockspx.c:696
fEnumerate
BOOL fEnumerate
Definition: sockspx.c:197
fStarted
BOOL fStarted
Definition: sockspx.c:200
OMEarray::outputOnStream
STREAMTYPE & outputOnStream(STREAMTYPE &outputStream, int_fast16_t indent=0, uint8_t includeTypePrefix=OME_DEFAULT_COMPLEX_OUTPUT_MODE) const
Output an OMEarray to an output stream.
Definition: OMEarray.h:275
NONNULL_PARAMETERS
#define NONNULL_PARAMETERS(...)
Mark parameters to a function as not permitting null pointers.
Definition: compiler_hints.h:335
REC_ALLOC_PREV
#define REC_ALLOC_PREV
Definition: test_malloc.c:147
OMEgetInterfaces
OME_DLL_EXPORT int OMEgetInterfaces(OMEtype &result)
Definition: OMEifList.cpp:290
POOL_SIZE
#define POOL_SIZE
Definition: test_malloc.c:83
EnumerateAdapters
void __stdcall EnumerateAdapters(void)
Definition: sockspx.c:292
n4to_uint32
uint32_t n4to_uint32(const void *byteData) NONNULL_PARAMETERS(1) OME_ALWAYS_INLINE OME_ALWAYS_OPTIMIZE("-O3")
Convert a network byte order 4-byte integer into a native unsigned 32-bit value.
Definition: text2int.h:321
OME_PREFETCH
#define OME_PREFETCH(addr, rw, locality)
Macro to request prefetch.
Definition: compiler_hints.h:362
reciprocalPowersOf10
const double reciprocalPowersOf10[16]
Table of reciprocal powers-of-10 divisors.
Definition: text2int_tbl.h:75
VariableFixedPointValue::precision
int_fast8_t precision
Definition: text2int.h:529
VariableFixedPointValue
Return value structure for representing fixed-point values with variable precision.
Definition: text2int.h:527
fixedpoint_to_ascii
char * fixedpoint_to_ascii(char *resultBfr, uint_fast8_t bfrLen, int64_t value, uint_fast8_t precision, uint_fast8_t *retStrLen, int_fast8_t outputPrecision)
Format a fixed-point value with indicated decimal places.
Definition: text2int.cpp:2734
SendData
INT __stdcall SendData(SOCKET s, CHAR *pchBuffer)
Definition: sockspx.c:747
INVALID_SOCKET
#define INVALID_SOCKET
Definition: io_processor.hpp:55
trap_bad_assert
void trap_bad_assert()
Definition: test_malloc.c:254
srcID
const char srcID[]
Definition: catSym.c:17
const_uint32_ton4
CONSTEXPR uint32_t const_uint32_ton4(const uint32_t arg) OME_ALWAYS_INLINE OME_PURE_FUNCTION OME_ALWAYS_OPTIMIZE("-O3")
Equivalent of htonl(), but evaluated at compile time.
Definition: text2int.h:391
ReceiveData
INT __stdcall ReceiveData(SOCKET s, CHAR *pchBuffer)
Definition: sockspx.c:776
PrintError
void __stdcall PrintError(CHAR *lpszRoutine, CHAR *lpszCallName, DWORD dwError)
Definition: sockspx.c:1025
REC_SIGNATURE
#define REC_SIGNATURE
Definition: test_malloc.c:150
OMEset
Implements an ordered list of OMEtype elements.
Definition: OMEset.h:64
CreateSocket
void __stdcall CreateSocket(void)
Definition: sockspx.c:632
const_uint64_ton8
CONSTEXPR uint64_t const_uint64_ton8(const uint64_t arg) OME_ALWAYS_INLINE OME_PURE_FUNCTION OME_ALWAYS_OPTIMIZE("-O3")
Equivalent of htonll(), but evaluated at compile time.
Definition: text2int.h:396
CACHE_LINE_LENGTH
#define CACHE_LINE_LENGTH
Definition for target system's cache line length.
Definition: compiler_hints.h:576
cleanedNumericValue
CONSTEXPR double cleanedNumericValue(double v, double maxResolution) OME_ALWAYS_INLINE OME_ALWAYS_OPTIMIZE("-O3")
Return value clipped to 0 if not above a threshold of precision.
Definition: text2int.h:875
n8to_uint64
uint64_t n8to_uint64(const void *byteData) NONNULL_PARAMETERS(1) OME_ALWAYS_INLINE OME_ALWAYS_OPTIMIZE("-O3")
Convert a network byte order 8-byte integer into a native unsigned 64-bit value.
Definition: text2int.h:344
WORDS_IN_RECORD
#define WORDS_IN_RECORD
Definition: test_malloc.c:153
const_uint16_ton2
CONSTEXPR uint16_t const_uint16_ton2(const uint16_t arg) OME_ALWAYS_INLINE OME_PURE_FUNCTION OME_ALWAYS_OPTIMIZE("-O3")
Equivalent of htons(), but evaluated at compile time.
Definition: text2int.h:386
mallocStopPoint
void mallocStopPoint()
Definition: test_malloc.c:249
SendDatagram
INT __stdcall SendDatagram(SOCKET s, CHAR *pchBuffer, SOCKADDR_IPX *psa)
Definition: sockspx.c:805
newsock
SOCKET newsock
Definition: sockspx.c:204
OME_EXPECT_TRUE
#define OME_EXPECT_TRUE(expr)
Annotation macro for conditional expression expected to be true.
Definition: compiler_hints.h:541
numberAsTwoDigits
const char numberAsTwoDigits[100][3]
Table of 2-character strings representing 00-99.
Definition: text2int.cpp:20
right_padded_strlen< 0 >
uint_fast32_t right_padded_strlen< 0 >(const char *s, const char PADDING_CHAR) NONNULL_PARAMETERS(1)
specialization to stop recursion at length 0
Definition: text2int.h:721
text2uint32
uint_fast32_t text2uint32(const char *textString, uint_fast8_t text_len) NONNULL_PARAMETERS(1) OME_ALWAYS_INLINE OME_ALWAYS_OPTIMIZE("-O3")
Convert a sequence of text characters into an unsigned integer as quickly as possible....
Definition: text2int.h:79
CtrlCHandler
BOOL __stdcall CtrlCHandler(DWORD dwEvent)
Definition: sockspx.c:274
text2int.h
Extreme-performance text/number conversion routines.
NULL
#define NULL
Definition: tmp.o.cpp:327
MAX_DATA_LEN
#define MAX_DATA_LEN
Definition: sockspx.c:83
DoClient
void __stdcall DoClient(void)
Definition: sockspx.c:489
bytesInUTFcharacter
uint_fast8_t bytesInUTFcharacter(const char val) OME_PURE_FUNCTION OME_ALWAYS_INLINE OME_ALWAYS_OPTIMIZE("-O3")
Return number of bytes required to represent UTF-encoded character as indicated by value of leading b...
Definition: text2int.h:627
float_to_ascii
char * float_to_ascii(char *resultBfr, uint_fast8_t bfrLen, double value, uint_fast8_t *retStrLen, int_fast8_t outputPrecision, bool roundValue)
Format a double-precision value with indicated decimal places.
Definition: text2int.cpp:2808
OMEtype.h
OME fundamental type implementation.
main
main()
Definition: t.c:27
arrayBaseTest
void arrayBaseTest()
Definition: test.cpp:6
int_to_ascii
char * int_to_ascii(uint32_t resultBfr[], uint_fast8_t bfrLen, int64_t value, uint_fast8_t *retStrLen)
Identical to uint_to_ascii(), except that negative values are accepted.
Definition: text2int.cpp:2699
DoStartup
void __stdcall DoStartup(void)
Definition: sockspx.c:607
pszServerEndpoint
CHAR * pszServerEndpoint
Definition: sockspx.c:213
REC_ALLOC_LINENUM
#define REC_ALLOC_LINENUM
Definition: test_malloc.c:148
OME_USED
const char srcID[] OME_USED
Definition: tick_time.cpp:24
main
main()
Definition: test.cpp:160
AtoH
void __stdcall AtoH(CHAR *szDest, CHAR *szSource, INT iCount)
Definition: sockspx.c:1075
stringTest
void stringTest()
Definition: test.cpp:77
REC_NEXT
#define REC_NEXT
Definition: test_malloc.c:144
text2double
double text2double(const char *str, uint_fast8_t len)
Convert ASCII decimal text string to a double.
Definition: text2int.cpp:2955
OME_CONST_FUNCTION
#define OME_CONST_FUNCTION
Mark as an idempotent function that only accesses arguments – no global data.
Definition: compiler_hints.h:390
operator<<
STREAMTYPE & operator<<(STREAMTYPE &os, const VariableFixedPointValue arg)
Definition: text2int.h:895
VariableFixedPointValue::value
int64_t value
Definition: text2int.h:528
OME_SET
@ OME_SET
Definition: OMEmanifests.h:89
OMEmanifests.h
OME constants and typedefs.
text2int_tbl.h
Internal tables used for extreme performance text/number conversion routines.
text2int_table
const uint32_t text2int_table[256][10]
Convert ASCII digit into corresponding 32-bit value.
Definition: text2int_tbl.h:95
compiler_hints.h
Compiler-specific macros to provide performance-related hints.
OME_EXPECT_FALSE
#define OME_EXPECT_FALSE(expr)
Annotation macro for conditional expression expected to be false.
Definition: compiler_hints.h:540
DoServer
void __stdcall DoServer(void)
Definition: sockspx.c:377
CheckProtocol
BOOL __stdcall CheckProtocol(CHAR chProtocol)
Definition: sockspx.c:985
OME_ALWAYS_INLINE
#define OME_ALWAYS_INLINE
Tell the compiler to alway inline a function, regardless of optimization level.
Definition: compiler_hints.h:364
Aligned4Chars::digits
char digits[4]
Definition: text2int_tbl.h:709
powerOf10Constant
CONSTEXPR uint64_t powerOf10Constant() OME_CONST_FUNCTION OME_ALWAYS_INLINE
Generate compile-time constant for integral power of 10.
Definition: text2int.h:678
BtoH
UCHAR __stdcall BtoH(CHAR ch)
Definition: sockspx.c:1093
cleanedPositiveNumericValue
CONSTEXPR double cleanedPositiveNumericValue(double v, double maxResolution) OME_ALWAYS_INLINE OME_ALWAYS_OPTIMIZE("-O3")
Return value clipped to 0 if not above a threshold of precision.
Definition: text2int.h:890
malloc
char * malloc(unsigned int bytes)
Definition: test_malloc.c:441
CheckParameters
void __stdcall CheckParameters(INT argc, CHAR **argv)
Definition: sockspx.c:894
main
void __cdecl main(INT argc, CHAR **argv)
Definition: sockspx.c:219
textField2int
int64_t textField2int(const char *field)
Templated ASCII-to-integer conversion routine that converts fixed-length fields.
Definition: text2int.h:782
DoCleanup
void __stdcall DoCleanup(void)
Definition: sockspx.c:868
trace_malloc
int trace_malloc
Definition: test_malloc.c:66
pszServerAddress
CHAR * pszServerAddress
Definition: sockspx.c:207
OMEarray
Implements sparse array of OMEtype elements.
Definition: OMEarray.h:75
main
int main(int argc, const char *argv[])
Definition: testint.c:7
Aligned4Chars::val
uint32_t val
Definition: text2int_tbl.h:710
READ_ONLY_OMEtype
const class OMEtype & READ_ONLY_OMEtype
A convenience typedef for performing read-only access to sparse and associative arrays....
Definition: OMEtype.h:58
byteAsUppercaseHexadecimal
const char byteAsUppercaseHexadecimal[256][3]
Table of uppercase hexadecimal characters for each byte value.
Definition: text2int.cpp:78
text2int64_table
const uint64_t text2int64_table[256][20]
Convert ASCII digit into corresponding 64-bit value.
Definition: text2int_tbl.h:384
free
void free(char *block)
Definition: test_malloc.c:553
assocTest
void assocTest()
Definition: test.cpp:139
BindSocket
void __stdcall BindSocket(SOCKADDR_IPX *psa, LPSTR lpsAddress, LPSTR lpsEndpoint)
Definition: sockspx.c:654
uint_to_ascii
char * uint_to_ascii(uint32_t resultBfr[], uint_fast8_t bfrLen, uint64_t value, uint_fast8_t *retStrLen)
Quickly convert a binary integer into ASCII decimal text.
Definition: text2int.cpp:2628
OMEextendedType
Storage record for large-sized elements on 32-bit hardware.
Definition: OMEbaseType.h:28
OME_ARRAY
@ OME_ARRAY
Definition: OMEmanifests.h:86
fast_ascii_to_fixedpoint
VariableFixedPointValue fast_ascii_to_fixedpoint(const char *str, uint_fast8_t len, int_fast8_t desiredPrecision)
Convert ASCII decimal text string to fixed point representation.
Definition: text2int.cpp:2888
n2to_uint32
uint32_t n2to_uint32(const void *byteData) NONNULL_PARAMETERS(1) OME_ALWAYS_INLINE OME_ALWAYS_OPTIMIZE("-O3")
Convert a network byte order 2-byte integer into a native unsigned 32-bit value.
Definition: text2int.h:300
text2int64
int64_t text2int64(const char *textString, uint_fast8_t text_len) NONNULL_PARAMETERS(1) OME_ALWAYS_OPTIMIZE("-O3")
Convert a sequence of text characters into a 64-bit signed integer as quickly as possible....
Definition: text2int.h:265
newCallSP
int newCallSP
Definition: test_malloc.c:71
lockMEM
#define lockMEM()
Definition: test_malloc.c:8
crypt
char * crypt(const char *, const char *)
Aligned4Chars::lastTwoDigits
struct Aligned4Chars::@3 lastTwoDigits
CONSTEXPR
#define CONSTEXPR
Generates constexpr if the compiler supports it.
Definition: compiler_hints.h:432
NONNULL_RETURN
char NONNULL_RETURN
Definition: compiler_hints.h:745
set_malloc_dump_time
void set_malloc_dump_time(unsigned long t, int blockSizeLimit)
Definition: test_malloc.c:266
text2uint64
uint64_t text2uint64(const char *textString, uint_fast8_t text_len) NONNULL_PARAMETERS(1) OME_ALWAYS_INLINE OME_ALWAYS_OPTIMIZE("-O3")
Convert a sequence of text characters into a 64-bit unsigned integer as quickly as possible.
Definition: text2int.h:182
OME_ASSOC
@ OME_ASSOC
Definition: OMEmanifests.h:87
textField2uint
uint64_t textField2uint(const char *field)
Templated ASCII-to-integer conversion routine that very quickly converts fixed-length fields of posit...
Definition: text2int.h:747
OME_PURE_FUNCTION
#define OME_PURE_FUNCTION
Mark as an idempotent function that can access global variables.
Definition: compiler_hints.h:388
floatingPowersOf10
const double floatingPowersOf10[10]
Table of powers-of-10 constants as floating-point values.
Definition: text2int_tbl.h:61
pszLocalAddress
CHAR * pszLocalAddress
Definition: sockspx.c:210
bytesInUTFchar
uint_fast8_t bytesInUTFchar(const void *s) NONNULL_PARAMETERS(1) OME_ALWAYS_INLINE OME_ALWAYS_OPTIMIZE("-O3")
Return number of bytes required to represent UTF-encoded character pointed to by argument.
Definition: text2int.h:653
Generated: Tue Jul 28 2020 16:03:26
Support Information