Fast Methods for Cosmological Simulations
FastSim serves as a tool for quick N-body simulations in modified gravity.
nlohmann::detail::serializer< BasicJsonType > Class Template Reference

#include <json.hpp>

Public Member Functions

 serializer (output_adapter_t< char > s, const char ichar, error_handler_t error_handler_=error_handler_t::strict)
 
 serializer (const serializer &)=delete
 
serializeroperator= (const serializer &)=delete
 
 serializer (serializer &&)=delete
 
serializeroperator= (serializer &&)=delete
 
 ~serializer ()=default
 
void dump (const BasicJsonType &val, const bool pretty_print, const bool ensure_ascii, const unsigned int indent_step, const unsigned int current_indent=0)
 internal implementation of the serialization function More...
 

Private Types

using string_t = typename BasicJsonType::string_t
 
using number_float_t = typename BasicJsonType::number_float_t
 
using number_integer_t = typename BasicJsonType::number_integer_t
 
using number_unsigned_t = typename BasicJsonType::number_unsigned_t
 

Private Member Functions

void dump_escaped (const string_t &s, const bool ensure_ascii)
 dump escaped string More...
 
template<typename NumberType , detail::enable_if_t< std::is_same< NumberType, number_unsigned_t >::value orstd::is_same< NumberType, number_integer_t >::value, int > = 0>
void dump_integer (NumberType x)
 dump an integer More...
 
void dump_float (number_float_t x)
 dump a floating-point number More...
 
void dump_float (number_float_t x, std::true_type)
 
void dump_float (number_float_t x, std::false_type)
 

Static Private Member Functions

static uint8_t decode (uint8_t &state, uint32_t &codep, const uint8_t byte) noexcept
 check whether a string is UTF-8 encoded More...
 

Private Attributes

output_adapter_t< char > o = nullptr
 the output of the serializer More...
 
std::array< char, 64 > number_buffer {{}}
 a (hopefully) large enough character buffer More...
 
const std::lconv * loc = nullptr
 the locale More...
 
const char thousands_sep = '\0'
 the locale's thousand separator character More...
 
const char decimal_point = '\0'
 the locale's decimal point character More...
 
std::array< char, 512 > string_buffer {{}}
 string buffer More...
 
const char indent_char
 the indentation character More...
 
string_t indent_string
 the indentation string More...
 
const error_handler_t error_handler
 error_handler how to react on decoding errors More...
 

Static Private Attributes

static constexpr uint8_t UTF8_ACCEPT = 0
 
static constexpr uint8_t UTF8_REJECT = 1
 

Detailed Description

template<typename BasicJsonType>
class nlohmann::detail::serializer< BasicJsonType >

Definition at line 10803 of file json.hpp.

Member Typedef Documentation

template<typename BasicJsonType >
using nlohmann::detail::serializer< BasicJsonType >::number_float_t = typename BasicJsonType::number_float_t
private

Definition at line 10806 of file json.hpp.

template<typename BasicJsonType >
using nlohmann::detail::serializer< BasicJsonType >::number_integer_t = typename BasicJsonType::number_integer_t
private

Definition at line 10807 of file json.hpp.

template<typename BasicJsonType >
using nlohmann::detail::serializer< BasicJsonType >::number_unsigned_t = typename BasicJsonType::number_unsigned_t
private

Definition at line 10808 of file json.hpp.

template<typename BasicJsonType >
using nlohmann::detail::serializer< BasicJsonType >::string_t = typename BasicJsonType::string_t
private

Definition at line 10805 of file json.hpp.

Constructor & Destructor Documentation

template<typename BasicJsonType >
nlohmann::detail::serializer< BasicJsonType >::serializer ( output_adapter_t< char >  s,
const char  ichar,
error_handler_t  error_handler_ = error_handler_t::strict 
)
inline
Parameters
[in]soutput stream to serialize to
[in]icharindentation character to use
[in]error_handler_how to react on decoding errors

Definition at line 10818 of file json.hpp.

