source: trunk/lib/Node.h @ 1356

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

Let Node hold an SVNproperty rather than copy (virtually) all its members

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.7 KB
Line 
1#ifndef _theplu_svndigest_node_
2#define _theplu_svndigest_node_
3
4// $Id: Node.h 1356 2011-05-17 23:59:27Z 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, Peter Johansson
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 "LineTypeParser.h"
28#include "StatsCollection.h"
29#include "SVNinfo.h"
30#include "SVNlog.h"
31#include "SVNproperty.h"
32#include "TinyStats.h"
33
34#include <map>
35#include <ostream>
36#include <stdexcept>
37#include <string>
38
39namespace theplu{
40namespace svndigest{
41
42  class Alias;
43  class NodeVisitor;
44
45  ///
46  /// If something goes wrong in the use of the Node or its derived
47  /// classes, a NodeException is thrown.
48  ///
49  struct NodeException : public std::runtime_error
50  { inline NodeException(const std::string& msg) : runtime_error(msg) {} };
51
52  ///
53  /// Abstract Base Class for files.
54  ///
55  class Node
56  {
57  public:
58
59    ///
60    /// @brief Constructor
61    ///
62    Node(const unsigned int, const std::string&, const std::string&, 
63         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    bool binary(void) const;
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    /**
94     */
95    void html_tablerow(std::ostream& os, 
96                       const std::string& stats_type,
97                       const std::string& css_class,
98                       const std::string& user) const;
99
100    /**
101       @brief Check whether node should be ignored in statistics.
102
103       If a node is to be ignored the statistics implementer should
104       respect this state. Currently binary files and items with
105       property svndigest:ignore are to be ignored by svndigest. If
106       the node is a directory then the direcotry and its siblings
107       should be ignored by statistics.
108
109       @return True of node should be ignored by statistics.
110
111       @see SVNproperty::svndigest_ingorable
112    */
113    inline bool ignore(void) const 
114    { return binary() || svndigest_ignore() || link_; }
115
116    /**
117       Create the TinyStats based on the stored CollectionStats
118     */
119    void init_tiny_stats(void);
120
121    ///
122    /// @brief Get the revision number of the latest commit.
123    ///
124    virtual svn_revnum_t last_changed_rev(void) const=0;
125
126    /**
127       @return log of this node in a recursive manner.
128    */
129    const SVNlog& log(void) const;
130
131    ///
132    /// @return
133    ///
134    inline const std::string& local_path(void) const { return local_path_; }
135
136    ///
137    /// Function returning everything after the last '/'
138    ///
139    /// @return name of node (not full path)
140    ///
141    std::string name(void) const;
142
143    /**
144       @return The explicit string identifying the underlying derived
145       class.
146    */
147    virtual std::string node_type(void) const=0;
148
149    ///
150    /// @todo doc
151    ///
152    inline const std::string& path(void) const { return path_; }
153
154    /**
155       \return true if svncopyright::ignore property was set
156     */
157    bool svncopyright_ignore(void) const;
158
159    /**
160       @brief Check if item used to create this object has been
161       assigned property svndigest:ignore.
162
163       Currently files with property svndigest:ignore are to be
164       ignored by svndigest. It is the responsibility of the
165       statistics implementer to obey the ignore state.
166
167       @return True if item property svndigest:ignore was set.
168    */
169    bool svndigest_ignore(void) const;
170
171    /**
172     */
173    const StatsCollection& stats(void) const;
174
175    /**
176     */
177    StatsCollection& stats(void);
178
179    /**
180       Access point for a NodeVisitor to start traversing Node and its
181       daughter nodes.
182     */
183    virtual void traverse(NodeVisitor& visitor)=0;
184
185    /**
186     */
187    inline const SVNinfo& svn_info(void) const { return svninfo_; }
188
189    /**
190     */
191    const TinyStats& tiny_stats(void) const { return tiny_stats_; }
192
193  protected:
194    unsigned int level_;
195    std::string output_dir_;
196    std::string path_; // absolute path
197    static std::string project_;
198    StatsCollection stats_;
199    TinyStats tiny_stats_;
200
201  private:
202    ///
203    /// @brief Copy Constructor, not implemented
204    ///
205    Node(const Node&);
206
207    /**
208     */
209    void html_tabletd(std::ostream&, 
210                      const std::string& stats_type, 
211                      const std::string& user, 
212                      LineTypeParser::line_type lt) const;
213
214    virtual void log_core(SVNlog&) const=0;
215
216    bool link_;
217    std::string local_path_; // path from root
218    mutable SVNlog* log_;
219    SVNproperty property_;
220    SVNinfo svninfo_;
221
222    friend class FilePrinter;
223    friend class DirectoryPrinter;
224    friend class NodePrinter;
225  };
226
227  /**
228     \brief Functor class to compare pointers of Nodes
229  */
230  struct NodePtrLess
231  {
232    /**
233       @return true if first and second are of same type (Directory or
234       File) and name of first is (alphabetically) less than name of
235       second; or if first is a Directory and second is a File.
236     */
237    inline bool operator()(const Node* first, const Node* second) const
238    {   
239      if (first->dir()==second->dir())
240        return first->name()<second->name();
241      return first->dir();
242    }
243  };
244
245}} // end of namespace svndigest and namespace theplu
246
247#endif
Note: See TracBrowser for help on using the repository browser.