source: branches/visitor/lib/Node.h @ 1224

Last change on this file since 1224 was 1224, checked in by Peter Johansson, 12 years ago

refs #476. Functions in Node structure that interacts with visitors.

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