10820  : o(std::move(s))
10821  , loc(std::localeconv())
10822  , thousands_sep(loc->thousands_sep == nullptr ? '\0' : * (loc->thousands_sep))
10823  , decimal_point(loc->decimal_point == nullptr ? '\0' : * (loc->decimal_point))
10824  , indent_char(ichar)
10825  , indent_string(512, indent_char)
10826  , error_handler(error_handler_)
10827  {}
const char indent_char
the indentation character
Definition: json.hpp:11495
const char decimal_point
the locale&#39;s decimal point character
Definition: json.hpp:11489
output_adapter_t< char > o
the output of the serializer
Definition: json.hpp:11479
const error_handler_t error_handler
error_handler how to react on decoding errors
Definition: json.hpp:11500
const std::lconv * loc
the locale
Definition: json.hpp:11485
const char thousands_sep
the locale&#39;s thousand separator character
Definition: json.hpp:11487
string_t indent_string
the indentation string
Definition: json.hpp:11497
template<typename BasicJsonType >
nlohmann::detail::serializer< BasicJsonType >::serializer ( const serializer< BasicJsonType > &  )
delete
template<typename BasicJsonType >
nlohmann::detail::serializer< BasicJsonType >::serializer ( serializer< BasicJsonType > &&  )
delete
template<typename BasicJsonType >
nlohmann::detail::serializer< BasicJsonType >::~serializer ( )
default

Member Function Documentation

template<typename BasicJsonType >
static uint8_t nlohmann::detail::serializer< BasicJsonType >::decode ( uint8_t &  state,
uint32_t &  codep,
const uint8_t  byte 
)
inlinestaticprivatenoexcept

check whether a string is UTF-8 encoded

The function checks each byte of a string whether it is UTF-8 encoded. The result of the check is stored in the state parameter. The function must be called initially with state 0 (accept). State 1 means the string must be rejected, because the current byte is not allowed. If the string is completely processed, but the state is non-zero, the string ended prematurely; that is, the last byte indicated more bytes should have followed.

Parameters
[in,out]statethe state of the decoding
[in,out]codepcodepoint (valid only if resulting state is UTF8_ACCEPT)
[in]bytenext byte to decode
Returns
new state
Note
The function has been edited: a std::array is used.
See also
http://bjoern.hoehrmann.de/utf-8/decoder/dfa/

Definition at line 11445 of file json.hpp.

11446  {
11447  static const std::array<uint8_t, 400> utf8d =
11448  {
11449  {
11450  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 00..1F
11451  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 20..3F
11452  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 40..5F
11453  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 60..7F
11454  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, // 80..9F
11455  7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, // A0..BF
11456  8, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // C0..DF
11457  0xA, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x4, 0x3, 0x3, // E0..EF
11458  0xB, 0x6, 0x6, 0x6, 0x5, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, // F0..FF
11459  0x0, 0x1, 0x2, 0x3, 0x5, 0x8, 0x7, 0x1, 0x1, 0x1, 0x4, 0x6, 0x1, 0x1, 0x1, 0x1, // s0..s0
11460  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, // s1..s2
11461  1, 2, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, // s3..s4
11462  1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, // s5..s6
11463  1, 3, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // s7..s8
11464  }
11465  };
11466 
11467  const uint8_t type = utf8d[byte];
11468 
11469  codep = (state != UTF8_ACCEPT)
11470  ? (byte & 0x3fu) | (codep << 6)
11471  : static_cast<uint32_t>(0xff >> type) & (byte);
11472 
11473  state = utf8d[256u + state * 16u + type];
11474  return state;
11475  }
static constexpr uint8_t UTF8_ACCEPT
Definition: json.hpp:10809
template<typename BasicJsonType >
void nlohmann::detail::serializer< BasicJsonType >::dump ( const BasicJsonType &  val,
const bool  pretty_print,
const bool  ensure_ascii,
const unsigned int  indent_step,
const unsigned int  current_indent = 0 
)
inline

internal implementation of the serialization function

This function is called by the public member function dump and organizes the serialization internally. The indentation level is propagated as additional parameter. In case of arrays and objects, the function is called recursively.

  • strings and object keys are escaped using escape_string()
  • integer numbers are converted implicitly via operator<<
  • floating-point numbers are converted to a string using "%g" format
Parameters
[in]valvalue to serialize
[in]pretty_printwhether the output shall be pretty-printed
[in]indent_stepthe indent level
[in]current_indentthe current indent level (only used internally)

