source: trunk/lib/Node.h @ 519

Last change on this file since 519 was 519, checked in by Jari Häkkinen, 14 years ago

trac moved to new location.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.9 KB
RevLine 
[165]1#ifndef _theplu_svndigest_node_
2#define _theplu_svndigest_node_
3
[7]4// $Id: Node.h 519 2007-12-23 20:14:50Z jari $
[4]5
[84]6/*
[380]7  Copyright (C) 2005, 2006, 2007 Jari Häkkinen, Peter Johansson
[84]8
[519]9  This file is part of svndigest, http://trac.thep.lu.se/svndigest
[84]10
[149]11  svndigest is free software; you can redistribute it and/or modify it
[84]12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation; either version 2 of the License, or
14  (at your option) any later version.
15
[149]16  svndigest is distributed in the hope that it will be useful, but
[84]17  WITHOUT ANY WARRANTY; without even the implied warranty of
[149]18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
[84]19  General Public License for more details.
20
21  You should have received a copy of the GNU General Public License
22  along with this program; if not, write to the Free Software
23  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24  02111-1307, USA.
25*/
26
[177]27#include "html_utility.h"
[487]28#include "ClassicStats.h"
[129]29#include "SVNinfo.h"
[285]30#include "SVNlog.h"
[100]31#include "utility.h"
[14]32
[226]33#include <map>
[29]34#include <ostream>
[91]35#include <stdexcept>
[4]36#include <string>
37
38namespace theplu{
[149]39namespace svndigest{
[4]40
[303]41  class Alias;
42
[91]43  ///
44  /// If something goes wrong in the use of the Node or its derived
45  /// classes, a NodeException is thrown.
46  ///
47  struct NodeException : public std::runtime_error
48  { inline NodeException(const std::string& msg) : runtime_error(msg) {} };
49
[4]50  ///
51  /// Abstract Base Class for files.
52  ///
53  class Node
54  {
55  public:
[91]56
[4]57    ///
58    /// @brief Constructor
59    ///
[112]60    Node(const u_int, const std::string&, const std::string&);
[91]61
[9]62    ///
63    /// @brief Destructor
64    ///
[453]65    virtual ~Node(void);
[4]66
[74]67    ///
[129]68    /// @brief Get the author of the latest commit.
[112]69    ///
[452]70    std::string author(void) const;
[112]71
[452]72
[185]73    /**
74       @brief Check whether node is binary.
75
76       @return True if node is binary.
77    */
78    inline bool binary(void) const { return binary_; }
79
[112]80    ///
[101]81    /// @return true if directory
82    ///
83    virtual bool dir(void) const;
84
85    ///
[175]86    /// @return href to this node
[74]87    ///
[175]88    virtual std::string href(void) const=0;
[74]89
[213]90    void html_tablerow(std::ostream&, const std::string&, 
91                       const std::string& user) const;
[74]92
[185]93    /**
94       @brief Check whether node should be ignored in statistics.
95
96       If a node is to be ignored the statistics implementer should
97       respect this state. Currently binary files and items with
98       property svndigest:ignore are to be ignored by svndigest. If
99       the node is a directory then the direcotry and its siblings
100       should be ignored by statistics.
101
102       @return True of node should be ignored by statistics.
103
104       @see SVNproperty::svndigest_ingorable
105    */
[361]106    inline bool ignore(void) const 
107    { return binary_ || svndigest_ignore_ || link_; }
[185]108
[100]109    ///
[129]110    /// @brief Get the revision number of the latest commit.
[112]111    ///
[452]112    svn_revnum_t last_changed_rev(void) const;
[112]113
[380]114    /**
[447]115       @return log of this node in a recursive manner.
116    */
[453]117    const SVNlog& log(void) const;
[447]118
119    /**
[380]120       @return The explicit string identifying the underlying derived
121       class.
122    */
[343]123    virtual std::string node_type(void) const=0;
[182]124
125    ///
[100]126    /// @return
127    ///
[201]128    inline const std::string& local_path(void) const { return local_path_; }
[60]129
[129]130    ///
[201]131    /// Function returning everything after the last '/'
132    ///
133    /// @return name of node (not full path)
134    ///
[482]135    std::string name(void) const;
[201]136
[343]137    /**
[356]138       Note that returned string always end with '/' with the
139       exception when an empty string is returned.
140
[482]141       @return output dir for example 'lib/' for this file
[343]142     */
143    std::string output_dir(void) const;
144
145    /**
[356]146       @return output path for example 'lib/Node.h.html' for this file
[343]147     */
148    virtual std::string output_path(void) const=0;
149
[201]150    ///
[129]151    /// @brief parsing file using svn blame.
152    ///
[487]153    virtual const ClassicStats& parse(const bool verbose=false)=0;
[4]154
[176]155    ///
156    /// @todo doc
157    ///
[91]158    inline const std::string& path(void) const { return path_; }
159
[10]160    ///
[58]161    /// Function printing HTML in current working directory
[10]162    ///
[258]163    void print(const bool verbose=false) const;
[4]164
[258]165    void print_author_summary(std::ostream&, std::string, const SVNlog&) const; 
[234]166
[425]167    virtual void print_copyright(std::map<std::string,Alias>&, bool) const=0;
[198]168
[185]169    /**
170       @brief Check if item used to create this object has been
171       assigned property svndigest:ignore.
172
173       Currently files with property svndigest:ignore are to be
174       ignored by svndigest. It is the responsibility of the
175       statistics implementer to obey the ignore state.
176
[203]177       @return True if item property svndigest:ignore was set.
[185]178    */
179    inline bool svndigest_ignore(void) const { return svndigest_ignore_; }
180
[330]181    /**
182       \see SVNinfo::url(void)
183    */
184    std::string url(void) const;
185   
[129]186  protected:
[112]187
[452]188    virtual SVNlog log_core(void) const=0;
189
[23]190    ///
[199]191    /// print path in html format (with anchors) to @a os
192    ///
193    void path_anchor(std::ostream& os) const; 
194
[112]195    u_int level_;
[201]196    std::string local_path_; // path from root
[343]197    std::string output_dir_;
[203]198    std::string path_; // absolute path
[207]199    static std::string project_;
[487]200    ClassicStats stats_;
[4]201
[9]202  private:
203    ///
204    /// @brief Copy Constructor, not implemented
205    ///
206    Node(const Node&);
[29]207
[258]208    virtual void print_core(bool verbose=false) const=0;
209
210    ///
211    /// print page for specific user (or all) and specific line_style
212    /// (or total).
213    ///
[497]214    virtual void print_core(const std::string& stats_type,
215                            const std::string& user, 
[258]216                            const std::string& line_type,
217                            const SVNlog&) const=0; 
218
[185]219    bool binary_;
[361]220    bool link_;
[453]221    mutable SVNlog* log_;
[185]222    bool svndigest_ignore_;
[129]223    SVNinfo svninfo_;
[9]224  };
[4]225
[330]226  /**
227     \brief Functor class to compare pointers of Nodes
228  */
[101]229  struct NodePtrLess
230  {
[330]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     */
[101]236    inline bool operator()(const Node* first, const Node* second) const
237    {   
238      if (first->dir()==second->dir())
[201]239        return first->name()<second->name();
[101]240      return first->dir();
241    }
242  };
243
[149]244}} // end of namespace svndigest and namespace theplu
[4]245
[7]246#endif
Note: See TracBrowser for help on using the repository browser.