stringbuffer.h

Engine/source/persistence/rapidjson/stringbuffer.h

More...

Classes:

class

Represents an in-memory output stream.

Namespaces:

namespace

Detailed Description

 1
 2#ifndef RAPIDJSON_STRINGBUFFER_H_
 3#define RAPIDJSON_STRINGBUFFER_H_
 4
 5#include "rapidjson.h"
 6#include "internal/stack.h"
 7
 8namespace rapidjson {
 9
10//! Represents an in-memory output stream.
11/*!
12   \tparam Encoding Encoding of the stream.
13   \tparam Allocator type for allocating memory buffer.
14   \implements Stream
15*/
16template <typename Encoding, typename Allocator = CrtAllocator>
17struct GenericStringBuffer {
18   typedef typename Encoding::Ch Ch;
19
20   GenericStringBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {}
21
22   void Put(Ch c) { *stack_.template Push<Ch>() = c; }
23   void Flush() {}
24
25   void Clear() { stack_.Clear(); }
26
27   const Ch* GetString() const {
28      // Push and pop a null terminator. This is safe.
29      *stack_.template Push<Ch>() = '\0';
30      stack_.template Pop<Ch>(1);
31
32      return stack_.template Bottom<Ch>();
33   }
34
35   size_t GetSize() const { return stack_.GetSize(); }
36
37   static const size_t kDefaultCapacity = 256;
38   mutable internal::Stack<Allocator> stack_;
39};
40
41typedef GenericStringBuffer<UTF8<> > StringBuffer;
42
43//! Implement specialized version of PutN() with memset() for better performance.
44template<>
45inline void PutN(GenericStringBuffer<UTF8<> >& stream, char c, size_t n) {
46   memset(stream.stack_.Push<char>(n), c, n * sizeof(c));
47}
48
49} // namespace rapidjson
50
51#endif // RAPIDJSON_STRINGBUFFER_H_
52