Definition at line 10853 of file json.hpp.

References nlohmann::detail::array, nlohmann::detail::boolean, nlohmann::detail::discarded, JSON_UNLIKELY, nlohmann::detail::null, nlohmann::detail::number_float, nlohmann::detail::number_integer, nlohmann::detail::number_unsigned, nlohmann::detail::object, and nlohmann::detail::string.

Referenced by nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer >::dump().

10857  {
10858  switch (val.m_type)
10859  {
10860  case value_t::object:
10861  {
10862  if (val.m_value.object->empty())
10863  {
10864  o->write_characters("{}", 2);
10865  return;
10866  }
10867 
10868  if (pretty_print)
10869  {
10870  o->write_characters("{\n", 2);
10871 
10872  // variable to hold indentation for recursive calls
10873  const auto new_indent = current_indent + indent_step;
10874  if (JSON_UNLIKELY(indent_string.size() < new_indent))
10875  {
10876  indent_string.resize(indent_string.size() * 2, ' ');
10877  }
10878 
10879  // first n-1 elements
10880  auto i = val.m_value.object->cbegin();
10881  for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
10882  {
10883  o->write_characters(indent_string.c_str(), new_indent);
10884  o->write_character('\"');
10885  dump_escaped(i->first, ensure_ascii);
10886  o->write_characters("\": ", 3);
10887  dump(i->second, true, ensure_ascii, indent_step, new_indent);
10888  o->write_characters(",\n", 2);
10889  }
10890 
10891  // last element
10892  assert(i != val.m_value.object->cend());
10893  assert(std::next(i) == val.m_value.object->cend());
10894  o->write_characters(indent_string.c_str(), new_indent);
10895  o->write_character('\"');
10896  dump_escaped(i->first, ensure_ascii);
10897  o->write_characters("\": ", 3);
10898  dump(i->second, true, ensure_ascii, indent_step, new_indent);
10899 
10900  o->write_character('\n');
10901  o->write_characters(indent_string.c_str(), current_indent);
10902  o->write_character('}');
10903  }
10904  else
10905  {
10906  o->write_character('{');
10907 
10908  // first n-1 elements
10909  auto i = val.m_value.object->cbegin();
10910  for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
10911  {
10912  o->write_character('\"');
10913  dump_escaped(i->first, ensure_ascii);
10914  o->write_characters("\":", 2);
10915  dump(i->second, false, ensure_ascii, indent_step, current_indent);
10916  o->write_character(',');
10917  }
10918 
10919  // last element
10920  assert(i != val.m_value.object->cend());
10921  assert(std::next(i) == val.m_value.object->cend());
10922  o->write_character('\"');
10923  dump_escaped(i->first, ensure_ascii);
10924  o->write_characters("\":", 2);
10925  dump(i->second, false, ensure_ascii, indent_step, current_indent);
10926 
10927  o->write_character('}');
10928  }
10929 
10930  return;
10931  }
10932 
10933  case value_t::array:
10934  {
10935  if (val.m_value.array->empty())
10936  {
10937  o->write_characters("[]", 2);
10938  return;
10939  }
10940 
10941  if (pretty_print)
10942  {
10943  o->write_characters("[\n", 2);
10944 
10945  // variable to hold indentation for recursive calls
10946  const auto new_indent = current_indent + indent_step;
10947  if (JSON_UNLIKELY(indent_string.size() < new_indent))
10948  {
10949  indent_string.resize(indent_string.size() * 2, ' ');
10950  }
10951 
10952  // first n-1 elements
10953  for (auto i = val.m_value.array->cbegin();
10954  i != val.m_value.array->cend() - 1; ++i)
10955  {
10956  o->write_characters(indent_string.c_str(), new_indent);
10957  dump(*i, true, ensure_ascii, indent_step, new_indent);
10958  o->write_characters(",\n", 2);
10959  }
10960 
10961  // last element
10962  assert(not val.m_value.array->empty());
10963  o->write_characters(indent_string.c_str(), new_indent);
10964  dump(val.m_value.array->back(), true, ensure_ascii, indent_step, new_indent);
10965 
10966  o->write_character('\n');
10967  o->write_characters(indent_string.c_str(), current_indent);
10968  o->write_character(']');
10969  }
10970  else
10971  {
10972  o->write_character('[');
10973 
10974  // first n-1 elements
10975  for (auto i = val.m_value.array->cbegin();
10976  i != val.m_value.array->cend() - 1; ++i)
10977  {
10978  dump(*i, false, ensure_ascii, indent_step, current_indent);
10979  o->write_character(',');
10980  }
10981 
10982  // last element
10983  assert(not val.m_value.array->empty());
10984  dump(val.m_value.array->back(), false, ensure_ascii, indent_step, current_indent);
10985 
10986  o->write_character(']');
10987  }
10988 
10989  return;
10990  }
10991 
10992  case value_t::string:
10993  {
10994  o->write_character('\"');
10995  dump_escaped(*val.m_value.string, ensure_ascii);
10996  o->write_character('\"');
10997  return;
10998  }
10999 
11000  case value_t::boolean:
11001  {
11002  if (val.m_value.boolean)
11003  {
11004  o->write_characters("true", 4);
11005  }
11006  else
11007  {
11008  o->write_characters("false", 5);
11009  }
11010  return;
11011  }
11012 
11014  {
11015  dump_integer(val.m_value.number_integer);
11016  return;
11017  }
11018 
11020  {
11021  dump_integer(val.m_value.number_unsigned);
11022  return;
11023  }
11024 
11025  case value_t::number_float:
11026  {
11027  dump_float(val.m_value.number_float);
11028  return;
11029  }
11030 
11031  case value_t::discarded:
11032  {
11033  o->write_characters("<discarded>", 11);
11034  return;
11035  }
11036 
11037  case value_t::null:
11038  {
11039  o->write_characters("null", 4);
11040  return;
11041  }
11042  }
11043  }
array (ordered collection of values)
number value (signed integer)
void dump_integer(NumberType x)
dump an integer
Definition: json.hpp:11305
void dump(const BasicJsonType &val, const bool pretty_print, const bool ensure_ascii, const unsigned int indent_step, const unsigned int current_indent=0)
internal implementation of the serialization function
Definition: json.hpp:10853
#define JSON_UNLIKELY(x)
Definition: json.hpp:194
output_adapter_t< char > o
the output of the serializer
Definition: json.hpp:11479
object (unordered set of name/value pairs)
void dump_float(number_float_t x)
dump a floating-point number
Definition: json.hpp:11346
void dump_escaped(const string_t &s, const bool ensure_ascii)
dump escaped string
Definition: json.hpp:11060
number value (unsigned integer)
string_t indent_string
the indentation string
Definition: json.hpp:11497
number value (floating-point)
discarded by the the parser callback function
template<typename BasicJsonType >
void nlohmann::detail::serializer< BasicJsonType >::dump_escaped ( const string_t s,
const bool  ensure_ascii 
)
inlineprivate

