source: trunk/lib/Node.h @ 343

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

refs #169

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.7 KB
Line 
1#ifndef _theplu_svndigest_node_
2#define _theplu_svndigest_node_
3
4// $Id: Node.h 343 2007-05-19 13:58:19Z 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       @return output dir for example 'lib' for this file
134     */
135    std::string output_dir(void) const;
136
137    /**
138       @return output path for example 'lib/File.h.html' for this file
139     */
140    virtual std::string output_path(void) const=0;
141
142    ///
143    /// @brief parsing file using svn blame.
144    ///
145    virtual const Stats& parse(const bool verbose=false)=0;
146
147    ///
148    /// @todo doc
149    ///
150    inline const std::string& path(void) const { return path_; }
151
152    ///
153    /// Function printing HTML in current working directory
154    ///
155    void print(const bool verbose=false) const;
156
157    void print_author_summary(std::ostream&, std::string, const SVNlog&) const; 
158
159    virtual void print_copyright(std::map<std::string,Alias>& ) const=0;
160
161    /**
162       @brief Check if item used to create this object has been
163       assigned property svndigest:ignore.
164
165       Currently files with property svndigest:ignore are to be
166       ignored by svndigest. It is the responsibility of the
167       statistics implementer to obey the ignore state.
168
169       @return True if item property svndigest:ignore was set.
170    */
171    inline bool svndigest_ignore(void) const { return svndigest_ignore_; }
172
173    /**
174       \see SVNinfo::url(void)
175    */
176    std::string url(void) const;
177   
178  protected:
179
180    ///
181    /// print path in html format (with anchors) to @a os
182    ///
183    void path_anchor(std::ostream& os) const; 
184
185    u_int level_;
186    std::string local_path_; // path from root
187    std::string output_dir_;
188    std::string path_; // absolute path
189    static std::string project_;
190    Stats stats_;
191
192  private:
193    ///
194    /// @brief Copy Constructor, not implemented
195    ///
196    Node(const Node&);
197
198    virtual void print_core(bool verbose=false) const=0;
199
200    ///
201    /// print page for specific user (or all) and specific line_style
202    /// (or total).
203    ///
204    virtual void print_core(const std::string& user, 
205                            const std::string& line_type,
206                            const SVNlog&) const=0; 
207
208    bool binary_;
209    bool svndigest_ignore_;
210    SVNinfo svninfo_;
211  };
212
213  /**
214     \brief Functor class to compare pointers of Nodes
215  */
216  struct NodePtrLess
217  {
218    /**
219       @return true if first and second are of same type (Directory or
220       File) and name of first is (alphabetically) less than name of
221       second; or if first is a Directory and second is a File.
222     */
223    inline bool operator()(const Node* first, const Node* second) const
224    {   
225      if (first->dir()==second->dir())
226        return first->name()<second->name();
227      return first->dir();
228    }
229  };
230
231}} // end of namespace svndigest and namespace theplu
232
233#endif
Note: See TracBrowser for help on using the repository browser.