source: trunk/lib/Node.h @ 330

Last change on this file since 330 was 330, checked in by Peter Johansson, 14 years ago

Using internal SVNinfo in tree rather than creating a new object.
Also added some docs.

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