MCPcopy Create free account
hub / github.com/PeterFWS/Structure-PLP-SLAM / dump_integer

Method dump_integer

3rd/json/include/nlohmann/json.hpp:12590–12666  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12588 std::is_same<NumberType, number_integer_t>::value,
12589 int> = 0>
12590 void dump_integer(NumberType x)
12591 {
12592 static constexpr std::array<std::array<char, 2>, 100> digits_to_99
12593 {
12594 {
12595 {{'0', '0'}}, {{'0', '1'}}, {{'0', '2'}}, {{'0', '3'}}, {{'0', '4'}}, {{'0', '5'}}, {{'0', '6'}}, {{'0', '7'}}, {{'0', '8'}}, {{'0', '9'}},
12596 {{'1', '0'}}, {{'1', '1'}}, {{'1', '2'}}, {{'1', '3'}}, {{'1', '4'}}, {{'1', '5'}}, {{'1', '6'}}, {{'1', '7'}}, {{'1', '8'}}, {{'1', '9'}},
12597 {{'2', '0'}}, {{'2', '1'}}, {{'2', '2'}}, {{'2', '3'}}, {{'2', '4'}}, {{'2', '5'}}, {{'2', '6'}}, {{'2', '7'}}, {{'2', '8'}}, {{'2', '9'}},
12598 {{'3', '0'}}, {{'3', '1'}}, {{'3', '2'}}, {{'3', '3'}}, {{'3', '4'}}, {{'3', '5'}}, {{'3', '6'}}, {{'3', '7'}}, {{'3', '8'}}, {{'3', '9'}},
12599 {{'4', '0'}}, {{'4', '1'}}, {{'4', '2'}}, {{'4', '3'}}, {{'4', '4'}}, {{'4', '5'}}, {{'4', '6'}}, {{'4', '7'}}, {{'4', '8'}}, {{'4', '9'}},
12600 {{'5', '0'}}, {{'5', '1'}}, {{'5', '2'}}, {{'5', '3'}}, {{'5', '4'}}, {{'5', '5'}}, {{'5', '6'}}, {{'5', '7'}}, {{'5', '8'}}, {{'5', '9'}},
12601 {{'6', '0'}}, {{'6', '1'}}, {{'6', '2'}}, {{'6', '3'}}, {{'6', '4'}}, {{'6', '5'}}, {{'6', '6'}}, {{'6', '7'}}, {{'6', '8'}}, {{'6', '9'}},
12602 {{'7', '0'}}, {{'7', '1'}}, {{'7', '2'}}, {{'7', '3'}}, {{'7', '4'}}, {{'7', '5'}}, {{'7', '6'}}, {{'7', '7'}}, {{'7', '8'}}, {{'7', '9'}},
12603 {{'8', '0'}}, {{'8', '1'}}, {{'8', '2'}}, {{'8', '3'}}, {{'8', '4'}}, {{'8', '5'}}, {{'8', '6'}}, {{'8', '7'}}, {{'8', '8'}}, {{'8', '9'}},
12604 {{'9', '0'}}, {{'9', '1'}}, {{'9', '2'}}, {{'9', '3'}}, {{'9', '4'}}, {{'9', '5'}}, {{'9', '6'}}, {{'9', '7'}}, {{'9', '8'}}, {{'9', '9'}},
12605 }
12606 };
12607
12608 // special case for "0"
12609 if (x == 0)
12610 {
12611 o->write_character('0');
12612 return;
12613 }
12614
12615 // use a pointer to fill the buffer
12616 auto buffer_ptr = number_buffer.begin();
12617
12618 const bool is_negative = std::is_same<NumberType, number_integer_t>::value and not(x >= 0); // see issue #755
12619 number_unsigned_t abs_value;
12620
12621 unsigned int n_chars;
12622
12623 if (is_negative)
12624 {
12625 *buffer_ptr = '-';
12626 abs_value = static_cast<number_unsigned_t>(std::abs(static_cast<std::intmax_t>(x)));
12627
12628 // account one more byte for the minus sign
12629 n_chars = 1 + count_digits(abs_value);
12630 }
12631 else
12632 {
12633 abs_value = static_cast<number_unsigned_t>(x);
12634 n_chars = count_digits(abs_value);
12635 }
12636
12637 // spare 1 byte for '\0'
12638 assert(n_chars < number_buffer.size() - 1);
12639
12640 // jump to the end to generate the string from backward
12641 // so we later avoid reversing the result
12642 buffer_ptr += n_chars;
12643
12644 // Fast int2ascii implementation inspired by "Fastware" talk by Andrei Alexandrescu
12645 // See: https://www.youtube.com/watch?v=o4-CwDo2zpg
12646 while (abs_value >= 100)
12647 {

Callers

nothing calls this directly

Calls 6

count_digitsFunction · 0.50
write_characterMethod · 0.45
beginMethod · 0.45
sizeMethod · 0.45
write_charactersMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected