source: trunk/lib/Node.h @ 1236

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

Remove parse from Node interface as we now use visitor pattern and only need to rase with File and 'collect_stats()' with Directory. refs 476

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 7.0 KB
Line 
1#ifndef _theplu_svndigest_node_
2#define _theplu_svndigest_node_
3
4// $Id: Node.h 1236 2010-10-23 21:30:17Z 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       creates a map from year to last rev for that year and call
176       virtual function.
177     */
178    void print_copyright(std::map<std::string,Alias>&, bool) const;
179
180    /**
181       typically called from function above
182     */
183    virtual void print_copyright(std::map<std::string,Alias>&, bool,
184                                 const std::map<int,svn_revnum_t>&) const=0;
185
186    /**
187       \return true if svncopyright::ignore property was set
188     */
189    bool svncopyright_ignore(void) const;
190
191    /**
192       @brief Check if item used to create this object has been
193       assigned property svndigest:ignore.
194
195       Currently files with property svndigest:ignore are to be
196       ignored by svndigest. It is the responsibility of the
197       statistics implementer to obey the ignore state.
198
199       @return True if item property svndigest:ignore was set.
200    */
201    inline bool svndigest_ignore(void) const { return svndigest_ignore_; }
202
203    /**
204     */
205    const StatsCollection& stats(void) const;
206
207    StatsCollection& stats(void);
208
209    /**
210       Access point for a NodeVisitor to start traversing Node and its
211       daughter nodes.
212     */
213    virtual void traverse(NodeVisitor& visitor)=0;
214
215    /**
216       \see SVNinfo::url(void)
217    */
218    std::string url(void) const;
219   
220  protected:
221    ///
222    /// print path in html format (with anchors) to @a os
223    ///
224    void path_anchor(std::ostream& os) const; 
225
226    inline const SVNinfo& svn_info(void) const { return svninfo_; }
227
228    unsigned int level_;
229    std::string output_dir_;
230    std::string path_; // absolute path
231    static std::string project_;
232    StatsCollection stats_;
233    TinyStats tiny_stats_;
234
235  private:
236    ///
237    /// @brief Copy Constructor, not implemented
238    ///
239    Node(const Node&);
240
241    void html_tabletd(std::ostream&, const std::string& stats_type, 
242                      const std::string& user, 
243                      LineTypeParser::line_type lt) const;
244
245    virtual void log_core(SVNlog&) const=0;
246
247    virtual void print_core(bool verbose=false) const=0;
248
249    ///
250    /// print page for specific user (or all) and specific line_style
251    /// (or total).
252    ///
253    virtual void print_core(const std::string& stats_type,
254                            const std::string& user, 
255                            const std::string& line_type,
256                            const SVNlog&) const=0; 
257
258    bool binary_;
259    bool link_;
260    std::string local_path_; // path from root
261    mutable SVNlog* log_;
262    bool svndigest_ignore_;
263    bool svncopyright_ignore_;
264    SVNinfo svninfo_;
265  };
266
267  /**
268     \brief Functor class to compare pointers of Nodes
269  */
270  struct NodePtrLess
271  {
272    /**
273       @return true if first and second are of same type (Directory or
274       File) and name of first is (alphabetically) less than name of
275       second; or if first is a Directory and second is a File.
276     */
277    inline bool operator()(const Node* first, const Node* second) const
278    {   
279      if (first->dir()==second->dir())
280        return first->name()<second->name();
281      return first->dir();
282    }
283  };
284
285}} // end of namespace svndigest and namespace theplu
286
287#endif
Note: See TracBrowser for help on using the repository browser.