source: trunk/lib/Node.h @ 1234

Last change on this file since 1234 was 1234, checked in by Peter Johansson, 11 years ago

refs #476. Merged visitor branch into trunk. Used 'svn merge /branches/visitor' because --reintegrate did (currently) not work on our repo. Since I could not merge as suggested in subversion manual, I reverted all mergeinfo properties to avoid future confusion by svn-client. This means (I think) that there will be no connection about this commit and the visitor branch, but to svn-client this will look like a large changeset (just like a merge in the old days).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 7.1 KB
Line 
1#ifndef _theplu_svndigest_node_
2#define _theplu_svndigest_node_
3
4// $Id: Node.h 1234 2010-10-23 16:41:33Z 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
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 "html_utility.h"
28#include "LineTypeParser.h"
29#include "StatsCollection.h"
30#include "SVNinfo.h"
31#include "SVNlog.h"
32#include "TinyStats.h"
33#include "utility.h"
34
35#include <map>
36#include <ostream>
37#include <stdexcept>
38#include <string>
39
40namespace theplu{
41namespace svndigest{
42
43  class Alias;
44  class NodeVisitor;
45
46  ///
47  /// If something goes wrong in the use of the Node or its derived
48  /// classes, a NodeException is thrown.
49  ///
50  struct NodeException : public std::runtime_error
51  { inline NodeException(const std::string& msg) : runtime_error(msg) {} };
52
53  ///
54  /// Abstract Base Class for files.
55  ///
56  class Node
57  {
58  public:
59
60    ///
61    /// @brief Constructor
62    ///
63    Node(const unsigned int, const std::string&, const std::string&);
64
65    ///
66    /// @brief Destructor
67    ///
68    virtual ~Node(void);
69
70    ///
71    /// @brief Get the author of the latest commit.
72    ///
73    std::string author(void) const;
74
75
76    /**
77       @brief Check whether node is binary.
78
79       @return True if node is binary.
80    */
81    inline bool binary(void) const { return binary_; }
82
83    ///
84    /// @return true if directory
85    ///
86    virtual bool dir(void) const;
87
88    ///
89    /// @return href to this node
90    ///
91    virtual std::string href(void) const=0;
92
93    void html_tablerow(std::ostream&, const std::string&, 
94                       const std::string& css, 
95                       const std::string& user) const;
96
97    /**
98       @brief Check whether node should be ignored in statistics.
99
100       If a node is to be ignored the statistics implementer should
101       respect this state. Currently binary files and items with
102       property svndigest:ignore are to be ignored by svndigest. If
103       the node is a directory then the direcotry and its siblings
104       should be ignored by statistics.
105
106       @return True of node should be ignored by statistics.
107
108       @see SVNproperty::svndigest_ingorable
109    */
110    inline bool ignore(void) const 
111    { return binary_ || svndigest_ignore_ || link_; }
112
113    /**
114       Create the TinyStats based on the stored CollectionStats
115     */
116    void init_tiny_stats(void);
117
118    ///
119    /// @brief Get the revision number of the latest commit.
120    ///
121    virtual svn_revnum_t last_changed_rev(void) const=0;
122
123    /**
124       @return log of this node in a recursive manner.
125    */
126    const SVNlog& log(void) const;
127
128    /**
129       @return The explicit string identifying the underlying derived
130       class.
131    */
132    virtual std::string node_type(void) const=0;
133
134    ///
135    /// @return
136    ///
137    inline const std::string& local_path(void) const { return local_path_; }
138
139    ///
140    /// Function returning everything after the last '/'
141    ///
142    /// @return name of node (not full path)
143    ///
144    std::string name(void) const;
145
146    /**
147       Note that returned string always end with '/' with the
148       exception when an empty string is returned.
149
150       @return output dir for example 'lib/' for this file
151     */
152    std::string output_dir(void) const;
153
154    /**
155       @return output path for example 'lib/Node.h.html' for this file
156     */
157    virtual std::string output_path(void) const=0;
158
159    ///
160    /// @brief parsing file using svn blame.
161    ///
162    virtual const StatsCollection& parse(bool verbose,
163                                         bool ignore_cache)=0;
164
165    ///
166    /// @todo doc
167    ///
168    inline const std::string& path(void) const { return path_; }
169
170    ///
171    /// Function printing HTML in current working directory
172    ///
173    void print(const bool verbose=false) const;
174
175    void print_author_summary(std::ostream&, 
176                              const Stats& stats, 
177                              const std::string& line_type, 
178                              const SVNlog&) const; 
179
180    /**
181       creates a map from year to last rev for that year and call
182       virtual function.
183     */
184    void print_copyright(std::map<std::string,Alias>&, bool) const;
185
186    /**
187       typically called from function above
188     */
189    virtual void print_copyright(std::map<std::string,Alias>&, bool,
190                                 const std::map<int,svn_revnum_t>&) const=0;
191
192    /**
193       \return true if svncopyright::ignore property was set
194     */
195    bool svncopyright_ignore(void) const;
196
197    /**
198       @brief Check if item used to create this object has been
199       assigned property svndigest:ignore.
200
201       Currently files with property svndigest:ignore are to be
202       ignored by svndigest. It is the responsibility of the
203       statistics implementer to obey the ignore state.
204
205       @return True if item property svndigest:ignore was set.
206    */
207    inline bool svndigest_ignore(void) const { return svndigest_ignore_; }
208
209    /**
210     */
211    const StatsCollection& stats(void) const;
212
213    StatsCollection& stats(void);
214
215    /**
216       Access point for a NodeVisitor to start traversing Node and its
217       daughter nodes.
218     */
219    virtual void traverse(NodeVisitor& visitor)=0;
220
221    /**
222       \see SVNinfo::url(void)
223    */
224    std::string url(void) const;
225   
226  protected:
227    ///
228    /// print path in html format (with anchors) to @a os
229    ///
230    void path_anchor(std::ostream& os) const; 
231
232    inline const SVNinfo& svn_info(void) const { return svninfo_; }
233
234    unsigned int level_;
235    std::string output_dir_;
236    std::string path_; // absolute path
237    static std::string project_;
238    StatsCollection stats_;
239    TinyStats tiny_stats_;
240
241  private:
242    ///
243    /// @brief Copy Constructor, not implemented
244    ///
245    Node(const Node&);
246
247    void html_tabletd(std::ostream&, const std::string& stats_type, 
248                      const std::string& user, 
249                      LineTypeParser::line_type lt) const;
250
251    virtual void log_core(SVNlog&) const=0;
252
253    virtual void print_core(bool verbose=false) const=0;
254
255    ///
256    /// print page for specific user (or all) and specific line_style
257    /// (or total).
258    ///
259    virtual void print_core(const std::string& stats_type,
260                            const std::string& user, 
261                            const std::string& line_type,
262                            const SVNlog&) const=0; 
263
264    bool binary_;
265    bool link_;
266    std::string local_path_; // path from root
267    mutable SVNlog* log_;
268    bool svndigest_ignore_;
269    bool svncopyright_ignore_;
270    SVNinfo svninfo_;
271  };
272
273  /**
274     \brief Functor class to compare pointers of Nodes
275  */
276  struct NodePtrLess
277  {
278    /**
279       @return true if first and second are of same type (Directory or
280       File) and name of first is (alphabetically) less than name of
281       second; or if first is a Directory and second is a File.
282     */
283    inline bool operator()(const Node* first, const Node* second) const
284    {   
285      if (first->dir()==second->dir())
286        return first->name()<second->name();
287      return first->dir();
288    }
289  };
290
291}} // end of namespace svndigest and namespace theplu
292
293#endif
Note: See TracBrowser for help on using the repository browser.