1 | // $Id: Node.h 112 2006-06-29 09:30:54Z peter $ |
---|
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 | #include "utility.h" |
---|
29 | |
---|
30 | #include <ostream> |
---|
31 | #include <sstream> |
---|
32 | #include <stdexcept> |
---|
33 | #include <string> |
---|
34 | |
---|
35 | namespace theplu{ |
---|
36 | namespace svnstat{ |
---|
37 | |
---|
38 | /// |
---|
39 | /// If something goes wrong in the use of the Node or its derived |
---|
40 | /// classes, a NodeException is thrown. |
---|
41 | /// |
---|
42 | struct NodeException : public std::runtime_error |
---|
43 | { inline NodeException(const std::string& msg) : runtime_error(msg) {} }; |
---|
44 | |
---|
45 | /// |
---|
46 | /// Abstract Base Class for files. |
---|
47 | /// |
---|
48 | class Node |
---|
49 | { |
---|
50 | public: |
---|
51 | |
---|
52 | /// |
---|
53 | /// @brief Constructor |
---|
54 | /// |
---|
55 | Node(const u_int, const std::string&, const std::string&); |
---|
56 | |
---|
57 | /// |
---|
58 | /// @brief Destructor |
---|
59 | /// |
---|
60 | virtual inline ~Node(void) {}; |
---|
61 | |
---|
62 | /// |
---|
63 | /// |
---|
64 | /// |
---|
65 | virtual std::string author(void) const=0; |
---|
66 | |
---|
67 | /// |
---|
68 | /// @return true if directory |
---|
69 | /// |
---|
70 | virtual bool dir(void) const; |
---|
71 | |
---|
72 | /// |
---|
73 | /// @return A properly formatted html link to this node. |
---|
74 | /// |
---|
75 | virtual std::string html_link(void) const=0; |
---|
76 | |
---|
77 | /// |
---|
78 | /// |
---|
79 | /// |
---|
80 | std::string html_tablerow(const std::string&) const; |
---|
81 | |
---|
82 | /// |
---|
83 | /// |
---|
84 | /// |
---|
85 | virtual u_int last_changed_rev(void) const=0; |
---|
86 | |
---|
87 | /// |
---|
88 | /// @return |
---|
89 | /// |
---|
90 | inline const std::string& output_name(void) const { return output_name_; } |
---|
91 | |
---|
92 | /// |
---|
93 | /// @brief parsing file using svn blame. |
---|
94 | /// |
---|
95 | virtual const Stats& parse(const bool verbose=false)=0; |
---|
96 | |
---|
97 | inline const std::string& path(void) const { return path_; } |
---|
98 | |
---|
99 | /// |
---|
100 | /// Function printing HTML in current working directory |
---|
101 | /// |
---|
102 | virtual void print(const bool verbose=false) const=0; |
---|
103 | |
---|
104 | protected: |
---|
105 | |
---|
106 | /// |
---|
107 | /// Function returning everything after the last '/' |
---|
108 | /// |
---|
109 | /// @return name of node (not full path) |
---|
110 | /// |
---|
111 | inline std::string name(void) const { return file_name(path_); } |
---|
112 | |
---|
113 | /// |
---|
114 | /// @brief print html footer of page |
---|
115 | /// |
---|
116 | void print_footer(std::ostream&) const; |
---|
117 | |
---|
118 | /// |
---|
119 | /// @brief print html header of page |
---|
120 | /// |
---|
121 | void print_header(std::ostream&) const; |
---|
122 | |
---|
123 | u_int level_; |
---|
124 | std::string output_name_; //without suffix |
---|
125 | std::string path_; |
---|
126 | Stats stats_; |
---|
127 | |
---|
128 | private: |
---|
129 | /// |
---|
130 | /// @brief Copy Constructor, not implemented |
---|
131 | /// |
---|
132 | Node(const Node&); |
---|
133 | |
---|
134 | }; |
---|
135 | |
---|
136 | struct NodePtrLess |
---|
137 | { |
---|
138 | inline bool operator()(const Node* first, const Node* second) const |
---|
139 | { |
---|
140 | if (first->dir()==second->dir()) |
---|
141 | return first->output_name()<second->output_name(); |
---|
142 | return first->dir(); |
---|
143 | } |
---|
144 | }; |
---|
145 | |
---|
146 | }} // end of namespace svnstat and namespace theplu |
---|
147 | |
---|
148 | #endif |
---|