source: trunk/lib/Node.h @ 1264

Last change on this file since 1264 was 1264, checked in by Peter Johansson, 11 years ago

merge release 0.8.1 into trunk. Delta 0.8.1 - 0.8

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