source: trunk/lib/Node.h @ 80

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

Removed nasty bug: svnstat crashed when the last checkin contained zero statistics
count items only, eg. empty directories or binary files.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.1 KB
Line 
1// $Id: Node.h 80 2006-03-10 16:52:04Z jari $
2
3#ifndef _theplu_svnstat_node_
4#define _theplu_svnstat_node_
5
6#include "Stats.h"
7
8#include <ostream>
9#include <sstream>
10#include <string>
11
12namespace theplu{
13namespace svnstat{
14
15  ///
16  /// Abstract Base Class for files.
17  ///
18  class Node
19  {
20  public:
21    ///
22    /// @brief Constructor
23    ///
24    Node(const std::string& path, const std::string& output="")
25      : path_(path), stats_(path)
26      { output_name_ = output + name(); }
27
28    ///
29    /// @brief Destructor
30    ///
31    virtual inline ~Node(void) {};
32
33    ///
34    /// @return A properly formatted html link to this node.
35    ///
36    inline std::string html_link(void) const
37    { return "<a href=\"" + output_name() + ".html\">" + name() + "</a>"; }
38
39    inline std::string html_tablerow(void) const
40    {
41      std::stringstream ss;
42      ss << "<tr><td>" << html_link() << "</td><td align=right>" << stats_.rows()
43         << "</td></tr>\n";
44      return ss.str();
45    }
46
47    inline const std::string& output_name(void) const { return output_name_; }
48
49    ///
50    /// @brief parsing file using svn blame.
51    ///
52    virtual const Stats& parse(const bool verbose=false)=0;
53
54    ///
55    /// Function printing HTML in current working directory
56    ///
57    virtual void print(const bool verbose=false) const=0;
58
59    ///
60    ///
61    ///
62    inline virtual void purge(const bool verbose=false) 
63    { /* Nothing to be done */ };
64
65    ///
66    /// Check if the node is under subversion control. This is done by
67    /// checking the return status of 'svn proplist <Node>.
68    ///
69    /// @return True if subversion controlled, false otherwise.
70    ///
71    bool subversion_controlled(void) const;
72
73  protected:
74    ///
75    /// Function returning everything after the last '/'
76    ///
77    /// @return name of node (not full path)
78    ///
79    std::string name(void) const;
80
81    ///
82    /// @brief print html footer of page
83    ///
84    void print_footer(std::ostream&) const;
85   
86    ///
87    /// @brief print html header of page
88    ///
89    void print_header(std::ostream&) const;
90
91    std::string output_name_; //without suffix
92    std::string path_;
93    Stats stats_;
94
95  private:
96    ///
97    /// @brief Copy Constructor, not implemented
98    ///
99    Node(const Node&);
100
101  };
102
103}} // end of namespace svnstat and namespace theplu
104
105#endif
Note: See TracBrowser for help on using the repository browser.