Changeset 606 for trunk/lib/HtmlBuf.h


Ignore:
Timestamp:
Apr 20, 2008, 5:46:56 AM (13 years ago)
Author:
Peter Johansson
Message:

Fixes ticket:318. Changed HtmlStream? to be inherited from ostream and created a HtmlBuf? (inherited from streambuf) that does the real work.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/lib/HtmlBuf.h

    r604 r606  
    1 #ifndef _theplu_svndigest_html_stream_
    2 #define _theplu_svndigest_html_stream_
     1#ifndef _theplu_svndigest_html_buf_
     2#define _theplu_svndigest_html_buf_
    33
    44// $Id$
    55
    66/*
    7   Copyright (C) 2007 Peter Johansson
     7  Copyright (C) 2007, 2008 Peter Johansson
    88
    99  This file is part of svndigest, http://trac.thep.lu.se/svndigest
     
    2525*/
    2626
     27#include <cstdio>
     28#include <locale>
    2729#include <map>
    28 #include <fstream>
    29 #include <sstream>
     30#include <streambuf>
     31#include <string>
    3032
    3133namespace theplu{
    3234namespace svndigest{
    33 
    3435  ///
    35   /// Filtering text to html code.
     36  /// Buffer that translates certain chars to the corresponding string
     37  /// representing the character in HTML. The class is typically not
     38  /// used directly but through the convenience class HtmlStream.
    3639  ///
    37   class HtmlStream
     40  class HtmlBuf : public std::streambuf
    3841  {
    3942  public:
     43    /// \param buf Buffer output is sent to.
     44    HtmlBuf(std::streambuf& buf);
    4045
    41     ///
    42     /// @brief Constructor
    43     ///
    44     HtmlStream(std::ostream&);
    45 
    46     ///
    47     /// @brief Destructor
    48     ///
    49     ~HtmlStream(void);
    50 
    51     ///
    52     /// \brief filter and print stringstream
    53     ///
    54     void print(std::stringstream&);
    55 
    56     ///
    57     /// \return reference to underlying ostream
    58     ///
    59     std::ostream& stream(void);
     46    typedef std::char_traits<char>::int_type int_type;
    6047
    6148  private:
    62     ///
    63     /// @brief Copy Constructor, not implemented
    64     ///
    65     HtmlStream(const HtmlStream&);
     49    // dictionary how to transform chars
     50    std::map<char, std::string> map_;
     51    std::streambuf& buf_;
    6652
    67     std::map<char, std::string> map_;
    68     std::ostream& os_;
     53    // called from base class
     54    int_type overflow (int_type c);
    6955  };
    70 
    71 
    72   template <typename T>
    73   HtmlStream& operator<<(HtmlStream& html, const T& rhs)
    74   {
    75     std::stringstream ss;
    76     ss << rhs;
    77     html.print(ss);
    78     return html;
    79   }
    8056
    8157}} // end of namespace svndigest and namespace theplu
Note: See TracChangeset for help on using the changeset viewer.