8 #ifndef CPPCMS_STEAL_BUF_H 9 #define CPPCMS_STEAL_BUF_H 46 void range(
char const *cbegin,
char const *cend)
48 char *
begin =
const_cast<char*
>(cbegin);
49 char *
end =
const_cast<char*
>(cend);
50 setg(begin,begin,end);
62 char const *
end()
const 86 buf_.range(begin,end);
99 char const *
end()
const 108 buf_.range(begin,end);
125 template<
size_t OnStackSize = 128>
173 if(pbase() == on_stack_) {
174 current_size = OnStackSize;
175 new_size = OnStackSize * 2;
176 on_heap_ = (
char *)malloc(new_size + 1);
178 throw std::bad_alloc();
179 memcpy(on_heap_,on_stack_,current_size);
182 current_size = pptr() - pbase();
183 new_size = current_size * 2;
184 char *new_ptr = (
char *)realloc(on_heap_,new_size + 1);
186 throw std::bad_alloc();
190 setp(on_heap_,on_heap_ + new_size);
200 setp(on_stack_,on_stack_+OnStackSize);
203 char on_stack_[OnStackSize + 1];
219 template<
size_t Size = 128>
245 stolen_ = out.rdbuf(
this);
254 if(stream_ && stolen_) {
255 stream_->rdbuf(stolen_);
265 std::streambuf *stolen_;
266 std::ostream *stream_;
276 template<
size_t Size = 128>
318 template<
typename Filter,
int BufferSize=128>
321 filterbuf() : output_(0), output_stream_(0)
323 setp(buffer_,buffer_+BufferSize);
325 filterbuf(std::ostream &out) : output_(0), output_stream_(0)
327 setp(buffer_,buffer_+BufferSize);
337 void steal(std::ostream &out)
340 output_stream_ = &out;
341 output_ = out.rdbuf(
this);
349 output_stream_->rdbuf(output_);
369 if(static_cast<Filter*>(
this)->convert(pbase(),pptr(),output_)!=0) {
370 output_stream_->setstate(std::ios_base::failbit);
373 setp(buffer_,buffer_ + BufferSize);
376 char buffer_[BufferSize];
377 std::streambuf *output_;
378 std::ostream *output_stream_;
381 template<
typename Filter>
384 filterbuf() : output_(0), output_stream_(0)
387 filterbuf(std::ostream &out) : output_(0), output_stream_(0)
395 void steal(std::ostream &out)
398 output_stream_ = &out;
399 output_ = out.rdbuf(
this);
405 output_stream_->rdbuf(output_);
416 if(write(&tmp,&tmp+1)!=0)
421 std::streamsize xsputn(
char const *s,std::streamsize size)
423 if(write(s,s+size)!=0)
428 int write(
char const *
begin,
char const *
end)
430 if(static_cast<Filter*>(
this)->convert(begin,end,output_)!=0) {
431 output_stream_->setstate(std::ios_base::failbit);
436 std::streambuf *output_;
437 std::ostream *output_stream_;
void range(char const *begin, char const *end)
Definition: steal_buf.h:106
char * end()
Definition: steal_buf.h:140
char const * end() const
Definition: steal_buf.h:99
Definition: steal_buf.h:72
char * begin()
Definition: steal_buf.h:133
char * begin()
Definition: steal_buf.h:289
void steal(std::ostream &out)
Definition: steal_buf.h:242
This is the namespace where all CppCMS functionality is placed.
Definition: application.h:19
const_char_buf()
Definition: steal_buf.h:32
char * c_str()
Definition: steal_buf.h:303
const_char_istream()
Definition: steal_buf.h:77
std::string str()
Definition: steal_buf.h:155
char const * end() const
Definition: steal_buf.h:62
char * end()
Definition: steal_buf.h:296
stackstream()
Definition: steal_buf.h:282
void range(char const *cbegin, char const *cend)
Definition: steal_buf.h:46
Fast output stream object.
Definition: steal_buf.h:277
const_char_istream(char const *begin, char const *end)
Definition: steal_buf.h:84
Definition: steal_buf.h:27
Definition: steal_buf.h:319
This is a special buffer that allows to "steal" some chunk of text from the output stream...
Definition: steal_buf.h:220
char * c_str()
Definition: steal_buf.h:147
std::string str()
Definition: steal_buf.h:310
char const * begin() const
Definition: steal_buf.h:55
steal_buffer(std::ostream &out)
Definition: steal_buf.h:225
Very simple output stream buffer that uses stack for small chunks of text and then allocates memory o...
Definition: steal_buf.h:126
char const * begin() const
Definition: steal_buf.h:92
void release()
Definition: steal_buf.h:252
const_char_buf(char const *begin, char const *end)
Definition: steal_buf.h:39
steal_buffer()
Definition: steal_buf.h:234