source: trunk/lib/Node.h @ 1017

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

updating copyright years

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