15 #ifndef CEREAL_RAPIDJSON_ENCODEDSTREAM_H_
16 #define CEREAL_RAPIDJSON_ENCODEDSTREAM_H_
22 CEREAL_RAPIDJSON_DIAG_PUSH
23 CEREAL_RAPIDJSON_DIAG_OFF(effc++)
27 CEREAL_RAPIDJSON_DIAG_PUSH
28 CEREAL_RAPIDJSON_DIAG_OFF(padded)
38 template <
typename Encoding,
typename InputByteStream>
42 typedef typename Encoding::Ch
Ch;
50 size_t Tell()
const {
return is_.Tell(); }
73 if (
static_cast<unsigned char>(
is_.Peek()) == 0xEFu)
is_.Take();
74 if (
static_cast<unsigned char>(
is_.Peek()) == 0xBBu)
is_.Take();
75 if (
static_cast<unsigned char>(
is_.Peek()) == 0xBFu)
is_.Take();
79 size_t Tell()
const {
return is_.Tell(); }
99 template <
typename Encoding,
typename OutputByteStream>
103 typedef typename Encoding::Ch
Ch;
107 Encoding::PutBOM(
os_);
127 #define CEREAL_RAPIDJSON_ENCODINGS_FUNC(x) UTF8<Ch>::x, UTF16LE<Ch>::x, UTF16BE<Ch>::x, UTF32LE<Ch>::x, UTF32BE<Ch>::x
134 template <
typename CharType,
typename InputByteStream>
179 const unsigned char* c =
reinterpret_cast<const unsigned char *
>(
is_->Peek4());
183 unsigned bom =
static_cast<unsigned>(c[0] | (c[1] << 8) | (c[2] << 16) | (c[3] << 24));
203 int pattern = (c[0] ? 1 : 0) | (c[1] ? 2 : 0) | (c[2] ? 4 : 0) | (c[3] ? 8 : 0);
232 template <
typename CharType,
typename OutputByteStream>
275 typedef void (*PutBOMFunc)(OutputByteStream&);
287 #undef CEREAL_RAPIDJSON_ENCODINGS_FUNC
292 CEREAL_RAPIDJSON_DIAG_POP
296 CEREAL_RAPIDJSON_DIAG_POP
#define CEREAL_RAPIDJSON_ASSERT(x)
Definition: json.hpp:50
Output stream wrapper with dynamically bound encoding and automatic encoding detection.
Definition: encodedstream.h:233
CEREAL_RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch)==1)
AutoUTFOutputStream(OutputByteStream &os, UTFType type, bool putBOM)
Constructor.
Definition: encodedstream.h:244
void Flush()
Definition: encodedstream.h:261
void(* PutFunc)(OutputByteStream &, Ch)
Definition: encodedstream.h:280
Ch * PutBegin()
Definition: encodedstream.h:267
Ch Take()
Definition: encodedstream.h:265
AutoUTFOutputStream & operator=(const AutoUTFOutputStream &)
size_t PutEnd(Ch *)
Definition: encodedstream.h:268
UTFType GetType() const
Definition: encodedstream.h:258
OutputByteStream * os_
Definition: encodedstream.h:282
UTFType type_
Definition: encodedstream.h:283
size_t Tell() const
Definition: encodedstream.h:266
void PutBOM()
Definition: encodedstream.h:274
CharType Ch
Definition: encodedstream.h:236
AutoUTFOutputStream(const AutoUTFOutputStream &)
void Put(Ch c)
Definition: encodedstream.h:260
Ch Peek() const
Definition: encodedstream.h:264
PutFunc putFunc_
Definition: encodedstream.h:284
Output byte stream wrapper with statically bound encoding.
Definition: encodedstream.h:100
void Put(Ch c)
Definition: encodedstream.h:110
CEREAL_RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch)==1)
size_t Tell() const
Definition: encodedstream.h:116
Ch Peek() const
Definition: encodedstream.h:114
EncodedOutputStream(const EncodedOutputStream &)
void Flush()
Definition: encodedstream.h:111
Ch * PutBegin()
Definition: encodedstream.h:117
size_t PutEnd(Ch *)
Definition: encodedstream.h:118
Ch Take()
Definition: encodedstream.h:115
OutputByteStream & os_
Definition: encodedstream.h:124
Encoding::Ch Ch
Definition: encodedstream.h:103
EncodedOutputStream(OutputByteStream &os, bool putBOM=true)
Definition: encodedstream.h:105
EncodedOutputStream & operator=(const EncodedOutputStream &)
#define CEREAL_RAPIDJSON_ENCODINGS_FUNC(x)
Definition: encodedstream.h:127
UTFType
Runtime-specified UTF encoding type of a stream.
Definition: encodings.h:603
@ kUTF32BE
UTF-32 big endian.
Definition: encodings.h:608
@ kUTF16BE
UTF-16 big endian.
Definition: encodings.h:606
@ kUTF8
UTF-8.
Definition: encodings.h:604
@ kUTF32LE
UTF-32 little endian.
Definition: encodings.h:607
@ kUTF16LE
UTF-16 little endian.
Definition: encodings.h:605
#define CEREAL_RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:121
#define CEREAL_RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:124
type
The type the bitset is encoded with.
Definition: bitset.hpp:44
Represents an in-memory input byte stream.
Definition: memorystream.h:40
UTF-8 encoding.
Definition: encodings.h:96
CharType Ch
Definition: encodings.h:97