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))
213 auto x = m_p->toValue();
215 return x->GetUint64();
227 auto d = m_p->toValue();
229 if (x == d->MemberEnd())
231 return JSONWrapperUtils::build(x);
240 return keyValueChild(name).
value();
249 JSONKeyValue k = keyValueChild(name);
263 auto d = m_p->toValue();
267 for (
auto& x : d->GetObject()) {
268 auto y = JSONWrapperUtils::build(&x);
269 values.add(y.value());
281 return JSONValueList();
282 auto d = m_p->toValue();
283 JSONValueList values;
286 for (rapidjson::SizeType i = 0; i < d->Size(); ++i) {
287 rapidjson::Value& x = (*d)[i];
288 auto y = JSONWrapperUtils::build(&x);
302 auto d = m_p->toValue();
314 auto d = m_p->toValue();
315 return d->IsObject();
322keyValueChildren()
const
325 return JSONKeyValueList();
326 auto d = m_p->toValue();
327 JSONKeyValueList values;
328 for (
auto& x : d->GetObject()) {
329 auto y = JSONWrapperUtils::build(&x);
340 return m_p->toValue()->IsNull();
348 return m_p->toValue()->IsBool();
356 return m_p->toValue()->IsString();
364 return m_p->toValue()->IsNumber();
372 return m_p->toValue()->IsInt64();
380 return m_p->toValue()->IsUint64();
400 rapidjson::Document m_document;
429 return "The document is empty";
431 return "The document root must not follow by other values";
433 return "Invalid value";
435 return "Missing a name for object member";
437 return "Missing a colon after a name of object member";
439 return "Missing a comma or '}' after an object member";
441 return "Missing a comma or ']' after an array element";
443 return "Incorrect hex digit after \\u escape in string";
445 return "The surrogate pair in string is invalid";
447 return "Invalid escape character in string";
449 return "Missing a closing quotation mark in string";
451 return "Invalid encoding in string";
453 return "Number too big to be stored in double";
455 return "Miss fraction part in number";
457 return "Miss exponent in number";
459 return "Parsing was terminated";
461 return "Unspecific syntax error";
482 r = d.
Parse<
kParseNoFlags>(
reinterpret_cast<const char*
>(bytes.data()), bytes.size());
499 ARCCORE_FATAL(
"Parsing error file='{0}' ret={1} position={2} message='{3}'",
511 parse(bytes,
"(Unknown)", flags);
538 rapidjson::Value& d = m_p->m_document;
539 return JSONWrapperUtils::build(&d);
#define ARCCORE_FATAL(...)
Macro throwing a FatalErrorException.
void parse(Span< const Byte > bytes, Int16 flags=ParseNoFlags)
Reads the file in UTF-8 format.
@ ParseNoFlags
No flags are set.
@ ParseNumbersAsStringsFlag
Parse all numbers (ints/doubles) as strings.
@ ParseCommentsFlag
Allow one-line (//) and multi-line (/**/) comments.
JSONValue root() const
Root element.
List of (key,value) pairs of a JSON document.
Represents a (key,value) pair of JSON.
List of values of a JSON document.
String value() const
Value in String format. The returned string is null if 'null()' is true.
bool isUint64() const
True if the value is an integer in the 'UInt64' range.
UInt64 valueAsUInt64() const
Value in UInt64 format. Returns 0 if 'null()' is true.
Int32 valueAsInt32() const
Value in Int64 format. Returns 0 if 'null()' is true.
Real valueAsReal() const
Value in Real format. Returns 0.0 if 'null()' is true.
bool valueAsBool() const
Value in boolean format. Returns false if 'null()' is true.
Int64 valueAsInt64() const
Value in Int64 format. Returns 0 if 'null()' is true.
bool isInt64() const
True if the value is an integer in the 'Int64' range.
StringView valueAsStringView() const
Value in StringView format. The string is empty if 'null()' is true.
JSONValue expectedChild(StringView name) const
Child value with name name. Throws an exception if not found.
bool isBool() const
True if the value is a boolean.
bool isString() const
True if the value is a string.
bool isNull() const
True if the value is of 'null' type.
JSONValue child(StringView name) const
Child value with name name. Returns a null value if not found.
bool isNumber() const
True if the value is a number.
View of an array of elements of type T.
View of a UTF-8 character string.
constexpr Span< const Byte > bytes() const ARCCORE_NOEXCEPT
Returns the conversion of the instance in UTF-8 encoding.
Unicode character string.
constexpr __host__ __device__ pointer data() const noexcept
Pointer to the start of the view.
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
Unsigned integer type of 64 bits.
std::int64_t Int64
Signed integer type of 64 bits.
std::int16_t Int16
Signed integer type of 16 bits.
double Real
Type representing a real number.
Impl::SpanTypeFromSize< conststd::byte, SizeType >::SpanType asBytes(const SpanImpl< DataType, SizeType, Extent > &s)
Converts the view into an array of non-modifiable bytes.
unsigned char Byte
Type of a byte.
std::int32_t Int32
Signed integer type of 32 bits.
@ kParseNoFlags
No flags are set.
@ kParseCommentsFlag
Allow one-line (//) and multi-line (/**/) comments.
@ kParseNumbersAsStringsFlag
Parse all numbers (ints/doubles) as strings.
Result of parsing (wraps ParseErrorCode).
ParseErrorCode Code() const
Get the error code.
size_t Offset() const
Get the error offset, if IsError(), 0 otherwise.