source: trunk/lib/Node.h @ 389

Last change on this file since 389 was 380, checked in by Jari Häkkinen, 14 years ago

Addresses #62. First blame output with lines.

  • 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 380 2007-06-21 19:25:39Z jari $
5
6/*
7  Copyright (C) 2005, 2006, 2007 Jari Häkkinen, Peter Johansson
8
9  This file is part of svndigest, http://lev.thep.lu.se/trac/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 2 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 this program; if not, write to the Free Software
23  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24  02111-1307, USA.
25*/
26
27#include "html_utility.h"
28#include "Stats.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 u_int, const std::string&, const std::string&);
61
62    ///
63    /// @brief Destructor
64    ///
65    virtual inline ~Node(void) {};
66
67    ///
68    /// @brief Get the author of the latest commit.
69    ///
70    inline const std::string& author(void) const
71    { return svninfo_.last_changed_author(); }
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& user) const;
92
93    /**
94       @brief Check whether node should be ignored in statistics.
95
96       If a node is to be ignored the statistics implementer should
97       respect this state. Currently binary files and items with
98       property svndigest:ignore are to be ignored by svndigest. If
99       the node is a directory then the direcotry and its siblings
100       should be ignored by statistics.
101
102       @return True of node should be ignored by statistics.
103
104       @see SVNproperty::svndigest_ingorable
105    */
106    inline bool ignore(void) const 
107    { return binary_ || svndigest_ignore_ || link_; }
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 The explicit string identifying the underlying derived
117       class.
118    */
119    virtual std::string node_type(void) const=0;
120
121    ///
122    /// @return
123    ///
124    inline const std::string& local_path(void) const { return local_path_; }
125
126    ///
127    /// Function returning everything after the last '/'
128    ///
129    /// @return name of node (not full path)
130    ///
131    inline std::string name(void) const { return file_name(path_); }
132
133    /**
134       Note that returned string always end with '/' with the
135       exception when an empty string is returned.
136
137       @return output dir for example 'lib' for this file
138     */
139    std::string output_dir(void) const;
140
141    /**
142       @return output path for example 'lib/Node.h.html' for this file
143     */
144    virtual std::string output_path(void) const=0;
145
146    ///
147    /// @brief parsing file using svn blame.
148    ///
149    virtual const Stats& parse(const bool verbose=false)=0;
150
151    ///
152    /// @todo doc
153    ///
154    inline const std::string& path(void) const { return path_; }
155
156    ///
157    /// Function printing HTML in current working directory
158    ///
159    void print(const bool verbose=false) const;
160
161    void print_author_summary(std::ostream&, std::string, const SVNlog&) const; 
162
163    virtual void print_copyright(std::map<std::string,Alias>& ) const=0;
164
165    /**
166       @brief Check if item used to create this object has been
167       assigned property svndigest:ignore.
168
169       Currently files with property svndigest:ignore are to be
170       ignored by svndigest. It is the responsibility of the
171       statistics implementer to obey the ignore state.
172
173       @return True if item property svndigest:ignore was set.
174    */
175    inline bool svndigest_ignore(void) const { return svndigest_ignore_; }
176
177    /**
178       \see SVNinfo::url(void)
179    */
180    std::string url(void) const;
181   
182  protected:
183
184    ///
185    /// print path in html format (with anchors) to @a os
186    ///
187    void path_anchor(std::ostream& os) const; 
188
189    u_int level_;
190    std::string local_path_; // path from root
191    std::string output_dir_;
192    std::string path_; // absolute path
193    static std::string project_;
194    Stats stats_;
195
196  private:
197    ///
198    /// @brief Copy Constructor, not implemented
199    ///
200    Node(const Node&);
201
202    virtual void print_core(bool verbose=false) const=0;
203
204    ///
205    /// print page for specific user (or all) and specific line_style
206    /// (or total).
207    ///
208    virtual void print_core(const std::string& user, 
209                            const std::string& line_type,
210                            const SVNlog&) const=0; 
211
212    bool binary_;
213    bool link_;
214    bool svndigest_ignore_;
215    SVNinfo svninfo_;
216  };
217
218  /**
219     \brief Functor class to compare pointers of Nodes
220  */
221  struct NodePtrLess
222  {
223    /**
224       @return true if first and second are of same type (Directory or
225       File) and name of first is (alphabetically) less than name of
226       second; or if first is a Directory and second is a File.
227     */
228    inline bool operator()(const Node* first, const Node* second) const
229    {   
230      if (first->dir()==second->dir())
231        return first->name()<second->name();
232      return first->dir();
233    }
234  };
235
236}} // end of namespace svndigest and namespace theplu
237
238#endif
Note: See TracBrowser for help on using the repository browser.