source: trunk/lib/Node.h @ 1290

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

closes #457. Lifting out plotting functions in Stats into a new class
StatsPlotter?. In same manner lifting out print functions from
Node/Directory/File? into a new hierarchy
NodePrinter/DirectoryPrinter/FilePrinter?. To accomplish these splits
without to much recoding some friendships are introduced. These new
classes are only needed for svndigest (not svncopyright) and are
therefore placed in a library named libsvndigest together with Graph
class and first_page functions. Remaining functionality, shared
between svncopyright and svndigest, are located in libsvndigest_core
and linked into both binaries.

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