1 | #ifndef _theplu_svndigest_node_ |
---|
2 | #define _theplu_svndigest_node_ |
---|
3 | |
---|
4 | // $Id: Node.h 1321 2010-11-28 23:41:31Z peter $ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) 2005, 2006, 2007, 2008 Jari Häkkinen, Peter Johansson |
---|
8 | Copyright (C) 2009 Peter Johansson |
---|
9 | Copyright (C) 2010 Jari Häkkinen, Peter Johansson |
---|
10 | |
---|
11 | This file is part of svndigest, http://dev.thep.lu.se/svndigest |
---|
12 | |
---|
13 | svndigest is free software; you can redistribute it and/or modify it |
---|
14 | under the terms of the GNU General Public License as published by |
---|
15 | the Free Software Foundation; either version 3 of the License, or |
---|
16 | (at your option) any later version. |
---|
17 | |
---|
18 | svndigest is distributed in the hope that it will be useful, but |
---|
19 | WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
21 | General Public License for more details. |
---|
22 | |
---|
23 | You should have received a copy of the GNU General Public License |
---|
24 | along with svndigest. If not, see <http://www.gnu.org/licenses/>. |
---|
25 | */ |
---|
26 | |
---|
27 | #include "LineTypeParser.h" |
---|
28 | #include "StatsCollection.h" |
---|
29 | #include "SVNinfo.h" |
---|
30 | #include "SVNlog.h" |
---|
31 | #include "TinyStats.h" |
---|
32 | |
---|
33 | #include <map> |
---|
34 | #include <ostream> |
---|
35 | #include <stdexcept> |
---|
36 | #include <string> |
---|
37 | |
---|
38 | namespace theplu{ |
---|
39 | namespace svndigest{ |
---|
40 | |
---|
41 | class Alias; |
---|
42 | class NodeVisitor; |
---|
43 | |
---|
44 | /// |
---|
45 | /// If something goes wrong in the use of the Node or its derived |
---|
46 | /// classes, a NodeException is thrown. |
---|
47 | /// |
---|
48 | struct NodeException : public std::runtime_error |
---|
49 | { inline NodeException(const std::string& msg) : runtime_error(msg) {} }; |
---|
50 | |
---|
51 | /// |
---|
52 | /// Abstract Base Class for files. |
---|
53 | /// |
---|
54 | class Node |
---|
55 | { |
---|
56 | public: |
---|
57 | |
---|
58 | /// |
---|
59 | /// @brief Constructor |
---|
60 | /// |
---|
61 | Node(const unsigned int, const std::string&, const std::string&, |
---|
62 | const std::string& = ""); |
---|
63 | |
---|
64 | /// |
---|
65 | /// @brief Destructor |
---|
66 | /// |
---|
67 | virtual ~Node(void); |
---|
68 | |
---|
69 | /// |
---|
70 | /// @brief Get the author of the latest commit. |
---|
71 | /// |
---|
72 | std::string author(void) const; |
---|
73 | |
---|
74 | |
---|
75 | /** |
---|
76 | @brief Check whether node is binary. |
---|
77 | |
---|
78 | @return True if node is binary. |
---|
79 | */ |
---|
80 | inline bool binary(void) const { return binary_; } |
---|
81 | |
---|
82 | /// |
---|
83 | /// @return true if directory |
---|
84 | /// |
---|
85 | virtual bool dir(void) const; |
---|
86 | |
---|
87 | /// |
---|
88 | /// @return href to this node |
---|
89 | /// |
---|
90 | virtual std::string href(void) const=0; |
---|
91 | |
---|
92 | /** |
---|
93 | */ |
---|
94 | void html_tablerow(std::ostream& os, |
---|
95 | const std::string& stats_type, |
---|
96 | const std::string& css_class, |
---|
97 | const std::string& user) const; |
---|
98 | |
---|
99 | /** |
---|
100 | @brief Check whether node should be ignored in statistics. |
---|
101 | |
---|
102 | If a node is to be ignored the statistics implementer should |
---|
103 | respect this state. Currently binary files and items with |
---|
104 | property svndigest:ignore are to be ignored by svndigest. If |
---|
105 | the node is a directory then the direcotry and its siblings |
---|
106 | should be ignored by statistics. |
---|
107 | |
---|
108 | @return True of node should be ignored by statistics. |
---|
109 | |
---|
110 | @see SVNproperty::svndigest_ingorable |
---|
111 | */ |
---|
112 | inline bool ignore(void) const |
---|
113 | { return binary_ || svndigest_ignore_ || link_; } |
---|
114 | |
---|
115 | /** |
---|
116 | Create the TinyStats based on the stored CollectionStats |
---|
117 | */ |
---|
118 | void init_tiny_stats(void); |
---|
119 | |
---|
120 | /// |
---|
121 | /// @brief Get the revision number of the latest commit. |
---|
122 | /// |
---|
123 | virtual svn_revnum_t last_changed_rev(void) const=0; |
---|
124 | |
---|
125 | /** |
---|
126 | @return log of this node in a recursive manner. |
---|
127 | */ |
---|
128 | const SVNlog& log(void) const; |
---|
129 | |
---|
130 | /// |
---|
131 | /// @return |
---|
132 | /// |
---|
133 | inline const std::string& local_path(void) const { return local_path_; } |
---|
134 | |
---|
135 | /// |
---|
136 | /// Function returning everything after the last '/' |
---|
137 | /// |
---|
138 | /// @return name of node (not full path) |
---|
139 | /// |
---|
140 | std::string name(void) const; |
---|
141 | |
---|
142 | /** |
---|
143 | @return The explicit string identifying the underlying derived |
---|
144 | class. |
---|
145 | */ |
---|
146 | virtual std::string node_type(void) const=0; |
---|
147 | |
---|
148 | /// |
---|
149 | /// @todo doc |
---|
150 | /// |
---|
151 | inline const std::string& path(void) const { return path_; } |
---|
152 | |
---|
153 | /** |
---|
154 | \return true if svncopyright::ignore property was set |
---|
155 | */ |
---|
156 | bool svncopyright_ignore(void) const; |
---|
157 | |
---|
158 | /** |
---|
159 | @brief Check if item used to create this object has been |
---|
160 | assigned property svndigest:ignore. |
---|
161 | |
---|
162 | Currently files with property svndigest:ignore are to be |
---|
163 | ignored by svndigest. It is the responsibility of the |
---|
164 | statistics implementer to obey the ignore state. |
---|
165 | |
---|
166 | @return True if item property svndigest:ignore was set. |
---|
167 | */ |
---|
168 | inline bool svndigest_ignore(void) const { return svndigest_ignore_; } |
---|
169 | |
---|
170 | /** |
---|
171 | */ |
---|
172 | const StatsCollection& stats(void) const; |
---|
173 | |
---|
174 | /** |
---|
175 | */ |
---|
176 | StatsCollection& stats(void); |
---|
177 | |
---|
178 | /** |
---|
179 | Access point for a NodeVisitor to start traversing Node and its |
---|
180 | daughter nodes. |
---|
181 | */ |
---|
182 | virtual void traverse(NodeVisitor& visitor)=0; |
---|
183 | |
---|
184 | /** |
---|
185 | */ |
---|
186 | inline const SVNinfo& svn_info(void) const { return svninfo_; } |
---|
187 | |
---|
188 | /** |
---|
189 | */ |
---|
190 | const TinyStats& tiny_stats(void) const { return tiny_stats_; } |
---|
191 | |
---|
192 | protected: |
---|
193 | unsigned int level_; |
---|
194 | std::string output_dir_; |
---|
195 | std::string path_; // absolute path |
---|
196 | static std::string project_; |
---|
197 | StatsCollection stats_; |
---|
198 | TinyStats tiny_stats_; |
---|
199 | |
---|
200 | private: |
---|
201 | /// |
---|
202 | /// @brief Copy Constructor, not implemented |
---|
203 | /// |
---|
204 | Node(const Node&); |
---|
205 | |
---|
206 | /** |
---|
207 | */ |
---|
208 | void html_tabletd(std::ostream&, |
---|
209 | const std::string& stats_type, |
---|
210 | const std::string& user, |
---|
211 | LineTypeParser::line_type lt) const; |
---|
212 | |
---|
213 | virtual void log_core(SVNlog&) const=0; |
---|
214 | |
---|
215 | bool binary_; |
---|
216 | bool link_; |
---|
217 | std::string local_path_; // path from root |
---|
218 | mutable SVNlog* log_; |
---|
219 | bool svndigest_ignore_; |
---|
220 | bool svncopyright_ignore_; |
---|
221 | SVNinfo svninfo_; |
---|
222 | |
---|
223 | friend class FilePrinter; |
---|
224 | friend class DirectoryPrinter; |
---|
225 | friend class NodePrinter; |
---|
226 | }; |
---|
227 | |
---|
228 | /** |
---|
229 | \brief Functor class to compare pointers of Nodes |
---|
230 | */ |
---|
231 | struct NodePtrLess |
---|
232 | { |
---|
233 | /** |
---|
234 | @return true if first and second are of same type (Directory or |
---|
235 | File) and name of first is (alphabetically) less than name of |
---|
236 | second; or if first is a Directory and second is a File. |
---|
237 | */ |
---|
238 | inline bool operator()(const Node* first, const Node* second) const |
---|
239 | { |
---|
240 | if (first->dir()==second->dir()) |
---|
241 | return first->name()<second->name(); |
---|
242 | return first->dir(); |
---|
243 | } |
---|
244 | }; |
---|
245 | |
---|
246 | }} // end of namespace svndigest and namespace theplu |
---|
247 | |
---|
248 | #endif |
---|