source: trunk/lib/Node.h @ 1238

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

remove print_copyright from Node interface since we use traverse to traverse node tree and only need to update copyright on File

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