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