dump escaped string

Escape a string by replacing certain special characters by a sequence of an escape character (backslash) and another character and other control characters by a sequence of "\u" followed by a four-digit hex representation. The escaped string is written to output stream o.

Parameters
[in]sthe string to escape
[in]ensure_asciiwhether to escape non-ASCII characters with sequences

Linear in the length of string s.

Definition at line 11060 of file json.hpp.

References nlohmann::detail::type_error::create(), nlohmann::detail::ignore, JSON_LIKELY, JSON_THROW, nlohmann::detail::replace, nlohmann::detail::strict, nlohmann::detail::string, nlohmann::detail::binary_writer< BasicJsonType, CharType >::to_char_type(), and Catch::Generators::value().

11061  {
11062  uint32_t codepoint;
11063  uint8_t state = UTF8_ACCEPT;
11064  std::size_t bytes = 0; // number of bytes written to string_buffer
11065 
11066  // number of bytes written at the point of the last valid byte
11067  std::size_t bytes_after_last_accept = 0;
11068  std::size_t undumped_chars = 0;
11069 
11070  for (std::size_t i = 0; i < s.size(); ++i)
11071  {
11072  const auto byte = static_cast<uint8_t>(s[i]);
11073 
11074  switch (decode(state, codepoint, byte))
11075  {
11076  case UTF8_ACCEPT: // decode found a new code point
11077  {
11078  switch (codepoint)
11079  {
11080  case 0x08: // backspace
11081  {
11082  string_buffer[bytes++] = '\\';
11083  string_buffer[bytes++] = 'b';
11084  break;
11085  }
11086 
11087  case 0x09: // horizontal tab
11088  {
11089  string_buffer[bytes++] = '\\';
11090  string_buffer[bytes++] = 't';
11091  break;
11092  }
11093 
11094  case 0x0A: // newline
11095  {
11096  string_buffer[bytes++] = '\\';
11097  string_buffer[bytes++] = 'n';
11098  break;
11099  }
11100 
11101  case 0x0C: // formfeed
11102  {
11103  string_buffer[bytes++] = '\\';
11104  string_buffer[bytes++] = 'f';
11105  break;
11106  }
11107 
11108  case 0x0D: // carriage return
11109  {
11110  string_buffer[bytes++] = '\\';
11111  string_buffer[bytes++] = 'r';
11112  break;
11113  }
11114 
11115  case 0x22: // quotation mark
11116  {
11117  string_buffer[bytes++] = '\\';
11118  string_buffer[bytes++] = '\"';
11119  break;
11120  }
11121 
11122  case 0x5C: // reverse solidus
11123  {
11124  string_buffer[bytes++] = '\\';
11125  string_buffer[bytes++] = '\\';
11126  break;
11127  }
11128 
11129  default:
11130  {
11131  // escape control characters (0x00..0x1F) or, if
11132  // ensure_ascii parameter is used, non-ASCII characters
11133  if ((codepoint <= 0x1F) or (ensure_ascii and (codepoint >= 0x7F)))
11134  {
11135  if (codepoint <= 0xFFFF)
11136  {
11137  std::snprintf(string_buffer.data() + bytes, 7, "\\u%04x",
11138  static_cast<uint16_t>(codepoint));
11139  bytes += 6;
11140  }
11141  else
11142  {
11143  std::snprintf(string_buffer.data() + bytes, 13, "\\u%04x\\u%04x",
11144  static_cast<uint16_t>(0xD7C0 + (codepoint >> 10)),
11145  static_cast<uint16_t>(0xDC00 + (codepoint & 0x3FF)));
11146  bytes += 12;
11147  }
11148  }
11149  else
11150  {
11151  // copy byte to buffer (all previous bytes
11152  // been copied have in default case above)
11153  string_buffer[bytes++] = s[i];
11154  }
11155  break;
11156  }
11157  }
11158 
11159  // write buffer and reset index; there must be 13 bytes
11160  // left, as this is the maximal number of bytes to be
11161  // written ("\uxxxx\uxxxx\0") for one code point
11162  if (string_buffer.size() - bytes < 13)
11163  {
11164  o->write_characters(string_buffer.data(), bytes);
11165  bytes = 0;
11166  }
11167 
11168  // remember the byte position of this accept
11169  bytes_after_last_accept = bytes;
11170  undumped_chars = 0;
11171  break;
11172  }
11173 
11174  case UTF8_REJECT: // decode found invalid UTF-8 byte
11175  {
11176  switch (error_handler)
11177  {
11179  {
11180  std::string sn(3, '\0');
11181  snprintf(&sn[0], sn.size(), "%.2X", byte);
11182  JSON_THROW(type_error::create(316, "invalid UTF-8 byte at index " + std::to_string(i) + ": 0x" + sn));
11183  }
11184 
11187  {
11188  // in case we saw this character the first time, we
11189  // would like to read it again, because the byte
11190  // may be OK for itself, but just not OK for the
11191  // previous sequence
11192  if (undumped_chars > 0)
11193  {
11194  --i;
11195  }
11196 
11197  // reset length buffer to the last accepted index;
11198  // thus removing/ignoring the invalid characters
11199  bytes = bytes_after_last_accept;
11200 
11202  {
11203  // add a replacement character
11204  if (ensure_ascii)
11205  {
11206  string_buffer[bytes++] = '\\';
11207  string_buffer[bytes++] = 'u';
11208  string_buffer[bytes++] = 'f';
11209  string_buffer[bytes++] = 'f';
11210  string_buffer[bytes++] = 'f';
11211  string_buffer[bytes++] = 'd';
11212  }
11213  else
11214  {
11218  }
11219  bytes_after_last_accept = bytes;
11220  }
11221 
11222  undumped_chars = 0;
11223 
11224  // continue processing the string
11225  state = UTF8_ACCEPT;
11226  break;
11227  }
11228  }
11229  break;
11230  }
11231 
11232  default: // decode found yet incomplete multi-byte code point
11233  {
11234  if (not ensure_ascii)
11235  {
11236  // code point will not be escaped - copy byte to buffer
11237  string_buffer[bytes++] = s[i];
11238  }
11239  ++undumped_chars;
11240  break;
11241  }
11242  }
11243  }
11244 
11245  // we finished processing the string
11246  if (JSON_LIKELY(state == UTF8_ACCEPT))
11247  {
11248  // write buffer
11249  if (bytes > 0)
11250  {
11251  o->write_characters(string_buffer.data(), bytes);
11252  }
11253  }
11254  else
11255  {
11256  // we finish reading, but do not accept: string was incomplete
11257  switch (error_handler)
11258  {
11260  {
11261  std::string sn(3, '\0');
11262  snprintf(&sn[0], sn.size(), "%.2X", static_cast<uint8_t>(s.back()));
11263  JSON_THROW(type_error::create(316, "incomplete UTF-8 string; last byte: 0x" + sn));
11264  }
11265 
11267  {
11268  // write all accepted bytes
11269  o->write_characters(string_buffer.data(), bytes_after_last_accept);
11270  break;
11271  }
11272 
11274  {
11275  // write all accepted bytes
11276  o->write_characters(string_buffer.data(), bytes_after_last_accept);
11277  // add a replacement character
11278  if (ensure_ascii)
11279  {
11280  o->write_characters("\\ufffd", 6);
11281  }
11282  else
11283  {
11284  o->write_characters("\xEF\xBF\xBD", 3);
11285  }
11286  break;
11287  }
11288  }
11289  }
11290  }
std::array< char, 512 > string_buffer
string buffer
Definition: json.hpp:11492
ignore invalid UTF-8 sequences
throw a type_error exception in case of invalid UTF-8
output_adapter_t< char > o
the output of the serializer
Definition: json.hpp:11479
#define JSON_THROW(exception)
Definition: json.hpp:162
const error_handler_t error_handler
error_handler how to react on decoding errors
Definition: json.hpp:11500
#define JSON_LIKELY(x)
Definition: json.hpp:193
static constexpr uint8_t UTF8_REJECT
Definition: json.hpp:10810
static uint8_t decode(uint8_t &state, uint32_t &codep, const uint8_t byte) noexcept
check whether a string is UTF-8 encoded
Definition: json.hpp:11445
replace invalid UTF-8 sequences with U+FFFD
static constexpr CharType to_char_type(std::uint8_t x) noexcept
Definition: json.hpp:9617
static constexpr uint8_t UTF8_ACCEPT
Definition: json.hpp:10809
static type_error create(int id_, const std::string &what_arg)
Definition: json.hpp:1024
template<typename BasicJsonType >
void nlohmann::detail::serializer< BasicJsonType >::dump_float ( number_float_t  x)
inlineprivate

