source: trunk/lib/Node.h

Last change on this file was 1538, checked in by Peter Johansson, 9 years ago

refs #334. implement --update also for directories. For Directories the 'revision: ' tag in html output reflects the lowest revision of the nodes (Directory and sub-nodes). Directory is not reprinted if this revision is at least last_changed_rev, in other words, there is no node by node comparison but a more easily implemented collective comparison. In case of homogenous revision (no mixtures) this is is the same thing.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.5 KB
Line 
1#ifndef _theplu_svndigest_node_
2#define _theplu_svndigest_node_
3
4// $Id: Node.h 1538 2012-10-07 09:29:04Z 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  Copyright (C) 2011 Peter Johansson
11
12  This file is part of svndigest, http://dev.thep.lu.se/svndigest
13
14  svndigest is free software; you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation; either version 3 of the License, or
17  (at your option) any later version.
18
19  svndigest is distributed in the hope that it will be useful, but
20  WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  General Public License for more details.
23
24  You should have received a copy of the GNU General Public License
25  along with svndigest. If not, see <http://www.gnu.org/licenses/>.
26*/
27
28#include "LineTypeParser.h"
29#include "StatsCollection.h"
30#include "SVNinfo.h"
31#include "SVNlog.h"
32#include "SVNproperty.h"
33#include "TinyStats.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         const std::string& = "");
65
66    ///
67    /// @brief Destructor
68    ///
69    virtual ~Node(void);
70
71    ///
72    /// @brief Get the author of the latest commit.
73    ///
74    std::string author(void) const;
75
76
77    /**
78       @brief Check whether node is binary.
79
80       @return True if node is binary.
81    */
82    bool binary(void) const;
83
84    ///
85    /// @return true if directory
86    ///
87    virtual bool dir(void) const;
88
89    ///
90    /// @return href to this node
91    ///
92    virtual std::string href(void) const=0;
93
94    /**
95     */
96    void html_tablerow(std::ostream& os,
97                       const std::string& stats_type,
98                       const std::string& css_class,
99                       const std::string& user) const;
100
101    /**
102       Create the TinyStats based on the stored CollectionStats
103     */
104    void init_tiny_stats(void);
105
106    ///
107    /// @brief Get the revision number of the latest commit.
108    ///
109    virtual svn_revnum_t last_changed_rev(void) const=0;
110
111    /**
112       @return log of this node in a recursive manner.
113    */
114    const SVNlog& log(void) const;
115
116    ///
117    /// @return
118    ///
119    inline const std::string& local_path(void) const { return local_path_; }
120
121    ///
122    /// Function returning everything after the last '/'
123    ///
124    /// @return name of node (not full path)
125    ///
126    std::string name(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    /// @todo doc
136    ///
137    inline const std::string& path(void) const { return path_; }
138
139    /**
140       \return svnprop for this Node
141     */
142    const SVNproperty& property(void) const;
143
144    /**
145       check revision of this node and sub-nodes and return the
146       smallest revision, i.e., all nodes are at least at revision
147       returned.
148     */
149    virtual svn_revnum_t revision_min(void) const=0;
150
151    /**
152       \return true if svncopyright::ignore property was set
153     */
154    bool svncopyright_ignore(void) const;
155
156    /**
157       @brief Check if Node should be ignored by svndigest.
158
159       Binary files and links will be ignored as well as nodes with
160       property svndigest:ignore set to "" as that implies that all
161       revs should be ignored.
162
163       @return True if item property svndigest:ignore was set with
164       empty string or node is binary or link.
165
166       \see SVNproperty::svndigest_ignore()
167    */
168    bool svndigest_ignore(void) const;
169
170    /**
171     */
172    const StatsCollection& stats(void) const;
173
174    /**
175     */
176    StatsCollection& stats(void);
177
178    /**
179       Access point for a NodeVisitor to start traversing Node and its
180       daughter nodes.
181     */
182    virtual void traverse(NodeVisitor& visitor)=0;
183
184    /**
185     */
186    inline const SVNinfo& svn_info(void) const { return svninfo_; }
187
188    /**
189     */
190    const TinyStats& tiny_stats(void) const { return tiny_stats_; }
191
192  protected:
193    unsigned int level_;
194    std::string output_dir_;
195    std::string path_; // absolute path
196    static std::string project_;
197    StatsCollection stats_;
198    TinyStats tiny_stats_;
199
200  private:
201    ///
202    /// @brief Copy Constructor, not implemented
203    ///
204    Node(const Node&);
205
206    /**
207     */
208    void html_tabletd(std::ostream&,
209                      const std::string& stats_type,
210                      const std::string& user,
211                      LineTypeParser::line_type lt) const;
212
213    virtual void log_core(SVNlog&) const=0;
214
215    bool link_;
216    std::string local_path_; // path from root
217    mutable SVNlog* log_;
218    SVNproperty property_;
219    SVNinfo svninfo_;
220
221    friend class FilePrinter;
222    friend class DirectoryPrinter;
223    friend class NodePrinter;
224  };
225
226  /**
227     \brief Functor class to compare pointers of Nodes
228  */
229  struct NodePtrLess
230  {
231    /**
232       @return true if first and second are of same type (Directory or
233       File) and name of first is (alphabetically) less than name of
234       second; or if first is a Directory and second is a File.
235     */
236    inline bool operator()(const Node* first, const Node* second) const
237    {
238      if (first->dir()==second->dir())
239        return first->name()<second->name();
240      return first->dir();
241    }
242  };
243
244}} // end of namespace svndigest and namespace theplu
245
246#endif
Note: See TracBrowser for help on using the repository browser.