CoolProp  4.2.5
An open-source fluid property and humid air property database
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
stringbuffer.h
Go to the documentation of this file.
1 #ifndef RAPIDJSON_STRINGBUFFER_H_
2 #define RAPIDJSON_STRINGBUFFER_H_
3 
4 #include "rapidjson.h"
5 #include "internal/stack.h"
6 
7 namespace rapidjson {
8 
10 
15 template <typename Encoding, typename Allocator = CrtAllocator>
17  typedef typename Encoding::Ch Ch;
18 
19  GenericStringBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {}
20 
21  void Put(Ch c) { *stack_.template Push<Ch>() = c; }
22 
23  void Clear() { stack_.Clear(); }
24 
25  const char* GetString() const {
26  // Push and pop a null terminator. This is safe.
27  *stack_.template Push<Ch>() = '\0';
28  stack_.template Pop<Ch>(1);
29 
30  return stack_.template Bottom<Ch>();
31  }
32 
33  size_t Size() const { return stack_.GetSize(); }
34 
35  static const size_t kDefaultCapacity = 256;
37 };
38 
40 
42 template<>
43 inline void PutN(GenericStringBuffer<UTF8<> >& stream, char c, size_t n) {
44  memset(stream.stack_.Push<char>(n), c, n * sizeof(c));
45 }
46 
47 } // namespace rapidjson
48 
49 #endif // RAPIDJSON_STRINGBUFFER_H_
const char * GetString() const
Definition: stringbuffer.h:25
A type-unsafe stack for storing different types of data.
Definition: stack.h:14
internal::Stack< Allocator > stack_
Definition: stringbuffer.h:36
Represents an in-memory output stream.
Definition: stringbuffer.h:16
static const size_t kDefaultCapacity
Definition: stringbuffer.h:35
UTF-8 encoding.
Definition: rapidjson.h:335
Concept for allocating, resizing and freeing memory block.
GenericStringBuffer(Allocator *allocator=0, size_t capacity=kDefaultCapacity)
Definition: stringbuffer.h:19
GenericStringBuffer< UTF8<> > StringBuffer
Definition: stringbuffer.h:39
void PutN(Stream &stream, Ch c, size_t n)
Put N copies of a character to a stream.
Definition: rapidjson.h:448