dump a floating-point number

Dump a given floating-point number to output stream o. Works internally with number_buffer.

Parameters
[in]xfloating-point number to dump

Definition at line 11346 of file json.hpp.

11347  {
11348  // NaN / inf
11349  if (not std::isfinite(x))
11350  {
11351  o->write_characters("null", 4);
11352  return;
11353  }
11354 
11355  // If number_float_t is an IEEE-754 single or double precision number,
11356  // use the Grisu2 algorithm to produce short numbers which are
11357  // guaranteed to round-trip, using strtof and strtod, resp.
11358  //
11359  // NB: The test below works if <long double> == <double>.
11360  static constexpr bool is_ieee_single_or_double
11361  = (std::numeric_limits<number_float_t>::is_iec559 and std::numeric_limits<number_float_t>::digits == 24 and std::numeric_limits<number_float_t>::max_exponent == 128) or
11362  (std::numeric_limits<number_float_t>::is_iec559 and std::numeric_limits<number_float_t>::digits == 53 and std::numeric_limits<number_float_t>::max_exponent == 1024);
11363 
11364  dump_float(x, std::integral_constant<bool, is_ieee_single_or_double>());
11365  }
output_adapter_t< char > o
the output of the serializer
Definition: json.hpp:11479
static CCL_BEGIN_DECLS double x[111][8]
void dump_float(number_float_t x)
dump a floating-point number
Definition: json.hpp:11346
template<typename BasicJsonType >
void nlohmann::detail::serializer< BasicJsonType >::dump_float ( number_float_t  x,
std::true_type   
)
inlineprivate

