MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / get_number

Method get_number

Source/Utils/json.hpp:9922–9948  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9920 */
9921 template<typename NumberType, bool InputIsLittleEndian = false>
9922 bool get_number(const input_format_t format, NumberType& result)
9923 {
9924 // step 1: read input into array with system's byte order
9925 std::array<std::uint8_t, sizeof(NumberType)> vec;
9926 for (std::size_t i = 0; i < sizeof(NumberType); ++i)
9927 {
9928 get();
9929 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "number")))
9930 {
9931 return false;
9932 }
9933
9934 // reverse byte order prior to conversion if necessary
9935 if (is_little_endian != InputIsLittleEndian)
9936 {
9937 vec[sizeof(NumberType) - i - 1] = static_cast<std::uint8_t>(current);
9938 }
9939 else
9940 {
9941 vec[i] = static_cast<std::uint8_t>(current); // LCOV_EXCL_LINE
9942 }
9943 }
9944
9945 // step 2: convert array into number of type T and return
9946 std::memcpy(&result, vec.data(), sizeof(NumberType));
9947 return true;
9948 }
9949
9950 /*!
9951 @brief create a string by reading characters from the input

Callers

nothing calls this directly

Calls 1

getFunction · 0.85

Tested by

no test coverage detected