+20
-12
@@ -179,7 +179,8 @@ public:
|
||||
|
||||
size = CEREAL_RAPIDJSON_ALIGN(size);
|
||||
if (chunkHead_ == 0 || chunkHead_->size + size > chunkHead_->capacity)
|
||||
AddChunk(chunk_capacity_ > size ? chunk_capacity_ : size);
|
||||
if (!AddChunk(chunk_capacity_ > size ? chunk_capacity_ : size))
|
||||
return NULL;
|
||||
|
||||
void *buffer = reinterpret_cast<char *>(chunkHead_) + CEREAL_RAPIDJSON_ALIGN(sizeof(ChunkHeader)) + chunkHead_->size;
|
||||
chunkHead_->size += size;
|
||||
@@ -211,11 +212,13 @@ public:
|
||||
}
|
||||
|
||||
// Realloc process: allocate and copy memory, do not free original buffer.
|
||||
void* newBuffer = Malloc(newSize);
|
||||
CEREAL_RAPIDJSON_ASSERT(newBuffer != 0); // Do not handle out-of-memory explicitly.
|
||||
if (originalSize)
|
||||
std::memcpy(newBuffer, originalPtr, originalSize);
|
||||
return newBuffer;
|
||||
if (void* newBuffer = Malloc(newSize)) {
|
||||
if (originalSize)
|
||||
std::memcpy(newBuffer, originalPtr, originalSize);
|
||||
return newBuffer;
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//! Frees a memory block (concept Allocator)
|
||||
@@ -229,15 +232,20 @@ private:
|
||||
|
||||
//! Creates a new chunk.
|
||||
/*! \param capacity Capacity of the chunk in bytes.
|
||||
\return true if success.
|
||||
*/
|
||||
void AddChunk(size_t capacity) {
|
||||
bool AddChunk(size_t capacity) {
|
||||
if (!baseAllocator_)
|
||||
ownBaseAllocator_ = baseAllocator_ = CEREAL_RAPIDJSON_NEW(BaseAllocator());
|
||||
ChunkHeader* chunk = reinterpret_cast<ChunkHeader*>(baseAllocator_->Malloc(CEREAL_RAPIDJSON_ALIGN(sizeof(ChunkHeader)) + capacity));
|
||||
chunk->capacity = capacity;
|
||||
chunk->size = 0;
|
||||
chunk->next = chunkHead_;
|
||||
chunkHead_ = chunk;
|
||||
if (ChunkHeader* chunk = reinterpret_cast<ChunkHeader*>(baseAllocator_->Malloc(CEREAL_RAPIDJSON_ALIGN(sizeof(ChunkHeader)) + capacity))) {
|
||||
chunk->capacity = capacity;
|
||||
chunk->size = 0;
|
||||
chunk->next = chunkHead_;
|
||||
chunkHead_ = chunk;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
static const int kDefaultChunkCapacity = 64 * 1024; //!< Default chunk capacity.
|
||||
|
||||
+17
-19
@@ -23,24 +23,26 @@
|
||||
#include "memorystream.h"
|
||||
#include "encodedstream.h"
|
||||
#include <new> // placement new
|
||||
#include <limits>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
CEREAL_RAPIDJSON_DIAG_PUSH
|
||||
#ifdef _MSC_VER
|
||||
CEREAL_RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant
|
||||
CEREAL_RAPIDJSON_DIAG_OFF(4244) // conversion from kXxxFlags to 'uint16_t', possible loss of data
|
||||
#endif
|
||||
|
||||
#ifdef __clang__
|
||||
CEREAL_RAPIDJSON_DIAG_PUSH
|
||||
CEREAL_RAPIDJSON_DIAG_OFF(padded)
|
||||
CEREAL_RAPIDJSON_DIAG_OFF(switch-enum)
|
||||
CEREAL_RAPIDJSON_DIAG_OFF(c++98-compat)
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
CEREAL_RAPIDJSON_DIAG_PUSH
|
||||
CEREAL_RAPIDJSON_DIAG_OFF(effc++)
|
||||
#if __GNUC__ >= 6
|
||||
CEREAL_RAPIDJSON_DIAG_OFF(terminate) // ignore throwing CEREAL_RAPIDJSON_ASSERT in CEREAL_RAPIDJSON_NOEXCEPT functions
|
||||
#endif
|
||||
#endif // __GNUC__
|
||||
|
||||
#ifndef CEREAL_RAPIDJSON_NOMEMBERITERATORCLASS
|
||||
#include <iterator> // std::iterator, std::random_access_iterator_tag
|
||||
@@ -478,7 +480,7 @@ template<typename ValueType>
|
||||
struct TypeHelper<ValueType, std::basic_string<typename ValueType::Ch> > {
|
||||
typedef std::basic_string<typename ValueType::Ch> StringType;
|
||||
static bool Is(const ValueType& v) { return v.IsString(); }
|
||||
static StringType Get(const ValueType& v) { return v.GetString(); }
|
||||
static StringType Get(const ValueType& v) { return StringType(v.GetString(), v.GetStringLength()); }
|
||||
static ValueType& Set(ValueType& v, const StringType& data, typename ValueType::AllocatorType& a) { return v.SetString(data, a); }
|
||||
};
|
||||
#endif
|
||||
@@ -952,12 +954,16 @@ public:
|
||||
if (IsUint64()) {
|
||||
uint64_t u = GetUint64();
|
||||
volatile double d = static_cast<double>(u);
|
||||
return static_cast<uint64_t>(d) == u;
|
||||
return (d >= 0.0)
|
||||
&& (d < static_cast<double>(std::numeric_limits<uint64_t>::max()))
|
||||
&& (u == static_cast<uint64_t>(d));
|
||||
}
|
||||
if (IsInt64()) {
|
||||
int64_t i = GetInt64();
|
||||
volatile double d = static_cast<double>(i);
|
||||
return static_cast< int64_t>(d) == i;
|
||||
return (d >= static_cast<double>(std::numeric_limits<int64_t>::min()))
|
||||
&& (d < static_cast<double>(std::numeric_limits<int64_t>::max()))
|
||||
&& (i == static_cast<int64_t>(d));
|
||||
}
|
||||
return true; // double, int, uint are always lossless
|
||||
}
|
||||
@@ -973,6 +979,9 @@ public:
|
||||
bool IsLosslessFloat() const {
|
||||
if (!IsNumber()) return false;
|
||||
double a = GetDouble();
|
||||
if (a < static_cast<double>(-std::numeric_limits<float>::max())
|
||||
|| a > static_cast<double>(std::numeric_limits<float>::max()))
|
||||
return false;
|
||||
double b = static_cast<double>(static_cast<float>(a));
|
||||
return a >= b && a <= b; // Prevent -Wfloat-equal
|
||||
}
|
||||
@@ -1160,8 +1169,8 @@ public:
|
||||
\return Iterator to member, if it exists.
|
||||
Otherwise returns \ref MemberEnd().
|
||||
*/
|
||||
MemberIterator FindMember(const std::basic_string<Ch>& name) { return FindMember(StringRef(name)); }
|
||||
ConstMemberIterator FindMember(const std::basic_string<Ch>& name) const { return FindMember(StringRef(name)); }
|
||||
MemberIterator FindMember(const std::basic_string<Ch>& name) { return FindMember(GenericValue(StringRef(name))); }
|
||||
ConstMemberIterator FindMember(const std::basic_string<Ch>& name) const { return FindMember(GenericValue(StringRef(name))); }
|
||||
#endif
|
||||
|
||||
//! Add a member (name-value pair) to the object.
|
||||
@@ -2561,17 +2570,6 @@ private:
|
||||
};
|
||||
|
||||
CEREAL_RAPIDJSON_NAMESPACE_END
|
||||
|
||||
#ifdef _MSC_VER
|
||||
CEREAL_RAPIDJSON_DIAG_POP
|
||||
#endif
|
||||
|
||||
#ifdef __clang__
|
||||
CEREAL_RAPIDJSON_DIAG_POP
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
CEREAL_RAPIDJSON_DIAG_POP
|
||||
#endif
|
||||
|
||||
#endif // CEREAL_RAPIDJSON_DOCUMENT_H_
|
||||
|
||||
+5
-1
@@ -154,7 +154,11 @@ struct UTF8 {
|
||||
}
|
||||
|
||||
unsigned char type = GetRange(static_cast<unsigned char>(c));
|
||||
*codepoint = (0xFF >> type) & static_cast<unsigned char>(c);
|
||||
if (type >= 32) {
|
||||
*codepoint = 0;
|
||||
} else {
|
||||
*codepoint = (0xFF >> type) & static_cast<unsigned char>(c);
|
||||
}
|
||||
bool result = true;
|
||||
switch (type) {
|
||||
case 2: TAIL(); return result;
|
||||
|
||||
+2
-1
@@ -102,7 +102,8 @@ inline void DigitGen(const DiyFp& W, const DiyFp& Mp, uint64_t delta, char* buff
|
||||
kappa--;
|
||||
if (p2 < delta) {
|
||||
*K += kappa;
|
||||
GrisuRound(buffer, *len, delta, p2, one.f, wp_w.f * kPow10[-static_cast<int>(kappa)]);
|
||||
int index = -static_cast<int>(kappa);
|
||||
GrisuRound(buffer, *len, delta, p2, one.f, wp_w.f * (index < 9 ? kPow10[-static_cast<int>(kappa)] : 0));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -142,7 +142,7 @@ inline bool StrtodDiyFp(const char* decimals, size_t length, size_t decimalPosit
|
||||
size_t remaining = length - i;
|
||||
const unsigned kUlpShift = 3;
|
||||
const unsigned kUlp = 1 << kUlpShift;
|
||||
int error = (remaining == 0) ? 0 : kUlp / 2;
|
||||
int64_t error = (remaining == 0) ? 0 : kUlp / 2;
|
||||
|
||||
DiyFp v(significand, 0);
|
||||
v = v.Normalize();
|
||||
|
||||
+12
-7
@@ -1,5 +1,5 @@
|
||||
// Tencent is pleased to support the open source community by making RapidJSON available.
|
||||
//
|
||||
//
|
||||
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
|
||||
//
|
||||
// Licensed under the MIT License (the "License"); you may not use this file except
|
||||
@@ -7,11 +7,14 @@
|
||||
//
|
||||
// http://opensource.org/licenses/MIT
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software distributed
|
||||
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
// Unless required by applicable law or agreed to in writing, software distributed
|
||||
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations under the License.
|
||||
|
||||
#ifndef CEREAL_RAPIDJSON_ISTREAMWRAPPER_H_
|
||||
#define CEREAL_RAPIDJSON_ISTREAMWRAPPER_H_
|
||||
|
||||
#include "stream.h"
|
||||
#include <iosfwd>
|
||||
|
||||
@@ -43,19 +46,19 @@ CEREAL_RAPIDJSON_NAMESPACE_BEGIN
|
||||
|
||||
\tparam StreamType Class derived from \c std::basic_istream.
|
||||
*/
|
||||
|
||||
|
||||
template <typename StreamType>
|
||||
class BasicIStreamWrapper {
|
||||
public:
|
||||
typedef typename StreamType::char_type Ch;
|
||||
BasicIStreamWrapper(StreamType& stream) : stream_(stream), count_(), peekBuffer_() {}
|
||||
|
||||
Ch Peek() const {
|
||||
Ch Peek() const {
|
||||
typename StreamType::int_type c = stream_.peek();
|
||||
return CEREAL_RAPIDJSON_LIKELY(c != StreamType::traits_type::eof()) ? static_cast<Ch>(c) : '\0';
|
||||
}
|
||||
|
||||
Ch Take() {
|
||||
Ch Take() {
|
||||
typename StreamType::int_type c = stream_.get();
|
||||
if (CEREAL_RAPIDJSON_LIKELY(c != StreamType::traits_type::eof())) {
|
||||
count_++;
|
||||
@@ -109,3 +112,5 @@ CEREAL_RAPIDJSON_DIAG_POP
|
||||
#endif
|
||||
|
||||
CEREAL_RAPIDJSON_NAMESPACE_END
|
||||
|
||||
#endif // CEREAL_RAPIDJSON_ISTREAMWRAPPER_H_
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
// Tencent is pleased to support the open source community by making RapidJSON available.
|
||||
//
|
||||
//
|
||||
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
|
||||
//
|
||||
// Licensed under the MIT License (the "License"); you may not use this file except
|
||||
@@ -7,9 +7,9 @@
|
||||
//
|
||||
// http://opensource.org/licenses/MIT
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software distributed
|
||||
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
// Unless required by applicable law or agreed to in writing, software distributed
|
||||
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations under the License.
|
||||
|
||||
#ifndef CEREAL_RAPIDJSON_MEMORYSTREAM_H_
|
||||
|
||||
@@ -12,6 +12,9 @@
|
||||
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations under the License.
|
||||
|
||||
#ifndef CEREAL_RAPIDJSON_OSTREAMWRAPPER_H_
|
||||
#define CEREAL_RAPIDJSON_OSTREAMWRAPPER_H_
|
||||
|
||||
#include "stream.h"
|
||||
#include <iosfwd>
|
||||
|
||||
@@ -74,3 +77,5 @@ CEREAL_RAPIDJSON_DIAG_POP
|
||||
#endif
|
||||
|
||||
CEREAL_RAPIDJSON_NAMESPACE_END
|
||||
|
||||
#endif // CEREAL_RAPIDJSON_OSTREAMWRAPPER_H_
|
||||
|
||||
+6
-2
@@ -767,8 +767,12 @@ private:
|
||||
tokenCount_ = rhs.tokenCount_ + extraToken;
|
||||
tokens_ = static_cast<Token *>(allocator_->Malloc(tokenCount_ * sizeof(Token) + (nameBufferSize + extraNameBufferSize) * sizeof(Ch)));
|
||||
nameBuffer_ = reinterpret_cast<Ch *>(tokens_ + tokenCount_);
|
||||
std::memcpy(tokens_, rhs.tokens_, rhs.tokenCount_ * sizeof(Token));
|
||||
std::memcpy(nameBuffer_, rhs.nameBuffer_, nameBufferSize * sizeof(Ch));
|
||||
if (rhs.tokenCount_ > 0) {
|
||||
std::memcpy(tokens_, rhs.tokens_, rhs.tokenCount_ * sizeof(Token));
|
||||
}
|
||||
if (nameBufferSize > 0) {
|
||||
std::memcpy(nameBuffer_, rhs.nameBuffer_, nameBufferSize * sizeof(Ch));
|
||||
}
|
||||
|
||||
// Adjust pointers to name buffer
|
||||
std::ptrdiff_t diff = nameBuffer_ - rhs.nameBuffer_;
|
||||
|
||||
@@ -115,6 +115,12 @@ public:
|
||||
}
|
||||
|
||||
bool Key(const Ch* str, SizeType length, bool copy = false) { return String(str, length, copy); }
|
||||
|
||||
#if CEREAL_RAPIDJSON_HAS_STDSTRING
|
||||
bool Key(const std::basic_string<Ch>& str) {
|
||||
return Key(str.data(), SizeType(str.size()));
|
||||
}
|
||||
#endif
|
||||
|
||||
bool EndObject(SizeType memberCount = 0) {
|
||||
(void)memberCount;
|
||||
|
||||
+18
-14
@@ -1,5 +1,5 @@
|
||||
// Tencent is pleased to support the open source community by making RapidJSON available.
|
||||
//
|
||||
//
|
||||
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
|
||||
//
|
||||
// Licensed under the MIT License (the "License"); you may not use this file except
|
||||
@@ -7,9 +7,9 @@
|
||||
//
|
||||
// http://opensource.org/licenses/MIT
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software distributed
|
||||
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
// Unless required by applicable law or agreed to in writing, software distributed
|
||||
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations under the License.
|
||||
|
||||
#ifndef CEREAL_RAPIDJSON_CEREAL_RAPIDJSON_H_
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
/*!\file rapidjson.h
|
||||
\brief common definitions and configuration
|
||||
|
||||
|
||||
\see CEREAL_RAPIDJSON_CONFIG
|
||||
*/
|
||||
|
||||
@@ -110,13 +110,13 @@
|
||||
\see CEREAL_RAPIDJSON_NAMESPACE
|
||||
*/
|
||||
#ifndef CEREAL_RAPIDJSON_NAMESPACE
|
||||
#define CEREAL_RAPIDJSON_NAMESPACE cereal::rapidjson
|
||||
#define CEREAL_RAPIDJSON_NAMESPACE rapidjson
|
||||
#endif
|
||||
#ifndef CEREAL_RAPIDJSON_NAMESPACE_BEGIN
|
||||
#define CEREAL_RAPIDJSON_NAMESPACE_BEGIN namespace cereal { namespace rapidjson {
|
||||
#define CEREAL_RAPIDJSON_NAMESPACE_BEGIN namespace CEREAL_RAPIDJSON_NAMESPACE {
|
||||
#endif
|
||||
#ifndef CEREAL_RAPIDJSON_NAMESPACE_END
|
||||
#define CEREAL_RAPIDJSON_NAMESPACE_END } }
|
||||
#define CEREAL_RAPIDJSON_NAMESPACE_END }
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@@ -241,7 +241,7 @@
|
||||
# elif defined(CEREAL_RAPIDJSON_DOXYGEN_RUNNING)
|
||||
# define CEREAL_RAPIDJSON_ENDIAN
|
||||
# else
|
||||
# error Unknown machine endianess detected. User needs to define CEREAL_RAPIDJSON_ENDIAN.
|
||||
# error Unknown machine endianess detected. User needs to define CEREAL_RAPIDJSON_ENDIAN.
|
||||
# endif
|
||||
#endif // CEREAL_RAPIDJSON_ENDIAN
|
||||
|
||||
@@ -250,7 +250,7 @@
|
||||
|
||||
//! Whether using 64-bit architecture
|
||||
#ifndef CEREAL_RAPIDJSON_64BIT
|
||||
#if defined(__LP64__) || defined(_WIN64) || defined(__EMSCRIPTEN__)
|
||||
#if defined(__LP64__) || (defined(__x86_64__) && defined(__ILP32__)) || defined(_WIN64) || defined(__EMSCRIPTEN__)
|
||||
#define CEREAL_RAPIDJSON_64BIT 1
|
||||
#else
|
||||
#define CEREAL_RAPIDJSON_64BIT 0
|
||||
@@ -423,7 +423,7 @@ CEREAL_RAPIDJSON_NAMESPACE_END
|
||||
#if defined(__GNUC__)
|
||||
#define CEREAL_RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE __attribute__((unused))
|
||||
#else
|
||||
#define CEREAL_RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE
|
||||
#define CEREAL_RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE
|
||||
#endif
|
||||
#ifndef __clang__
|
||||
//!@endcond
|
||||
@@ -474,7 +474,7 @@ CEREAL_RAPIDJSON_NAMESPACE_END
|
||||
|
||||
//!@cond CEREAL_RAPIDJSON_HIDDEN_FROM_DOXYGEN
|
||||
|
||||
#define CEREAL_RAPIDJSON_MULTILINEMACRO_BEGIN do {
|
||||
#define CEREAL_RAPIDJSON_MULTILINEMACRO_BEGIN do {
|
||||
#define CEREAL_RAPIDJSON_MULTILINEMACRO_END \
|
||||
} while((void)0, 0)
|
||||
|
||||
@@ -529,8 +529,12 @@ CEREAL_RAPIDJSON_NAMESPACE_END
|
||||
|
||||
#ifndef CEREAL_RAPIDJSON_HAS_CXX11_RVALUE_REFS
|
||||
#if defined(__clang__)
|
||||
#define CEREAL_RAPIDJSON_HAS_CXX11_RVALUE_REFS __has_feature(cxx_rvalue_references) && \
|
||||
#if __has_feature(cxx_rvalue_references) && \
|
||||
(defined(_LIBCPP_VERSION) || defined(__GLIBCXX__) && __GLIBCXX__ >= 20080306)
|
||||
#define CEREAL_RAPIDJSON_HAS_CXX11_RVALUE_REFS 1
|
||||
#else
|
||||
#define CEREAL_RAPIDJSON_HAS_CXX11_RVALUE_REFS 0
|
||||
#endif
|
||||
#elif (defined(CEREAL_RAPIDJSON_GNUC) && (CEREAL_RAPIDJSON_GNUC >= CEREAL_RAPIDJSON_VERSION_CODE(4,3,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
|
||||
(defined(_MSC_VER) && _MSC_VER >= 1600)
|
||||
|
||||
@@ -601,7 +605,7 @@ enum Type {
|
||||
kFalseType = 1, //!< false
|
||||
kTrueType = 2, //!< true
|
||||
kObjectType = 3, //!< object
|
||||
kArrayType = 4, //!< array
|
||||
kArrayType = 4, //!< array
|
||||
kStringType = 5, //!< string
|
||||
kNumberType = 6 //!< number
|
||||
};
|
||||
|
||||
+23
-12
@@ -43,6 +43,7 @@ CEREAL_RAPIDJSON_DIAG_OFF(4702) // unreachable code
|
||||
|
||||
#ifdef __clang__
|
||||
CEREAL_RAPIDJSON_DIAG_PUSH
|
||||
CEREAL_RAPIDJSON_DIAG_OFF(old-style-cast)
|
||||
CEREAL_RAPIDJSON_DIAG_OFF(padded)
|
||||
CEREAL_RAPIDJSON_DIAG_OFF(switch-enum)
|
||||
#endif
|
||||
@@ -151,6 +152,7 @@ enum ParseFlag {
|
||||
kParseCommentsFlag = 32, //!< Allow one-line (//) and multi-line (/**/) comments.
|
||||
kParseNumbersAsStringsFlag = 64, //!< Parse all numbers (ints/doubles) as strings.
|
||||
kParseTrailingCommasFlag = 128, //!< Allow trailing commas at the end of objects and arrays.
|
||||
kParseNanAndInfFlag = 256, //!< Allow parsing NaN, Inf, Infinity, -Inf and -Infinity as doubles.
|
||||
kParseDefaultFlags = CEREAL_RAPIDJSON_PARSE_DEFAULT_FLAGS //!< Default parse flags. Can be customized by defining CEREAL_RAPIDJSON_PARSE_DEFAULT_FLAGS
|
||||
};
|
||||
|
||||
@@ -700,7 +702,7 @@ private:
|
||||
}
|
||||
|
||||
template<unsigned parseFlags, typename InputStream, typename Handler>
|
||||
void ParseNullOrNan(InputStream& is, Handler& handler) {
|
||||
void ParseNull(InputStream& is, Handler& handler) {
|
||||
CEREAL_RAPIDJSON_ASSERT(is.Peek() == 'n');
|
||||
is.Take();
|
||||
|
||||
@@ -708,10 +710,6 @@ private:
|
||||
if (CEREAL_RAPIDJSON_UNLIKELY(!handler.Null()))
|
||||
CEREAL_RAPIDJSON_PARSE_ERROR(kParseErrorTermination, is.Tell());
|
||||
}
|
||||
else if (Consume(is, 'a') && Consume(is, 'n')) {
|
||||
if (CEREAL_RAPIDJSON_UNLIKELY(!handler.Double( std::numeric_limits<double>::quiet_NaN() )))
|
||||
CEREAL_RAPIDJSON_PARSE_ERROR(kParseErrorTermination, is.Tell());
|
||||
}
|
||||
else
|
||||
CEREAL_RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, is.Tell());
|
||||
}
|
||||
@@ -1142,6 +1140,8 @@ private:
|
||||
(parseFlags & kParseInsituFlag) == 0> s(*this, copy.s);
|
||||
|
||||
size_t startOffset = s.Tell();
|
||||
double d = 0.0;
|
||||
bool useNanOrInf = false;
|
||||
|
||||
// Parse minus
|
||||
bool minus = Consume(s, '-');
|
||||
@@ -1183,18 +1183,26 @@ private:
|
||||
significandDigit++;
|
||||
}
|
||||
}
|
||||
else if (CEREAL_RAPIDJSON_UNLIKELY(Consume(s, 'i')) && Consume(s, 'n') && Consume(s, 'f')) {
|
||||
double inf = std::numeric_limits<double>::infinity();
|
||||
if (CEREAL_RAPIDJSON_UNLIKELY(!handler.Double(minus ? -inf : inf)))
|
||||
CEREAL_RAPIDJSON_PARSE_ERROR(kParseErrorTermination, startOffset);
|
||||
return;
|
||||
// Parse NaN or Infinity here
|
||||
else if ((parseFlags & kParseNanAndInfFlag) && CEREAL_RAPIDJSON_LIKELY((s.Peek() == 'I' || s.Peek() == 'N'))) {
|
||||
useNanOrInf = true;
|
||||
if (CEREAL_RAPIDJSON_LIKELY(Consume(s, 'N') && Consume(s, 'a') && Consume(s, 'N'))) {
|
||||
d = std::numeric_limits<double>::quiet_NaN();
|
||||
}
|
||||
else if (CEREAL_RAPIDJSON_LIKELY(Consume(s, 'I') && Consume(s, 'n') && Consume(s, 'f'))) {
|
||||
d = (minus ? -std::numeric_limits<double>::infinity() : std::numeric_limits<double>::infinity());
|
||||
if (CEREAL_RAPIDJSON_UNLIKELY(s.Peek() == 'i' && !(Consume(s, 'i') && Consume(s, 'n')
|
||||
&& Consume(s, 'i') && Consume(s, 't') && Consume(s, 'y'))))
|
||||
CEREAL_RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, s.Tell());
|
||||
}
|
||||
else
|
||||
CEREAL_RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, s.Tell());
|
||||
}
|
||||
else
|
||||
CEREAL_RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, s.Tell());
|
||||
|
||||
// Parse 64bit int
|
||||
bool useDouble = false;
|
||||
double d = 0.0;
|
||||
if (use64bit) {
|
||||
if (minus)
|
||||
while (CEREAL_RAPIDJSON_LIKELY(s.Peek() >= '0' && s.Peek() <= '9')) {
|
||||
@@ -1357,6 +1365,9 @@ private:
|
||||
|
||||
cont = handler.Double(minus ? -d : d);
|
||||
}
|
||||
else if (useNanOrInf) {
|
||||
cont = handler.Double(d);
|
||||
}
|
||||
else {
|
||||
if (use64bit) {
|
||||
if (minus)
|
||||
@@ -1380,7 +1391,7 @@ private:
|
||||
template<unsigned parseFlags, typename InputStream, typename Handler>
|
||||
void ParseValue(InputStream& is, Handler& handler) {
|
||||
switch (is.Peek()) {
|
||||
case 'n': ParseNullOrNan<parseFlags>(is, handler); break;
|
||||
case 'n': ParseNull <parseFlags>(is, handler); break;
|
||||
case 't': ParseTrue <parseFlags>(is, handler); break;
|
||||
case 'f': ParseFalse <parseFlags>(is, handler); break;
|
||||
case '"': ParseString<parseFlags>(is, handler); break;
|
||||
|
||||
+14
-26
@@ -19,13 +19,6 @@
|
||||
#include "pointer.h"
|
||||
#include <cmath> // abs, floor
|
||||
|
||||
#ifdef __clang__
|
||||
CEREAL_RAPIDJSON_DIAG_PUSH
|
||||
CEREAL_RAPIDJSON_DIAG_OFF(weak-vtables)
|
||||
CEREAL_RAPIDJSON_DIAG_OFF(exit-time-destructors)
|
||||
CEREAL_RAPIDJSON_DIAG_OFF(c++98-compat-pedantic)
|
||||
#endif
|
||||
|
||||
#if !defined(CEREAL_RAPIDJSON_SCHEMA_USE_INTERNALREGEX)
|
||||
#define CEREAL_RAPIDJSON_SCHEMA_USE_INTERNALREGEX 1
|
||||
#else
|
||||
@@ -58,18 +51,20 @@ CEREAL_RAPIDJSON_DIAG_OFF(c++98-compat-pedantic)
|
||||
#include "stringbuffer.h"
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__)
|
||||
CEREAL_RAPIDJSON_DIAG_PUSH
|
||||
|
||||
#if defined(__GNUC__)
|
||||
CEREAL_RAPIDJSON_DIAG_OFF(effc++)
|
||||
#endif
|
||||
|
||||
#ifdef __clang__
|
||||
CEREAL_RAPIDJSON_DIAG_PUSH
|
||||
CEREAL_RAPIDJSON_DIAG_OFF(weak-vtables)
|
||||
CEREAL_RAPIDJSON_DIAG_OFF(exit-time-destructors)
|
||||
CEREAL_RAPIDJSON_DIAG_OFF(c++98-compat-pedantic)
|
||||
CEREAL_RAPIDJSON_DIAG_OFF(variadic-macros)
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
CEREAL_RAPIDJSON_DIAG_PUSH
|
||||
CEREAL_RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated
|
||||
#endif
|
||||
|
||||
@@ -413,9 +408,11 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
AssignIfExist(allOf_, *schemaDocument, p, value, GetAllOfString(), document);
|
||||
AssignIfExist(anyOf_, *schemaDocument, p, value, GetAnyOfString(), document);
|
||||
AssignIfExist(oneOf_, *schemaDocument, p, value, GetOneOfString(), document);
|
||||
if (schemaDocument) {
|
||||
AssignIfExist(allOf_, *schemaDocument, p, value, GetAllOfString(), document);
|
||||
AssignIfExist(anyOf_, *schemaDocument, p, value, GetAnyOfString(), document);
|
||||
AssignIfExist(oneOf_, *schemaDocument, p, value, GetOneOfString(), document);
|
||||
}
|
||||
|
||||
if (const ValueType* v = GetMember(value, GetNotString())) {
|
||||
schemaDocument->CreateSchema(¬_, p.Append(GetNotString(), allocator_), *v, document);
|
||||
@@ -578,7 +575,9 @@ public:
|
||||
}
|
||||
|
||||
~Schema() {
|
||||
allocator_->Free(enum_);
|
||||
if (allocator_) {
|
||||
allocator_->Free(enum_);
|
||||
}
|
||||
if (properties_) {
|
||||
for (SizeType i = 0; i < propertyCount_; i++)
|
||||
properties_[i].~Property();
|
||||
@@ -1339,7 +1338,7 @@ public:
|
||||
\param remoteProvider An optional remote schema document provider for resolving remote reference. Can be null.
|
||||
\param allocator An optional allocator instance for allocating memory. Can be null.
|
||||
*/
|
||||
GenericSchemaDocument(const ValueType& document, IRemoteSchemaDocumentProviderType* remoteProvider = 0, Allocator* allocator = 0) CEREAL_RAPIDJSON_NOEXCEPT :
|
||||
explicit GenericSchemaDocument(const ValueType& document, IRemoteSchemaDocumentProviderType* remoteProvider = 0, Allocator* allocator = 0) :
|
||||
remoteProvider_(remoteProvider),
|
||||
allocator_(allocator),
|
||||
ownAllocator_(),
|
||||
@@ -2002,17 +2001,6 @@ private:
|
||||
};
|
||||
|
||||
CEREAL_RAPIDJSON_NAMESPACE_END
|
||||
|
||||
#if defined(__GNUC__)
|
||||
CEREAL_RAPIDJSON_DIAG_POP
|
||||
#endif
|
||||
|
||||
#ifdef __clang__
|
||||
CEREAL_RAPIDJSON_DIAG_POP
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
CEREAL_RAPIDJSON_DIAG_POP
|
||||
#endif
|
||||
|
||||
#endif // CEREAL_RAPIDJSON_SCHEMA_H_
|
||||
|
||||
+1
-1
@@ -95,7 +95,7 @@ inline void PutUnsafe(Stream& stream, typename Stream::Ch c) {
|
||||
//! Put N copies of a character to a stream.
|
||||
template<typename Stream, typename Ch>
|
||||
inline void PutN(Stream& stream, Ch c, size_t n) {
|
||||
PutReserve<Stream>(stream, n);
|
||||
PutReserve(stream, n);
|
||||
for (size_t i = 0; i < n; i++)
|
||||
PutUnsafe(stream, c);
|
||||
}
|
||||
|
||||
+54
-35
@@ -41,6 +41,7 @@ CEREAL_RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant
|
||||
#ifdef __clang__
|
||||
CEREAL_RAPIDJSON_DIAG_PUSH
|
||||
CEREAL_RAPIDJSON_DIAG_OFF(padded)
|
||||
CEREAL_RAPIDJSON_DIAG_OFF(unreachable-code)
|
||||
#endif
|
||||
|
||||
CEREAL_RAPIDJSON_NAMESPACE_BEGIN
|
||||
@@ -62,6 +63,7 @@ CEREAL_RAPIDJSON_NAMESPACE_BEGIN
|
||||
enum WriteFlag {
|
||||
kWriteNoFlags = 0, //!< No flags are set.
|
||||
kWriteValidateEncodingFlag = 1, //!< Validate encoding of JSON strings.
|
||||
kWriteNanAndInfFlag = 2, //!< Allow writing of Inf, -Inf and NaN.
|
||||
kWriteDefaultFlags = CEREAL_RAPIDJSON_WRITE_DEFAULT_FLAGS //!< Default write flags. Can be customized by defining CEREAL_RAPIDJSON_WRITE_DEFAULT_FLAGS
|
||||
};
|
||||
|
||||
@@ -167,30 +169,30 @@ public:
|
||||
*/
|
||||
//@{
|
||||
|
||||
bool Null() { Prefix(kNullType); return WriteNull(); }
|
||||
bool Bool(bool b) { Prefix(b ? kTrueType : kFalseType); return WriteBool(b); }
|
||||
bool Int(int i) { Prefix(kNumberType); return WriteInt(i); }
|
||||
bool Uint(unsigned u) { Prefix(kNumberType); return WriteUint(u); }
|
||||
bool Int64(int64_t i64) { Prefix(kNumberType); return WriteInt64(i64); }
|
||||
bool Uint64(uint64_t u64) { Prefix(kNumberType); return WriteUint64(u64); }
|
||||
bool Null() { Prefix(kNullType); return EndValue(WriteNull()); }
|
||||
bool Bool(bool b) { Prefix(b ? kTrueType : kFalseType); return EndValue(WriteBool(b)); }
|
||||
bool Int(int i) { Prefix(kNumberType); return EndValue(WriteInt(i)); }
|
||||
bool Uint(unsigned u) { Prefix(kNumberType); return EndValue(WriteUint(u)); }
|
||||
bool Int64(int64_t i64) { Prefix(kNumberType); return EndValue(WriteInt64(i64)); }
|
||||
bool Uint64(uint64_t u64) { Prefix(kNumberType); return EndValue(WriteUint64(u64)); }
|
||||
|
||||
//! Writes the given \c double value to the stream
|
||||
/*!
|
||||
\param d The value to be written.
|
||||
\return Whether it is succeed.
|
||||
*/
|
||||
bool Double(double d) { Prefix(kNumberType); return WriteDouble(d); }
|
||||
bool Double(double d) { Prefix(kNumberType); return EndValue(WriteDouble(d)); }
|
||||
|
||||
bool RawNumber(const Ch* str, SizeType length, bool copy = false) {
|
||||
(void)copy;
|
||||
Prefix(kNumberType);
|
||||
return WriteString(str, length);
|
||||
return EndValue(WriteString(str, length));
|
||||
}
|
||||
|
||||
bool String(const Ch* str, SizeType length, bool copy = false) {
|
||||
(void)copy;
|
||||
Prefix(kStringType);
|
||||
return WriteString(str, length);
|
||||
return EndValue(WriteString(str, length));
|
||||
}
|
||||
|
||||
#if CEREAL_RAPIDJSON_HAS_STDSTRING
|
||||
@@ -212,10 +214,7 @@ public:
|
||||
CEREAL_RAPIDJSON_ASSERT(level_stack_.GetSize() >= sizeof(Level));
|
||||
CEREAL_RAPIDJSON_ASSERT(!level_stack_.template Top<Level>()->inArray);
|
||||
level_stack_.template Pop<Level>(1);
|
||||
bool ret = WriteEndObject();
|
||||
if (CEREAL_RAPIDJSON_UNLIKELY(level_stack_.Empty())) // end of json text
|
||||
os_->Flush();
|
||||
return ret;
|
||||
return EndValue(WriteEndObject());
|
||||
}
|
||||
|
||||
bool StartArray() {
|
||||
@@ -229,10 +228,7 @@ public:
|
||||
CEREAL_RAPIDJSON_ASSERT(level_stack_.GetSize() >= sizeof(Level));
|
||||
CEREAL_RAPIDJSON_ASSERT(level_stack_.template Top<Level>()->inArray);
|
||||
level_stack_.template Pop<Level>(1);
|
||||
bool ret = WriteEndArray();
|
||||
if (CEREAL_RAPIDJSON_UNLIKELY(level_stack_.Empty())) // end of json text
|
||||
os_->Flush();
|
||||
return ret;
|
||||
return EndValue(WriteEndArray());
|
||||
}
|
||||
//@}
|
||||
|
||||
@@ -253,7 +249,7 @@ public:
|
||||
\param length Length of the json.
|
||||
\param type Type of the root of json.
|
||||
*/
|
||||
bool RawValue(const Ch* json, size_t length, Type type) { Prefix(type); return WriteRawValue(json, length); }
|
||||
bool RawValue(const Ch* json, size_t length, Type type) { Prefix(type); return EndValue(WriteRawValue(json, length)); }
|
||||
|
||||
protected:
|
||||
//! Information for each nested level
|
||||
@@ -320,25 +316,24 @@ protected:
|
||||
|
||||
bool WriteDouble(double d) {
|
||||
if (internal::Double(d).IsNanOrInf()) {
|
||||
if (!(writeFlags & kWriteNanAndInfFlag))
|
||||
return false;
|
||||
if (internal::Double(d).IsNan()) {
|
||||
PutReserve(*os_, 3);
|
||||
PutUnsafe(*os_, static_cast<typename TargetEncoding::Ch>('n'));
|
||||
PutUnsafe(*os_, static_cast<typename TargetEncoding::Ch>('a'));
|
||||
PutUnsafe(*os_, static_cast<typename TargetEncoding::Ch>('n'));
|
||||
} else {
|
||||
if (internal::Double(d).Sign()) {
|
||||
PutReserve(*os_, 4);
|
||||
PutUnsafe(*os_, static_cast<typename TargetEncoding::Ch>('-'));
|
||||
} else {
|
||||
PutReserve(*os_, 3);
|
||||
}
|
||||
PutUnsafe(*os_, static_cast<typename TargetEncoding::Ch>('i'));
|
||||
PutUnsafe(*os_, static_cast<typename TargetEncoding::Ch>('n'));
|
||||
PutUnsafe(*os_, static_cast<typename TargetEncoding::Ch>('f'));
|
||||
PutUnsafe(*os_, 'N'); PutUnsafe(*os_, 'a'); PutUnsafe(*os_, 'N');
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
if (internal::Double(d).Sign()) {
|
||||
PutReserve(*os_, 9);
|
||||
PutUnsafe(*os_, '-');
|
||||
}
|
||||
else
|
||||
PutReserve(*os_, 8);
|
||||
PutUnsafe(*os_, 'I'); PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'f');
|
||||
PutUnsafe(*os_, 'i'); PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'i'); PutUnsafe(*os_, 't'); PutUnsafe(*os_, 'y');
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
char buffer[25];
|
||||
char* end = internal::dtoa(d, buffer, maxDecimalPlaces_);
|
||||
PutReserve(*os_, static_cast<size_t>(end - buffer));
|
||||
@@ -459,6 +454,13 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
// Flush the value if it is the top level one.
|
||||
bool EndValue(bool ret) {
|
||||
if (CEREAL_RAPIDJSON_UNLIKELY(level_stack_.Empty())) // end of json text
|
||||
os_->Flush();
|
||||
return ret;
|
||||
}
|
||||
|
||||
OutputStream* os_;
|
||||
internal::Stack<StackAllocator> level_stack_;
|
||||
int maxDecimalPlaces_;
|
||||
@@ -506,8 +508,25 @@ inline bool Writer<StringBuffer>::WriteUint64(uint64_t u) {
|
||||
|
||||
template<>
|
||||
inline bool Writer<StringBuffer>::WriteDouble(double d) {
|
||||
if (internal::Double(d).IsNanOrInf())
|
||||
return false;
|
||||
if (internal::Double(d).IsNanOrInf()) {
|
||||
// Note: This code path can only be reached if (CEREAL_RAPIDJSON_WRITE_DEFAULT_FLAGS & kWriteNanAndInfFlag).
|
||||
if (!(kWriteDefaultFlags & kWriteNanAndInfFlag))
|
||||
return false;
|
||||
if (internal::Double(d).IsNan()) {
|
||||
PutReserve(*os_, 3);
|
||||
PutUnsafe(*os_, 'N'); PutUnsafe(*os_, 'a'); PutUnsafe(*os_, 'N');
|
||||
return true;
|
||||
}
|
||||
if (internal::Double(d).Sign()) {
|
||||
PutReserve(*os_, 9);
|
||||
PutUnsafe(*os_, '-');
|
||||
}
|
||||
else
|
||||
PutReserve(*os_, 8);
|
||||
PutUnsafe(*os_, 'I'); PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'f');
|
||||
PutUnsafe(*os_, 'i'); PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'i'); PutUnsafe(*os_, 't'); PutUnsafe(*os_, 'y');
|
||||
return true;
|
||||
}
|
||||
|
||||
char *buffer = os_->Push(25);
|
||||
char* end = internal::dtoa(d, buffer, maxDecimalPlaces_);
|
||||
|
||||
Executable
+4
@@ -0,0 +1,4 @@
|
||||
# Applies renaming within all of the rapidjson source files to add a cereal prefix
|
||||
find ./../include/cereal/external/rapidjson/ -type f -name \*.h -exec sed -i "s/RAPIDJSON_/CEREAL_RAPIDJSON_/g" {} \;
|
||||
echo "Remember to backport any cereal specific changes not in this version of RapidJSON!"
|
||||
echo "See https://github.com/USCiLab/cereal/commits/develop/include/cereal/external/rapidjson"
|
||||
Reference in New Issue
Block a user