Definition at line 11367 of file json.hpp.

References Catch::begin, Catch::end, nlohmann::detail::to_chars(), and x.

11368  {
11369  char* begin = number_buffer.data();
11370  char* end = ::nlohmann::detail::to_chars(begin, begin + number_buffer.size(), x);
11371 
11372  o->write_characters(begin, static_cast<size_t>(end - begin));
11373  }
not_this_one end(...)
char * to_chars(char *first, const char *last, FloatType value)
generates a decimal representation of the floating-point number value in [first, last).
Definition: json.hpp:10727
std::array< char, 64 > number_buffer
a (hopefully) large enough character buffer
Definition: json.hpp:11482
output_adapter_t< char > o
the output of the serializer
Definition: json.hpp:11479
not_this_one begin(...)
static CCL_BEGIN_DECLS double x[111][8]
template<typename BasicJsonType >
void nlohmann::detail::serializer< BasicJsonType >::dump_float ( number_float_t  x,
std::false_type   
)
inlineprivate

Definition at line 11375 of file json.hpp.

References cl_cmbl_bm::c, Catch::end, and x.

11376  {
11377  // get number of digits for a float -> text -> float round-trip
11378  static constexpr auto d = std::numeric_limits<number_float_t>::max_digits10;
11379 
11380  // the actual conversion
11381  std::ptrdiff_t len = snprintf(number_buffer.data(), number_buffer.size(), "%.*g", d, x);
11382 
11383  // negative value indicates an error
11384  assert(len > 0);
11385  // check if buffer was large enough
11386  assert(static_cast<std::size_t>(len) < number_buffer.size());
11387 
11388  // erase thousands separator
11389  if (thousands_sep != '\0')
11390  {
11391  const auto end = std::remove(number_buffer.begin(),
11392  number_buffer.begin() + len, thousands_sep);
11393  std::fill(end, number_buffer.end(), '\0');
11394  assert((end - number_buffer.begin()) <= len);
11395  len = (end - number_buffer.begin());
11396  }
11397 
11398  // convert decimal point to '.'
11399  if (decimal_point != '\0' and decimal_point != '.')
11400  {
11401  const auto dec_pos = std::find(number_buffer.begin(), number_buffer.end(), decimal_point);
11402  if (dec_pos != number_buffer.end())
11403  {
11404  *dec_pos = '.';
11405  }
11406  }
11407 
11408  o->write_characters(number_buffer.data(), static_cast<std::size_t>(len));
11409 
11410  // determine if need to append ".0"
11411  const bool value_is_int_like =
11412  std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1,
11413  [](char c)
11414  {
11415  return (c == '.' or c == 'e');
11416  });
11417 
11418  if (value_is_int_like)
11419  {
11420  o->write_characters(".0", 2);
11421  }
11422  }
not_this_one end(...)
const char decimal_point
the locale&#39;s decimal point character
Definition: json.hpp:11489
std::array< char, 64 > number_buffer
a (hopefully) large enough character buffer
Definition: json.hpp:11482
output_adapter_t< char > o
the output of the serializer
Definition: json.hpp:11479
static CCL_BEGIN_DECLS double x[111][8]
const char thousands_sep
the locale&#39;s thousand separator character
Definition: json.hpp:11487
template<typename BasicJsonType >
template<typename NumberType , detail::enable_if_t< std::is_same< NumberType, number_unsigned_t >::value orstd::is_same< NumberType, number_integer_t >::value, int > = 0>
void nlohmann::detail::serializer< BasicJsonType >::dump_integer ( NumberType  x)
inlineprivate

