source: tags/0.6.8/lib/Node.h @ 848

Last change on this file since 848 was 731, checked in by Peter Johansson, 13 years ago

update copyright statements

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.9 KB
Line 
1#ifndef _theplu_svndigest_node_
2#define _theplu_svndigest_node_
3
4// $Id: Node.h 731 2008-12-15 19:03:04Z peter $
5
6/*
7  Copyright (C) 2005, 2006, 2007 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2008 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 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 
108    { return binary_ || svndigest_ignore_ || link_; }
109
110    ///
111    /// @brief Get the revision number of the latest commit.
112    ///
113    inline svn_revnum_t last_changed_rev(void) const
114    { return svninfo_.last_changed_rev(); }
115
116    /**
117       @return The explicit string identifying the underlying derived
118       class.
119    */
120    virtual std::string node_type(void) const=0;
121
122    ///
123    /// @return
124    ///
125    inline const std::string& local_path(void) const { return local_path_; }
126
127    ///
128    /// Function returning everything after the last '/'
129    ///
130    /// @return name of node (not full path)
131    ///
132    inline std::string name(void) const { return file_name(path_); }
133
134    /**
135       Note that returned string always end with '/' with the
136       exception when an empty string is returned.
137
138       @return output dir for example 'lib' for this file
139     */
140    std::string output_dir(void) const;
141
142    /**
143       @return output path for example 'lib/Node.h.html' for this file
144     */
145    virtual std::string output_path(void) const=0;
146
147    ///
148    /// @brief parsing file using svn blame.
149    ///
150    virtual const Stats& parse(const bool verbose=false)=0;
151
152    ///
153    /// @todo doc
154    ///
155    inline const std::string& path(void) const { return path_; }
156
157    ///
158    /// Function printing HTML in current working directory
159    ///
160    void print(const bool verbose=false) const;
161
162    void print_author_summary(std::ostream&, std::string, const SVNlog&) const; 
163
164    virtual void print_copyright(std::map<std::string,Alias>& ) const=0;
165
166    /**
167       @brief Check if item used to create this object has been
168       assigned property svndigest:ignore.
169
170       Currently files with property svndigest:ignore are to be
171       ignored by svndigest. It is the responsibility of the
172       statistics implementer to obey the ignore state.
173
174       @return True if item property svndigest:ignore was set.
175    */
176    inline bool svndigest_ignore(void) const { return svndigest_ignore_; }
177
178    /**
179       \see SVNinfo::url(void)
180    */
181    std::string url(void) const;
182   
183  protected:
184
185    ///
186    /// print path in html format (with anchors) to @a os
187    ///
188    void path_anchor(std::ostream& os) const; 
189
190    u_int level_;
191    std::string local_path_; // path from root
192    std::string output_dir_;
193    std::string path_; // absolute path
194    static std::string project_;
195    Stats stats_;
196
197  private:
198    ///
199    /// @brief Copy Constructor, not implemented
200    ///
201    Node(const Node&);
202
203    virtual void print_core(bool verbose=false) const=0;
204
205    ///
206    /// print page for specific user (or all) and specific line_style
207    /// (or total).
208    ///
209    virtual void print_core(const std::string& user, 
210                            const std::string& line_type,
211                            const SVNlog&) const=0; 
212
213    bool binary_;
214    bool link_;
215    bool svndigest_ignore_;
216    SVNinfo svninfo_;
217  };
218
219  /**
220     \brief Functor class to compare pointers of Nodes
221  */
222  struct NodePtrLess
223  {
224    /**
225       @return true if first and second are of same type (Directory or
226       File) and name of first is (alphabetically) less than name of
227       second; or if first is a Directory and second is a File.
228     */
229    inline bool operator()(const Node* first, const Node* second) const
230    {   
231      if (first->dir()==second->dir())
232        return first->name()<second->name();
233      return first->dir();
234    }
235  };
236
237}} // end of namespace svndigest and namespace theplu
238
239#endif
Note: See TracBrowser for help on using the repository browser.