source: trunk/lib/Node.h @ 356

Last change on this file since 356 was 356, checked in by Peter Johansson, 14 years ago

fixes #203. Authors statistics link broken.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.8 KB
Line 
1#ifndef _theplu_svndigest_node_
2#define _theplu_svndigest_node_
3
4// $Id: Node.h 356 2007-05-25 16:59:46Z peter $
5
6/*
7  Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2007 Peter Johansson
9
10  This file is part of svndigest, http://lev.thep.lu.se/trac/svndigest
11
12  svndigest is free software; you can redistribute it and/or modify it
13  under the terms of the GNU General Public License as published by
14  the Free Software Foundation; either version 2 of the License, or
15  (at your option) any later version.
16
17  svndigest is distributed in the hope that it will be useful, but
18  WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  General Public License for more details.
21
22  You should have received a copy of the GNU General Public License
23  along with this program; if not, write to the Free Software
24  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25  02111-1307, USA.
26*/
27
28#include "html_utility.h"
29#include "Stats.h"
30#include "SVNinfo.h"
31#include "SVNlog.h"
32#include "utility.h"
33
34#include <map>
35#include <ostream>
36#include <stdexcept>
37#include <string>
38
39namespace theplu{
40namespace svndigest{
41
42  class Alias;
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 u_int, const std::string&, const std::string&);
62
63    ///
64    /// @brief Destructor
65    ///
66    virtual inline ~Node(void) {};
67
68    ///
69    /// @brief Get the author of the latest commit.
70    ///
71    inline const std::string& author(void) const
72    { return svninfo_.last_changed_author(); }
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& 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 { return binary_ || svndigest_ignore_; }
108
109    ///
110    /// @brief Get the revision number of the latest commit.
111    ///
112    inline svn_revnum_t last_changed_rev(void) const
113    { return svninfo_.last_changed_rev(); }
114
115    ///
116    /// @return file or directory
117    ///
118    virtual std::string node_type(void) const=0;
119
120    ///
121    /// @return
122    ///
123    inline const std::string& local_path(void) const { return local_path_; }
124
125    ///
126    /// Function returning everything after the last '/'
127    ///
128    /// @return name of node (not full path)
129    ///
130    inline std::string name(void) const { return file_name(path_); }
131
132    /**
133       Note that returned string always end with '/' with the
134       exception when an empty string is returned.
135
136       @return output dir for example 'lib' for this file
137     */
138    std::string output_dir(void) const;
139
140    /**
141       @return output path for example 'lib/Node.h.html' for this file
142     */
143    virtual std::string output_path(void) const=0;
144
145    ///
146    /// @brief parsing file using svn blame.
147    ///
148    virtual const Stats& parse(const bool verbose=false)=0;
149
150    ///
151    /// @todo doc
152    ///
153    inline const std::string& path(void) const { return path_; }
154
155    ///
156    /// Function printing HTML in current working directory
157    ///
158    void print(const bool verbose=false) const;
159
160    void print_author_summary(std::ostream&, std::string, const SVNlog&) const; 
161
162    virtual void print_copyright(std::map<std::string,Alias>& ) const=0;
163
164    /**
165       @brief Check if item used to create this object has been
166       assigned property svndigest:ignore.
167
168       Currently files with property svndigest:ignore are to be
169       ignored by svndigest. It is the responsibility of the
170       statistics implementer to obey the ignore state.
171
172       @return True if item property svndigest:ignore was set.
173    */
174    inline bool svndigest_ignore(void) const { return svndigest_ignore_; }
175
176    /**
177       \see SVNinfo::url(void)
178    */
179    std::string url(void) const;
180   
181  protected:
182
183    ///
184    /// print path in html format (with anchors) to @a os
185    ///
186    void path_anchor(std::ostream& os) const; 
187
188    u_int level_;
189    std::string local_path_; // path from root
190    std::string output_dir_;
191    std::string path_; // absolute path
192    static std::string project_;
193    Stats stats_;
194
195  private:
196    ///
197    /// @brief Copy Constructor, not implemented
198    ///
199    Node(const Node&);
200
201    virtual void print_core(bool verbose=false) const=0;
202
203    ///
204    /// print page for specific user (or all) and specific line_style
205    /// (or total).
206    ///
207    virtual void print_core(const std::string& user, 
208                            const std::string& line_type,
209                            const SVNlog&) const=0; 
210
211    bool binary_;
212    bool svndigest_ignore_;
213    SVNinfo svninfo_;
214  };
215
216  /**
217     \brief Functor class to compare pointers of Nodes
218  */
219  struct NodePtrLess
220  {
221    /**
222       @return true if first and second are of same type (Directory or
223       File) and name of first is (alphabetically) less than name of
224       second; or if first is a Directory and second is a File.
225     */
226    inline bool operator()(const Node* first, const Node* second) const
227    {   
228      if (first->dir()==second->dir())
229        return first->name()<second->name();
230      return first->dir();
231    }
232  };
233
234}} // end of namespace svndigest and namespace theplu
235
236#endif
Note: See TracBrowser for help on using the repository browser.