dump an integer

Dump a given integer to output stream o. Works internally with number_buffer.

Parameters
[in]xinteger number (signed or unsigned) to dump
Template Parameters
NumberTypeeither number_integer_t or number_unsigned_t

Definition at line 11305 of file json.hpp.

11306  {
11307  // special case for "0"
11308  if (x == 0)
11309  {
11310  o->write_character('0');
11311  return;
11312  }
11313 
11314  const bool is_negative = std::is_same<NumberType, number_integer_t>::value and not (x >= 0); // see issue #755
11315  std::size_t i = 0;
11316 
11317  while (x != 0)
11318  {
11319  // spare 1 byte for '\0'
11320  assert(i < number_buffer.size() - 1);
11321 
11322  const auto digit = std::labs(static_cast<long>(x % 10));
11323  number_buffer[i++] = static_cast<char>('0' + digit);
11324  x /= 10;
11325  }
11326 
11327  if (is_negative)
11328  {
11329  // make sure there is capacity for the '-'
11330  assert(i < number_buffer.size() - 2);
11331  number_buffer[i++] = '-';
11332  }
11333 
11334  std::reverse(number_buffer.begin(), number_buffer.begin() + i);
11335  o->write_characters(number_buffer.data(), i);
11336  }
std::array< char, 64 > number_buffer
a (hopefully) large enough character buffer
Definition: json.hpp:11482
output_adapter_t< char > o
the output of the serializer
Definition: json.hpp:11479
static CCL_BEGIN_DECLS double x[111][8]
auto value(T const &val) -> Generator< T >
Definition: catch.hpp:3177
template<typename BasicJsonType >
serializer& nlohmann::detail::serializer< BasicJsonType >::operator= ( const serializer< BasicJsonType > &  )
delete
template<typename BasicJsonType >
serializer& nlohmann::detail::serializer< BasicJsonType >::operator= ( serializer< BasicJsonType > &&  )
delete

