 |
Blamite Game Engine - blam!
00368.02.12.23.1347.blamite
The core library for the Blamite Game Engine.
|
Go to the documentation of this file.
15 #ifndef RAPIDJSON_WRITER_H_
16 #define RAPIDJSON_WRITER_H_
28 #if defined(RAPIDJSON_SIMD) && defined(_MSC_VER)
30 #pragma intrinsic(_BitScanForward)
32 #ifdef RAPIDJSON_SSE42
33 #include <nmmintrin.h>
34 #elif defined(RAPIDJSON_SSE2)
35 #include <emmintrin.h>
36 #elif defined(RAPIDJSON_NEON)
42 RAPIDJSON_DIAG_OFF(padded)
43 RAPIDJSON_DIAG_OFF(unreachable-code)
44 RAPIDJSON_DIAG_OFF(c++98-compat)
45 #elif defined(_MSC_VER)
47 RAPIDJSON_DIAG_OFF(4127)
61 #ifndef RAPIDJSON_WRITE_DEFAULT_FLAGS
62 #define RAPIDJSON_WRITE_DEFAULT_FLAGS kWriteNoFlags
89 template<
typename OutputStream,
typename SourceEncoding = UTF8<>,
typename TargetEncoding = UTF8<>,
typename StackAllocator = CrtAllocator,
unsigned writeFlags = kWriteDefaultFlags>
92 typedef typename SourceEncoding::Ch
Ch;
109 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
210 #if RAPIDJSON_HAS_STDSTRING
211 bool String(
const std::basic_string<Ch>& str) {
224 #if RAPIDJSON_HAS_STDSTRING
225 bool Key(
const std::basic_string<Ch>& str)
317 for (
const char* p = buffer; p != end; ++p)
318 PutUnsafe(*
os_,
static_cast<typename OutputStream::Ch
>(*p));
326 for (
const char* p = buffer; p != end; ++p)
327 PutUnsafe(*
os_,
static_cast<typename OutputStream::Ch
>(*p));
335 for (
const char* p = buffer; p != end; ++p)
336 PutUnsafe(*
os_,
static_cast<typename OutputStream::Ch
>(*p));
344 for (
char* p = buffer; p != end; ++p)
345 PutUnsafe(*
os_,
static_cast<typename OutputStream::Ch
>(*p));
372 for (
char* p = buffer; p != end; ++p)
373 PutUnsafe(*
os_,
static_cast<typename OutputStream::Ch
>(*p));
378 static const typename OutputStream::Ch hexDigits[16] = {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'A',
'B',
'C',
'D',
'E',
'F' };
379 static const char escape[256] = {
380 #define Z16 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
382 'u',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
'b',
't',
'n',
'u',
'f',
'r',
'u',
'u',
383 'u',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
384 0, 0,
'"', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
386 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
'\\', 0, 0, 0,
391 if (TargetEncoding::supportUnicode)
400 if (!TargetEncoding::supportUnicode &&
static_cast<unsigned>(c) >= 0x80) {
407 if (codepoint <= 0xD7FF || (codepoint >= 0xE000 && codepoint <= 0xFFFF)) {
416 unsigned s = codepoint - 0x010000;
417 unsigned lead = (s >> 10) + 0xD800;
418 unsigned trail = (s & 0x3FF) + 0xDC00;
431 else if ((
sizeof(
Ch) == 1 ||
static_cast<unsigned>(c) < 256) &&
RAPIDJSON_UNLIKELY(escape[
static_cast<unsigned char>(c)])) {
434 PutUnsafe(*
os_,
static_cast<typename OutputStream::Ch
>(escape[
static_cast<unsigned char>(c)]));
435 if (escape[
static_cast<unsigned char>(c)] ==
'u') {
438 PutUnsafe(*
os_, hexDigits[
static_cast<unsigned char>(c) >> 4]);
439 PutUnsafe(*
os_, hexDigits[
static_cast<unsigned char>(c) & 0xF]);
515 char *buffer = os_->Push(11);
517 os_->Pop(
static_cast<size_t>(11 - (end - buffer)));
523 char *buffer = os_->Push(10);
525 os_->Pop(
static_cast<size_t>(10 - (end - buffer)));
531 char *buffer = os_->Push(21);
533 os_->Pop(
static_cast<size_t>(21 - (end - buffer)));
539 char *buffer = os_->Push(20);
541 os_->Pop(
static_cast<size_t>(20 - (end - buffer)));
567 char *buffer = os_->Push(25);
569 os_->Pop(
static_cast<size_t>(25 - (end - buffer)));
573 #if defined(RAPIDJSON_SSE2) || defined(RAPIDJSON_SSE42)
582 const char* p = is.
src_;
583 const char* end = is.
head_ + length;
584 const char* nextAligned =
reinterpret_cast<const char*
>((
reinterpret_cast<size_t>(p) + 15) &
static_cast<size_t>(~15));
585 const char* endAligned =
reinterpret_cast<const char*
>(
reinterpret_cast<size_t>(end) &
static_cast<size_t>(~15));
586 if (nextAligned > end)
589 while (p != nextAligned)
590 if (*p < 0x20 || *p ==
'\"' || *p ==
'\\') {
595 os_->PutUnsafe(*p++);
598 static const char dquote[16] = {
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"' };
599 static const char bslash[16] = {
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\' };
600 static const char space[16] = { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F };
601 const __m128i dq = _mm_loadu_si128(
reinterpret_cast<const __m128i *
>(&dquote[0]));
602 const __m128i bs = _mm_loadu_si128(
reinterpret_cast<const __m128i *
>(&bslash[0]));
603 const __m128i sp = _mm_loadu_si128(
reinterpret_cast<const __m128i *
>(&space[0]));
605 for (; p != endAligned; p += 16) {
606 const __m128i s = _mm_load_si128(
reinterpret_cast<const __m128i *
>(p));
607 const __m128i t1 = _mm_cmpeq_epi8(s, dq);
608 const __m128i t2 = _mm_cmpeq_epi8(s, bs);
609 const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp);
610 const __m128i
x = _mm_or_si128(_mm_or_si128(t1, t2), t3);
611 unsigned short r =
static_cast<unsigned short>(_mm_movemask_epi8(
x));
614 #ifdef _MSC_VER // Find the index of first escaped
615 unsigned long offset;
616 _BitScanForward(&offset, r);
619 len =
static_cast<SizeType>(__builtin_ffs(r) - 1);
621 char* q =
reinterpret_cast<char*
>(os_->PushUnsafe(len));
622 for (
size_t i = 0; i < len; i++)
628 _mm_storeu_si128(
reinterpret_cast<__m128i *
>(os_->PushUnsafe(16)), s);
634 #elif defined(RAPIDJSON_NEON)
643 const char* p = is.
src_;
644 const char* end = is.
head_ + length;
645 const char* nextAligned =
reinterpret_cast<const char*
>((
reinterpret_cast<size_t>(p) + 15) &
static_cast<size_t>(~15));
646 const char* endAligned =
reinterpret_cast<const char*
>(
reinterpret_cast<size_t>(end) &
static_cast<size_t>(~15));
647 if (nextAligned > end)
650 while (p != nextAligned)
651 if (*p < 0x20 || *p ==
'\"' || *p ==
'\\') {
656 os_->PutUnsafe(*p++);
659 const uint8x16_t s0 = vmovq_n_u8(
'"');
660 const uint8x16_t s1 = vmovq_n_u8(
'\\');
661 const uint8x16_t s2 = vmovq_n_u8(
'\b');
662 const uint8x16_t s3 = vmovq_n_u8(32);
664 for (; p != endAligned; p += 16) {
665 const uint8x16_t s = vld1q_u8(
reinterpret_cast<const uint8_t *
>(p));
666 uint8x16_t
x = vceqq_u8(s, s0);
667 x = vorrq_u8(
x, vceqq_u8(s, s1));
668 x = vorrq_u8(
x, vceqq_u8(s, s2));
669 x = vorrq_u8(
x, vcltq_u8(s, s3));
672 uint64_t low = vgetq_lane_u64(vreinterpretq_u64_u8(
x), 0);
673 uint64_t high = vgetq_lane_u64(vreinterpretq_u64_u8(
x), 1);
676 bool escaped =
false;
689 char* q =
reinterpret_cast<char*
>(os_->PushUnsafe(len));
690 for (
size_t i = 0; i < len; i++)
696 vst1q_u8(
reinterpret_cast<uint8_t *
>(os_->PushUnsafe(16)), s);
702 #endif // RAPIDJSON_NEON
706 #if defined(_MSC_VER) || defined(__clang__)
710 #endif // RAPIDJSON_RAPIDJSON_H_
char * i32toa(int32_t value, char *buffer)
Definition: itoa.h:115
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:124
char * dtoa(double value, char *buffer, int maxDecimalPlaces=324)
Definition: dtoa.h:220
unsigned char uint8_t
Definition: stdint.h:124
bool WriteRawValue(const Ch *json, size_t length)
Definition: writer.h:460
@ kNullType
null
Definition: rapidjson.h:730
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:121
bool WriteDouble(double d)
Definition: writer.h:349
@ kWriteNoFlags
No flags are set.
Definition: writer.h:67
@ kFalseType
false
Definition: rapidjson.h:731
@ kArrayType
array
Definition: rapidjson.h:734
@ kWriteNanAndInfFlag
Allow writing of Infinity, -Infinity and NaN.
Definition: writer.h:69
Encoding conversion.
Definition: encodings.h:658
int maxDecimalPlaces_
Definition: writer.h:502
bool Uint(unsigned u)
Definition: writer.h:185
Type
Type of JSON value.
Definition: rapidjson.h:729
void Clear()
Definition: stack.h:99
bool Double(double d)
Writes the given double value to the stream.
Definition: writer.h:194
bool hasRoot_
Definition: writer.h:503
Ch Peek() const
Definition: stream.h:159
bool Int64(int64_t i64)
Definition: writer.h:186
@ kObjectType
object
Definition: rapidjson.h:733
bool WriteEndArray()
Definition: writer.h:458
bool Bool(bool b)
Definition: writer.h:183
void PutUnsafe(Stream &stream, typename Stream::Ch c)
Write character to a stream, presuming buffer is reserved.
Definition: stream.h:91
size_t valueCount
number of values in this level
Definition: writer.h:292
WriteFlag
Combination of writeFlags.
Definition: writer.h:66
@ kWriteValidateEncodingFlag
Validate encoding of JSON strings.
Definition: writer.h:68
Writer(OutputStream &os, StackAllocator *stackAllocator=0, size_t levelDepth=kDefaultLevelDepth)
Constructor.
Definition: writer.h:102
bool ScanWriteUnescapedString(GenericStringStream< SourceEncoding > &is, size_t length)
Definition: writer.h:451
bool IsComplete() const
Checks whether the output is a complete JSON.
Definition: writer.h:144
bool WriteUint64(uint64_t u64)
Definition: writer.h:340
void SetMaxDecimalPlaces(int maxDecimalPlaces)
Sets the maximum number of decimal places for double output.
Definition: writer.h:173
bool WriteString(const Ch *str, SizeType length)
Definition: writer.h:377
Level(bool inArray_)
Definition: writer.h:291
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:415
bool WriteUint(unsigned u)
Definition: writer.h:322
bool String(const Ch *const &str)
Simpler but slower overload.
Definition: writer.h:259
bool Null()
Definition: writer.h:182
bool EndObject(SizeType memberCount=0)
Definition: writer.h:231
uint32_t clzll(uint64_t x)
Definition: clzll.h:32
char * i64toa(int64_t value, char *buffer)
Definition: itoa.h:294
Blam::LinearAllocator allocator
– TO BE FILLED IN BY VERTIGO –
Definition: main.cpp:76
@ kStringType
string
Definition: rapidjson.h:735
int GetMaxDecimalPlaces() const
Definition: writer.h:148
bool WriteStartArray()
Definition: writer.h:457
Read-only string stream.
Definition: fwd.h:47
JSON writer.
Definition: fwd.h:95
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:437
unsigned int uint32_t
Definition: stdint.h:126
size_t Tell() const
Definition: stream.h:161
#define RAPIDJSON_WRITE_DEFAULT_FLAGS
Definition: writer.h:62
bool WriteBool(bool b)
Definition: writer.h:301
unsigned __int64 uint64_t
Definition: stdint.h:136
bool Key(const Ch *str, SizeType length, bool copy=false)
Definition: writer.h:222
@ kNumberType
number
Definition: rapidjson.h:736
bool WriteInt64(int64_t i64)
Definition: writer.h:331
bool Key(const Ch *const &str)
Definition: writer.h:260
bool WriteEndObject()
Definition: writer.h:456
void Prefix(Type type)
Definition: writer.h:473
bool StartArray()
Definition: writer.h:240
size_t GetSize() const
Definition: stack.h:178
bool inArray
true if in array, otherwise in object
Definition: writer.h:293
const Ch * src_
Current read position.
Definition: stream.h:168
internal::Stack< StackAllocator > level_stack_
Definition: writer.h:501
void Flush()
Flush the output stream.
Definition: writer.h:282
void PutReserve(Stream &stream, size_t count)
Reserve n characters for writing to a stream.
Definition: stream.h:84
bool EndArray(SizeType elementCount=0)
Definition: writer.h:246
OutputStream * os_
Definition: writer.h:500
bool Int(int i)
Definition: writer.h:184
signed __int64 int64_t
Definition: stdint.h:135
Writer(StackAllocator *allocator=0, size_t levelDepth=kDefaultLevelDepth)
Definition: writer.h:106
Ch Take()
Definition: stream.h:160
bool StartObject()
Definition: writer.h:216
bool WriteStartObject()
Definition: writer.h:455
SourceEncoding::Ch Ch
Definition: writer.h:92
The original diffuse textures are from the NVIDIA texture with other maps generated from them by Steve Streeting The following license applies to all textures Single Product or Project Use of NVSDK Art Imagery THIS IS A LEGAL immediately delete the NVSDK Art Imagery from your hard disk If you proceed to use any of the you thereby signify that you have agreed to all of the terms and conditions set forth below You may not copy
Definition: TextureUsageAgreement.txt:6
static const int kDefaultMaxDecimalPlaces
Definition: writer.h:94
bool Empty() const
Definition: stack.h:177
@ kTrueType
true
Definition: rapidjson.h:732
static const size_t kDefaultLevelDepth
Definition: writer.h:286
bool String(const Ch *str, SizeType length, bool copy=false)
Definition: writer.h:203
bool WriteNull()
Definition: writer.h:296
void Reset(OutputStream &os)
Reset the writer with a new stream.
Definition: writer.h:134
char * u64toa(uint64_t value, char *buffer)
Definition: itoa.h:126
bool WriteInt(int i)
Definition: writer.h:313
config GlyphExtraSpacing x
Definition: README.txt:30
const Ch * head_
Original head of the string.
Definition: stream.h:169
Information for each nested level.
Definition: writer.h:290
#define RAPIDJSON_LIKELY(x)
Compiler branching hint for expression with high probability to be true.
Definition: rapidjson.h:494
char * u32toa(uint32_t value, char *buffer)
Definition: itoa.h:39
bool Uint64(uint64_t u64)
Definition: writer.h:187
bool RawValue(const Ch *json, size_t length, Type type)
Write a raw JSON value.
Definition: writer.h:272
#define RAPIDJSON_UNLIKELY(x)
Compiler branching hint for expression with low probability to be true.
Definition: rapidjson.h:507
@ kWriteDefaultFlags
Default write flags. Can be customized by defining RAPIDJSON_WRITE_DEFAULT_FLAGS.
Definition: writer.h:70
SizeType StrLen(const Ch *s)
Custom strlen() which works on different character types.
Definition: strfunc.h:31
bool EndValue(bool ret)
Definition: writer.h:494
bool RawNumber(const Ch *str, SizeType length, bool copy=false)
Definition: writer.h:196