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
21#include "arccore/common/internal/json/rapidjson/document.h"
22#include "arccore/common/internal/json/rapidjson/stringbuffer.h"
39 rapidjson::Value::Member* toMember()
const
41 return (rapidjson::Value::Member*)(
this);
49 rapidjson::Value* toValue()
const
51 return (rapidjson::Value*)(
this);
63 static JSONKeyValue build(rapidjson::Value::ConstMemberIterator v)
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();
196 std::cout <<
"TYPE=" << x->GetType() <<
"\n";
198 return x->GetDouble();
199 if (x->GetType() == rapidjson::kStringType) {
203 if (!Convert::Impl::StringViewToIntegral::getValue(r, s))
217 auto d = m_p->toValue();
218 rapidjson::Value::MemberIterator x = d->FindMember((
const char*)(name.
bytes().
data()));
219 if (x == d->MemberEnd())
221 return JSONWrapperUtils::build(x);
230 return keyValueChild(name).
value();
239 JSONKeyValue k = keyValueChild(name);
253 auto d = m_p->toValue();
257 for (
auto& x : d->GetObject()) {
258 auto y = JSONWrapperUtils::build(&x);
259 values.add(y.value());
271 return JSONValueList();
272 auto d = m_p->toValue();
273 JSONValueList values;
276 for (rapidjson::SizeType i = 0; i < d->Size(); ++i) {
277 rapidjson::Value& x = (*d)[i];
278 auto y = JSONWrapperUtils::build(&x);
292 auto d = m_p->toValue();
304 auto d = m_p->toValue();
305 return d->IsObject();
312keyValueChildren()
const
315 return JSONKeyValueList();
316 auto d = m_p->toValue();
317 JSONKeyValueList values;
318 for (
auto& x : d->GetObject()) {
319 auto y = JSONWrapperUtils::build(&x);
342 rapidjson::Document m_document;
363 using namespace rapidjson;
366 _getErrorCodeString(ParseErrorCode c)
369 case kParseErrorNone:
371 case kParseErrorDocumentEmpty:
372 return "The document is empty";
373 case kParseErrorDocumentRootNotSingular:
374 return "The document root must not follow by other values";
375 case kParseErrorValueInvalid:
376 return "Invalid value";
377 case kParseErrorObjectMissName:
378 return "Missing a name for object member";
379 case kParseErrorObjectMissColon:
380 return "Missing a colon after a name of object member";
381 case kParseErrorObjectMissCommaOrCurlyBracket:
382 return "Missing a comma or '}' after an object member";
383 case kParseErrorArrayMissCommaOrSquareBracket:
384 return "Missing a comma or ']' after an array element";
385 case kParseErrorStringUnicodeEscapeInvalidHex:
386 return "Incorrect hex digit after \\u escape in string";
387 case kParseErrorStringUnicodeSurrogateInvalid:
388 return "The surrogate pair in string is invalid";
389 case kParseErrorStringEscapeInvalid:
390 return "Invalid escape character in string";
391 case kParseErrorStringMissQuotationMark:
392 return "Missing a closing quotation mark in string";
393 case kParseErrorStringInvalidEncoding:
394 return "Invalid encoding in string";
395 case kParseErrorNumberTooBig:
396 return "Number too big to be stored in double";
397 case kParseErrorNumberMissFraction:
398 return "Miss fraction part in number";
399 case kParseErrorNumberMissExponent:
400 return "Miss exponent in number";
401 case kParseErrorTermination:
402 return "Parsing was terminated";
403 case kParseErrorUnspecificSyntaxError:
404 return "Unspecific syntax error";
418 using namespace rapidjson;
419 Document& d = m_p->m_document;
420 ParseResult r = d.Parse((
const char*)bytes.
data(), bytes.
size());
421 if (d.HasParseError()) {
422 std::cout <<
"ERROR: " << d.GetParseError() <<
"\n";
423 ARCCORE_FATAL(
"Parsing error file='{0}' ret={1} position={2} message='{3}'",
424 filename, d.GetParseError(),
425 r.Offset(), _getErrorCodeString(r.Code()));
435 parse(bytes,
"(Unknown)");
462 rapidjson::Value& d = m_p->m_document;
463 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.
Liste de valeurs d'un document JSON.
String value() const
Valeur sous forme de String. La chaîne retournée est nulle si 'null()' est vrai.
Int32 valueAsInt32() const
Valeur sous forme de Int64. 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.
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é.
JSONValue child(StringView name) const
Valeur fille de nom name. Retourne une valeur nulle si non trouvé.
constexpr __host__ __device__ pointer data() const noexcept
Pointeur sur le début de la vue.
constexpr __host__ __device__ SizeType size() const noexcept
Retourne la taille du tableau.
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.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
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)
Converti 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.