source: trunk/lib/Node.h @ 745

Last change on this file since 745 was 693, checked in by Jari Häkkinen, 13 years ago

Fixes #339. Change to GPLv3.

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