#ifndef RAPIDJSON_STRINGBUFFER_H_#define RAPIDJSON_STRINGBUFFER_H_#include"rapidjson.h"#include"internal/stack.h"namespacerapidjson{//! Represents an in-memory output stream./*!\tparam Encoding Encoding of the stream.\tparam Allocator type for allocating memory buffer.\implements Stream*/template<typenameEncoding,typenameAllocator=CrtAllocator>structGenericStringBuffer{typedeftypenameEncoding::ChCh;GenericStringBuffer(Allocator*allocator=0,size_tcapacity=kDefaultCapacity):stack_(allocator,capacity){}voidPut(Chc){*stack_.templatePush<Ch>()=c;}voidClear(){stack_.Clear();}constchar*GetString()const{// Push and pop a null terminator. This is safe.*stack_.templatePush<Ch>()='\0';stack_.templatePop<Ch>(1);returnstack_.templateBottom<Ch>();}size_tSize()const{returnstack_.GetSize();}staticconstsize_tkDefaultCapacity=256;mutableinternal::Stack<Allocator>stack_;};typedefGenericStringBuffer<UTF8<>>StringBuffer;//! Implement specialized version of PutN() with memset() for better performance.template<>inlinevoidPutN(GenericStringBuffer<UTF8<>>&stream,charc,size_tn){memset(stream.stack_.Push<char>(n),c,n*sizeof(c));}}// namespace rapidjson#endif // RAPIDJSON_STRINGBUFFER_H_