source: trunk/lib/Node.h @ 91

Last change on this file since 91 was 91, checked in by Jari Häkkinen, 16 years ago

Fixes #4, #19, #32, #34: Started to implement subversion API usage.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.0 KB
Line 
1// $Id: Node.h 91 2006-03-23 22:56:17Z jari $
2
3/*
4  Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson
5
6  This file is part of svnstat, http://lev.thep.lu.se/trac/svnstat
7
8  svnstat is free software; you can redistribute it and/or modify it
9  under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  svnstat is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#ifndef _theplu_svnstat_node_
25#define _theplu_svnstat_node_
26
27#include "Stats.h"
28
29#include <ostream>
30#include <sstream>
31#include <stdexcept>
32#include <string>
33
34namespace theplu{
35namespace svnstat{
36
37  ///
38  /// If something goes wrong in the use of the Node or its derived
39  /// classes, a NodeException is thrown.
40  ///
41  struct NodeException : public std::runtime_error
42  { inline NodeException(const std::string& msg) : runtime_error(msg) {} };
43
44  ///
45  /// Abstract Base Class for files.
46  ///
47  class Node
48  {
49  public:
50
51    ///
52    /// @brief Constructor
53    ///
54    //    Node(void) : path_("JARI_trixar"), stats_("JARI_trixar") { };
55
56    ///
57    /// @brief Constructor
58    ///
59    Node(const std::string& path, const std::string& output="")
60      : path_(path), stats_(path)
61      { output_name_ = output + name(); }
62
63    ///
64    /// @brief Destructor
65    ///
66    virtual inline ~Node(void) {};
67
68    ///
69    /// @return A properly formatted html link to this node.
70    ///
71    inline std::string html_link(void) const
72    { return "<a href=\"" + output_name() + ".html\">" + name() + "</a>"; }
73
74    inline std::string html_tablerow(void) const
75    {
76      std::stringstream ss;
77      ss << "<tr><td>" << html_link() << "</td><td align=right>" << stats_.rows()
78         << "</td></tr>\n";
79      return ss.str();
80    }
81
82    inline const std::string& output_name(void) const { return output_name_; }
83
84    ///
85    /// @brief parsing file using svn blame.
86    ///
87    virtual const Stats& parse(const bool verbose=false)=0;
88
89    inline const std::string& path(void) const { return path_; }
90
91    ///
92    /// Function printing HTML in current working directory
93    ///
94    virtual void print(const bool verbose=false) const=0;
95
96  protected:
97    ///
98    /// Function returning everything after the last '/'
99    ///
100    /// @return name of node (not full path)
101    ///
102    std::string name(void) const;
103
104    ///
105    /// @brief print html footer of page
106    ///
107    void print_footer(std::ostream&) const;
108   
109    ///
110    /// @brief print html header of page
111    ///
112    void print_header(std::ostream&) const;
113
114    std::string output_name_; //without suffix
115    std::string path_;
116    Stats stats_;
117
118  private:
119    ///
120    /// @brief Copy Constructor, not implemented
121    ///
122    Node(const Node&);
123
124  };
125
126}} // end of namespace svnstat and namespace theplu
127
128#endif
Note: See TracBrowser for help on using the repository browser.