fastcgi++
A C++ FastCGI/Web API
webstreambuf.hpp
Go to the documentation of this file.
1 
10 /*******************************************************************************
11 * Copyright (C) 2016 Eddie Carle [eddie@isatec.ca] *
12 * *
13 * This file is part of fastcgi++. *
14 * *
15 * fastcgi++ is free software: you can redistribute it and/or modify it under *
16 * the terms of the GNU Lesser General Public License as published by the Free *
17 * Software Foundation, either version 3 of the License, or (at your option) *
18 * any later version. *
19 * *
20 * fastcgi++ is distributed in the hope that it will be useful, but WITHOUT ANY *
21 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for *
23 * more details. *
24 * *
25 * You should have received a copy of the GNU Lesser General Public License *
26 * along with fastcgi++. If not, see <http://www.gnu.org/licenses/>. *
27 *******************************************************************************/
28 
29 #ifndef FASTCGIPP_WEBSTREAMBUF_HPP
30 #define FASTCGIPP_WEBSTREAMBUF_HPP
31 
32 #include <map>
33 #include <streambuf>
34 
36 namespace Fastcgipp
37 {
39 
182  enum class Encoding
183  {
184  NONE,
185  HTML,
186  URL
187  };
188 
189  template<class charT, class traits>
190  std::basic_ostream<charT, traits>& operator<<(
191  std::basic_ostream<charT, traits>& os,
192  const Encoding& encoding);
193 
195 
205  template <class charT, class traits = std::char_traits<charT>>
206  class WebStreambuf: public std::basic_streambuf<charT, traits>
207  {
208  typedef typename std::basic_streambuf<charT, traits>::char_type char_type;
209 
211  static const std::map<charT, const std::basic_string<charT>> htmlCharacters;
212 
214  static const std::map<charT, const std::basic_string<charT>> urlCharacters;
215 
217  std::streamsize xsputn(const char_type *s, std::streamsize n);
218 
221 
222  friend std::basic_ostream<charT, traits>& operator<< <charT, traits>(
223  std::basic_ostream<charT, traits>& os,
224  const Encoding& encoding);
225  public:
227  m_encoding(Encoding::NONE)
228  {}
229  };
230 }
231 
232 #endif
Encoding
Stream manipulator for setting output encoding.
Encoding m_encoding
Output encoding for stream buffer.
std::basic_streambuf< charT, traits >::char_type char_type
Topmost namespace for the fastcgi++ library.
Stream buffer class for output of HTML/Web stream.
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &os, const Encoding &encoding)
static const std::map< charT, const std::basic_string< charT > > htmlCharacters
Needed for html encoding of stream data.
static const std::map< charT, const std::basic_string< charT > > urlCharacters
Needed for url encoding of stream data.