Member Data Documentation

template<typename BasicJsonType >
const char nlohmann::detail::serializer< BasicJsonType >::decimal_point = '\0'
private

the locale's decimal point character

Definition at line 11489 of file json.hpp.

template<typename BasicJsonType >
const error_handler_t nlohmann::detail::serializer< BasicJsonType >::error_handler
private

error_handler how to react on decoding errors

Definition at line 11500 of file json.hpp.

template<typename BasicJsonType >
const char nlohmann::detail::serializer< BasicJsonType >::indent_char
private

the indentation character

Definition at line 11495 of file json.hpp.

template<typename BasicJsonType >
string_t nlohmann::detail::serializer< BasicJsonType >::indent_string
private

the indentation string

Definition at line 11497 of file json.hpp.

template<typename BasicJsonType >
const std::lconv* nlohmann::detail::serializer< BasicJsonType >::loc = nullptr
private

the locale

Definition at line 11485 of file json.hpp.

template<typename BasicJsonType >
std::array<char, 64> nlohmann::detail::serializer< BasicJsonType >::number_buffer {{}}
private

a (hopefully) large enough character buffer

Definition at line 11482 of file json.hpp.

template<typename BasicJsonType >
output_adapter_t<char> nlohmann::detail::serializer< BasicJsonType >::o = nullptr
private

the output of the serializer

Definition at line 11479 of file json.hpp.

template<typename BasicJsonType >
std::array<char, 512> nlohmann::detail::serializer< BasicJsonType >::string_buffer {{}}
private

string buffer

Definition at line 11492 of file json.hpp.

template<typename BasicJsonType >
const char nlohmann::detail::serializer< BasicJsonType >::thousands_sep = '\0'
private

the locale's thousand separator character

Definition at line 11487 of file json.hpp.

template<typename BasicJsonType >
constexpr uint8_t nlohmann::detail::serializer< BasicJsonType >::UTF8_ACCEPT = 0
staticprivate

Definition at line 10809 of file json.hpp.

template<typename BasicJsonType >
constexpr uint8_t nlohmann::detail::serializer< BasicJsonType >::UTF8_REJECT = 1
staticprivate

Definition at line 10810 of file json.hpp.


The documentation for this class was generated from the following file: