fastcgi++  3.1alpha
A C++ FastCGI/Web API
webstreambuf.hpp
Go to the documentation of this file.
1 
9 /*******************************************************************************
10 * Copyright (C) 2018 Eddie Carle [eddie@isatec.ca] *
11 * *
12 * This file is part of fastcgi++. *
13 * *
14 * fastcgi++ is free software: you can redistribute it and/or modify it under *
15 * the terms of the GNU Lesser General Public License as published by the Free *
16 * Software Foundation, either version 3 of the License, or (at your option) *
17 * any later version. *
18 * *
19 * fastcgi++ is distributed in the hope that it will be useful, but WITHOUT ANY *
20 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *
21 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for *
22 * more details. *
23 * *
24 * You should have received a copy of the GNU Lesser General Public License *
25 * along with fastcgi++. If not, see <http://www.gnu.org/licenses/>. *
26 *******************************************************************************/
27 
28 #ifndef FASTCGIPP_WEBSTREAMBUF_HPP
29 #define FASTCGIPP_WEBSTREAMBUF_HPP
30 
31 #include <map>
32 #include <streambuf>
33 
35 namespace Fastcgipp
36 {
38 
181  enum class Encoding
182  {
183  NONE,
184  HTML,
185  URL
186  };
187 
188  template<class charT, class traits>
189  std::basic_ostream<charT, traits>& operator<<(
190  std::basic_ostream<charT, traits>& os,
191  const Encoding& encoding);
192 
194 
204  template <class charT, class traits = std::char_traits<charT>>
205  class WebStreambuf: public std::basic_streambuf<charT, traits>
206  {
207  typedef typename std::basic_streambuf<charT, traits>::int_type int_type;
208  typedef typename std::basic_streambuf<charT, traits>::traits_type traits_type;
209  typedef typename std::basic_streambuf<charT, traits>::char_type char_type;
210 
212  static const std::map<charT, const std::basic_string<charT>> htmlCharacters;
213 
215  static const std::map<charT, const std::basic_string<charT>> urlCharacters;
216 
218  std::streamsize xsputn(const char_type *s, std::streamsize n);
219 
222 
223  friend std::basic_ostream<charT, traits>& operator<< <charT, traits>(
224  std::basic_ostream<charT, traits>& os,
225  const Encoding& encoding);
226 
227  int sync()
228  {
229  return emptyBuffer()?0:-1;
230  }
231 
232  int_type overflow(int_type c = traits_type::eof());
233 
234  protected:
236  virtual bool emptyBuffer() =0;
237 
240  {}
241  };
242 }
243 
244 #endif
Fastcgipp::WebStreambuf::int_type
std::basic_streambuf< charT, traits >::int_type int_type
Definition: webstreambuf.hpp:224
Fastcgipp::WebStreambuf::sync
int sync()
Definition: webstreambuf.hpp:244
Fastcgipp::operator<<
std::basic_ostream< charT, Traits > & operator<<(std::basic_ostream< charT, Traits > &os, const Address &address)
Address stream insertion operation.
Definition: address.cpp:179
Fastcgipp::WebStreambuf::overflow
int_type overflow(int_type c=traits_type::eof())
Definition: webstreambuf.cpp:205
Fastcgipp::Encoding::NONE
@ NONE
Fastcgipp::WebStreambuf::WebStreambuf
WebStreambuf()
Definition: webstreambuf.hpp:255
Fastcgipp::WebStreambuf::m_encoding
Encoding m_encoding
Output encoding for stream buffer.
Definition: webstreambuf.hpp:238
Fastcgipp::Encoding::HTML
@ HTML
Fastcgipp::WebStreambuf::emptyBuffer
virtual bool emptyBuffer()=0
Code converts, packages and deals with all data in the stream buffer.
Fastcgipp::Encoding::URL
@ URL
Fastcgipp::Encoding
Encoding
Stream manipulator for setting output encoding.
Definition: webstreambuf.hpp:198
Fastcgipp::WebStreambuf::htmlCharacters
static const std::map< charT, const std::basic_string< charT > > htmlCharacters
Needed for html encoding of stream data.
Definition: webstreambuf.hpp:229
Fastcgipp::WebStreambuf::traits_type
std::basic_streambuf< charT, traits >::traits_type traits_type
Definition: webstreambuf.hpp:225
Fastcgipp
Topmost namespace for the fastcgi++ library.
Definition: fcgistreambuf.cpp:34
Fastcgipp::WebStreambuf::char_type
std::basic_streambuf< charT, traits >::char_type char_type
Definition: webstreambuf.hpp:226
Fastcgipp::WebStreambuf::urlCharacters
static const std::map< charT, const std::basic_string< charT > > urlCharacters
Needed for url encoding of stream data.
Definition: webstreambuf.hpp:232
Fastcgipp::WebStreambuf::xsputn
std::streamsize xsputn(const char_type *s, std::streamsize n)
Derived from std::basic_streambuf<charT, traits>
Definition: webstreambuf.cpp:144