source: branches/replacing_gnuplot/lib/Node.h @ 845

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

Merged trunk changes -r782:844 to replacing_gnuplot branch.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.4 KB
Line 
1#ifndef _theplu_svndigest_node_
2#define _theplu_svndigest_node_
3
4// $Id: Node.h 845 2009-11-16 22:27:19Z jari $
5
6/*
7  Copyright (C) 2005, 2006, 2007 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2009 Peter Johansson
9
10  This file is part of svndigest, http://dev.thep.lu.se/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 3 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 svndigest. If not, see <http://www.gnu.org/licenses/>.
24*/
25
26#include "html_utility.h"
27#include "StatsCollection.h"
28#include "SVNinfo.h"
29#include "SVNlog.h"
30#include "utility.h"
31
32#include <map>
33#include <ostream>
34#include <stdexcept>
35#include <string>
36
37namespace theplu{
38namespace svndigest{
39
40  class Alias;
41
42  ///
43  /// If something goes wrong in the use of the Node or its derived
44  /// classes, a NodeException is thrown.
45  ///
46  struct NodeException : public std::runtime_error
47  { inline NodeException(const std::string& msg) : runtime_error(msg) {} };
48
49  ///
50  /// Abstract Base Class for files.
51  ///
52  class Node
53  {
54  public:
55
56    ///
57    /// @brief Constructor
58    ///
59    Node(const unsigned int, const std::string&, const std::string&);
60
61    ///
62    /// @brief Destructor
63    ///
64    virtual ~Node(void);
65
66    ///
67    /// @brief Get the author of the latest commit.
68    ///
69    std::string author(void) const;
70
71
72    /**
73       @brief Check whether node is binary.
74
75       @return True if node is binary.
76    */
77    inline bool binary(void) const { return binary_; }
78
79    ///
80    /// @return true if directory
81    ///
82    virtual bool dir(void) const;
83
84    ///
85    /// @return href to this node
86    ///
87    virtual std::string href(void) const=0;
88
89    void html_tablerow(std::ostream&, const std::string&, 
90                       const std::string& css, 
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    virtual svn_revnum_t last_changed_rev(void) const=0;
113
114    /**
115       @return log of this node in a recursive manner.
116    */
117    const SVNlog& log(void) const;
118
119    /**
120       @return The explicit string identifying the underlying derived
121       class.
122    */
123    virtual std::string node_type(void) const=0;
124
125    ///
126    /// @return
127    ///
128    inline const std::string& local_path(void) const { return local_path_; }
129
130    ///
131    /// Function returning everything after the last '/'
132    ///
133    /// @return name of node (not full path)
134    ///
135    std::string name(void) const;
136
137    /**
138       Note that returned string always end with '/' with the
139       exception when an empty string is returned.
140
141       @return output dir for example 'lib/' for this file
142     */
143    std::string output_dir(void) const;
144
145    /**
146       @return output path for example 'lib/Node.h.html' for this file
147     */
148    virtual std::string output_path(void) const=0;
149
150    ///
151    /// @brief parsing file using svn blame.
152    ///
153    virtual const StatsCollection& parse(bool verbose,
154                                         bool ignore_cache)=0;
155
156    ///
157    /// @todo doc
158    ///
159    inline const std::string& path(void) const { return path_; }
160
161    ///
162    /// Function printing HTML in current working directory
163    ///
164    void print(const bool verbose=false) const;
165
166    void print_author_summary(std::ostream&, 
167                              const Stats& stats, 
168                              const std::string& line_type, 
169                              const SVNlog&) const; 
170
171    /**
172       creates a map from year to last rev for that year and call
173       virtual function.
174     */
175    void print_copyright(std::map<std::string,Alias>&, bool) const;
176
177    /**
178       typically called from function above
179     */
180    virtual void print_copyright(std::map<std::string,Alias>&, bool,
181                                 const std::map<int,svn_revnum_t>&) const=0;
182
183    /**
184       @brief Check if item used to create this object has been
185       assigned property svndigest:ignore.
186
187       Currently files with property svndigest:ignore are to be
188       ignored by svndigest. It is the responsibility of the
189       statistics implementer to obey the ignore state.
190
191       @return True if item property svndigest:ignore was set.
192    */
193    inline bool svndigest_ignore(void) const { return svndigest_ignore_; }
194
195    /**
196       \see SVNinfo::url(void)
197    */
198    std::string url(void) const;
199   
200  protected:
201
202    ///
203    /// print path in html format (with anchors) to @a os
204    ///
205    void path_anchor(std::ostream& os) const; 
206
207    inline const SVNinfo& svn_info(void) const { return svninfo_; }
208
209    unsigned int level_;
210    std::string local_path_; // path from root
211    std::string output_dir_;
212    std::string path_; // absolute path
213    static std::string project_;
214    StatsCollection stats_;
215
216  private:
217    ///
218    /// @brief Copy Constructor, not implemented
219    ///
220    Node(const Node&);
221
222    virtual void log_core(SVNlog&) const=0;
223
224    virtual void print_core(bool verbose=false) const=0;
225
226    ///
227    /// print page for specific user (or all) and specific line_style
228    /// (or total).
229    ///
230    virtual void print_core(const std::string& stats_type,
231                            const std::string& user, 
232                            const std::string& line_type,
233                            const SVNlog&) const=0; 
234
235    bool binary_;
236    bool link_;
237    mutable SVNlog* log_;
238    bool svndigest_ignore_;
239    SVNinfo svninfo_;
240  };
241
242  /**
243     \brief Functor class to compare pointers of Nodes
244  */
245  struct NodePtrLess
246  {
247    /**
248       @return true if first and second are of same type (Directory or
249       File) and name of first is (alphabetically) less than name of
250       second; or if first is a Directory and second is a File.
251     */
252    inline bool operator()(const Node* first, const Node* second) const
253    {   
254      if (first->dir()==second->dir())
255        return first->name()<second->name();
256      return first->dir();
257    }
258  };
259
260}} // end of namespace svndigest and namespace theplu
261
262#endif
Note: See TracBrowser for help on using the repository browser.