14#include "arccore/common/JSONReader.h"
16#include "arccore/base/FatalErrorException.h"
17#include "arccore/base/CheckedConvert.h"
18#include "arccore/base/internal/ConvertInternal.h"
20#define RAPIDJSON_HAS_STDSTRING 1
22#include "arccore/common/internal/json/rapidjson/stringbuffer.h"
49 rapidjson::Value* toValue()
const
51 return (rapidjson::Value*)(
this);
67 static JSONValue build(rapidjson::Value* v)
94 auto& x = m_p->toMember()->
name;
103JSONValue JSONKeyValue::
108 auto& x = m_p->toMember()->
value;
109 return JSONWrapperUtils::build(&x);
120 auto x = m_p->toValue();
134 auto x = m_p->toValue();
157 auto x = m_p->toValue();
159 return x->GetInt64();
171 auto x = m_p->toValue();
184 return CheckedConvert::toInt32(v);
195 auto x = m_p->toValue();
197 return x->GetDouble();
198 if (x->GetType() == rapidjson::kStringType) {
202 if (!Convert::Impl::StringViewToIntegral::getValue(r, s))
216 auto x = m_p->toValue();
218 return x->GetUint64();
230 auto d = m_p->toValue();
232 if (x == d->MemberEnd())
234 return JSONWrapperUtils::build(x);
243 return keyValueChild(name).
value();
252 JSONKeyValue k = keyValueChild(name);
266 auto d = m_p->toValue();
270 for (
auto& x : d->GetObject()) {
271 auto y = JSONWrapperUtils::build(&x);
272 values.add(y.value());
284 return JSONValueList();
285 auto d = m_p->toValue();
286 JSONValueList values;
289 for (rapidjson::SizeType i = 0; i < d->Size(); ++i) {
290 rapidjson::Value& x = (*d)[i];
291 auto y = JSONWrapperUtils::build(&x);
305 auto d = m_p->toValue();
317 auto d = m_p->toValue();
318 return d->IsObject();
325keyValueChildren()
const
328 return JSONKeyValueList();
329 auto d = m_p->toValue();
330 JSONKeyValueList values;
331 for (
auto& x : d->GetObject()) {
332 auto y = JSONWrapperUtils::build(&x);
343 return m_p->toValue()->IsNull();
351 return m_p->toValue()->IsBool();
359 return m_p->toValue()->IsString();
367 return m_p->toValue()->IsNumber();
375 return m_p->toValue()->IsInt64();
383 return m_p->toValue()->IsUint64();
403 rapidjson::Document m_document;
432 return "The document is empty";
434 return "The document root must not follow by other values";
436 return "Invalid value";
438 return "Missing a name for object member";
440 return "Missing a colon after a name of object member";
442 return "Missing a comma or '}' after an object member";
444 return "Missing a comma or ']' after an array element";
446 return "Incorrect hex digit after \\u escape in string";
448 return "The surrogate pair in string is invalid";
450 return "Invalid escape character in string";
452 return "Missing a closing quotation mark in string";
454 return "Invalid encoding in string";
456 return "Number too big to be stored in double";
458 return "Miss fraction part in number";
460 return "Miss exponent in number";
462 return "Parsing was terminated";
464 return "Unspecific syntax error";
483 ARCCORE_FATAL(
"Parsing error file='{0}' ret={1} position={2} message='{3}'",
495 parse(bytes,
"(Unknown)");
522 rapidjson::Value& d = m_p->m_document;
523 return JSONWrapperUtils::build(&d);
#define ARCCORE_FATAL(...)
Macro envoyant une exception FatalErrorException.
void parse(Span< const Byte > bytes)
Lit le fichier au format UTF-8.
JSONValue root() const
Elément racine.
Liste de (clé,valeur) d'un document JSON.
Représente une paire (clé, valeur) de JSON.
Liste de valeurs d'un document JSON.
Représente une valeur JSON.
String value() const
Valeur sous forme de String. La chaîne retournée est nulle si 'null()' est vrai.
bool isUint64() const
Vrai si la valeur est un entier dans la plage 'UInt64'.
UInt64 valueAsUInt64() const
Valeur sous forme de UInt64. Retourn 0 si 'null()' est vrai.
Int32 valueAsInt32() const
Valeur sous forme de Int32. Retourn 0 si 'null()' est vrai.
Real valueAsReal() const
Valeur sous forme de Real. Retourn 0.0 si 'null()' est vrai.
bool valueAsBool() const
Valeur sous forme de booléen. Retourn false si 'null()' est vrai.
Int64 valueAsInt64() const
Valeur sous forme de Int64. Retourn 0 si 'null()' est vrai.
bool isInt64() const
Vrai si la valeur est un entier dans la plage 'Int64'.
StringView valueAsStringView() const
Valeur sous forme de StringView. La chaîne est vide si 'null()' est vrai.
JSONValue expectedChild(StringView name) const
Valeur fille de nom name. Lance une exception si non trouvé.
bool isBool() const
Vrai si la valeur est un booléen.
bool isString() const
Vrai si la valeur est une chaîne de caractères.
bool isNull() const
Vrai si la valeur est de type 'null'.
JSONValue child(StringView name) const
Valeur fille de nom name. Retourne une valeur nulle si non trouvé.
bool isNumber() const
Vrai si la valeur est un nombre.
Vue d'un tableau d'éléments de type T.
Vue sur une chaîne de caractères UTF-8.
constexpr Span< const Byte > bytes() const ARCCORE_NOEXCEPT
Retourne la conversion de l'instance dans l'encodage UTF-8.
Chaîne de caractères unicode.
constexpr __host__ __device__ pointer data() const noexcept
Pointeur sur le début de la vue.
bool HasParseError() const
Whether a parse error has occurred in the last parsing.
GenericDocument & Parse(const typename SourceEncoding::Ch *str)
Parse JSON text from a read-only string (with Encoding conversion).
ParseErrorCode GetParseError() const
Get the ParseErrorCode of last parsing.
GenericValue< Encoding, Allocator > name
name of member (must be a string)
GenericValue< Encoding, Allocator > value
value of member.
GenericMemberIterator< false, UTF8<>, RAPIDJSON_DEFAULT_ALLOCATOR >::Iterator MemberIterator
GenericMember< UTF8<>, RAPIDJSON_DEFAULT_ALLOCATOR > Member
GenericMemberIterator< true, UTF8<>, RAPIDJSON_DEFAULT_ALLOCATOR >::Iterator ConstMemberIterator
GenericDocument< UTF8<> > Document
GenericDocument with UTF8 encoding.
ParseErrorCode
Error code of parsing.
@ kParseErrorDocumentEmpty
The document is empty.
@ kParseErrorNumberMissFraction
Miss fraction part in number.
@ kParseErrorStringInvalidEncoding
Invalid encoding in string.
@ kParseErrorValueInvalid
Invalid value.
@ kParseErrorDocumentRootNotSingular
The document root must not follow by other values.
@ kParseErrorUnspecificSyntaxError
Unspecific syntax error.
@ kParseErrorObjectMissCommaOrCurlyBracket
Missing a comma or '}' after an object member.
@ kParseErrorObjectMissColon
Missing a colon after a name of object member.
@ kParseErrorStringMissQuotationMark
Missing a closing quotation mark in string.
@ kParseErrorTermination
Parsing was terminated.
@ kParseErrorNumberMissExponent
Miss exponent in number.
@ kParseErrorStringEscapeInvalid
Invalid escape character in string.
@ kParseErrorArrayMissCommaOrSquareBracket
Missing a comma or ']' after an array element.
@ kParseErrorNone
No error.
@ kParseErrorStringUnicodeSurrogateInvalid
The surrogate pair in string is invalid.
@ kParseErrorObjectMissName
Missing a name for object member.
@ kParseErrorNumberTooBig
Number too big to be stored in double.
@ kParseErrorStringUnicodeEscapeInvalidHex
Incorrect hex digit after \u escape in string.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::uint64_t UInt64
Type entier non signé sur 64 bits.
std::int64_t Int64
Type entier signé sur 64 bits.
double Real
Type représentant un réel.
Impl::SpanTypeFromSize< conststd::byte, SizeType >::SpanType asBytes(const SpanImpl< DataType, SizeType, Extent > &s)
Convertit la vue en un tableau d'octets non modifiables.
unsigned char Byte
Type d'un octet.
std::int32_t Int32
Type entier signé sur 32 bits.
Result of parsing (wraps ParseErrorCode).
ParseErrorCode Code() const
Get the error code.
size_t Offset() const
Get the error offset, if IsError(), 0 otherwise.