8 #ifndef CPPCMS_STEAL_BUF_H
9 #define CPPCMS_STEAL_BUF_H
31 template<
size_t OnStackSize = 128>
79 if(pbase() == on_stack_) {
80 current_size = OnStackSize;
81 new_size = OnStackSize * 2;
82 on_heap_ = (
char *)malloc(new_size + 1);
84 throw std::bad_alloc();
85 memcpy(on_heap_,on_stack_,current_size);
88 current_size = pptr() - pbase();
89 new_size = current_size * 2;
90 char *new_ptr = (
char *)realloc(on_heap_,new_size + 1);
92 throw std::bad_alloc();
96 setp(on_heap_,on_heap_ + new_size);
106 setp(on_stack_,on_stack_+OnStackSize);
109 char on_stack_[OnStackSize + 1];
125 template<
size_t Size = 128>
151 stolen_ = out.rdbuf(
this);
160 if(stream_ && stolen_) {
161 stream_->rdbuf(stolen_);
171 std::streambuf *stolen_;
172 std::ostream *stream_;
182 template<
size_t Size = 128>
char * end()
Definition: steal_buf.h:46
char * begin()
Definition: steal_buf.h:39
char * begin()
Definition: steal_buf.h:195
void steal(std::ostream &out)
Definition: steal_buf.h:148
char * c_str()
Definition: steal_buf.h:209
std::string str()
Definition: steal_buf.h:61
char * end()
Definition: steal_buf.h:202
stackstream()
Definition: steal_buf.h:188
Fast output stream object.
Definition: steal_buf.h:183
This is a special buffer that allows to "steal" some chunk of text from the output stream...
Definition: steal_buf.h:126
char * c_str()
Definition: steal_buf.h:53
std::string str()
Definition: steal_buf.h:216
steal_buffer(std::ostream &out)
Definition: steal_buf.h:131
Very simple output stream buffer that uses stack for small chunks of text and then allocates memory o...
Definition: steal_buf.h:32
void release()
Definition: steal_buf.h:158
steal_buffer()
Definition: steal_buf.h:140