source: trunk/lib/Node.h @ 303

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

Sorting authors in copyright statement in same order as stated in config file. fixes #172

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.1 KB
Line 
1#ifndef _theplu_svndigest_node_
2#define _theplu_svndigest_node_
3
4// $Id: Node.h 303 2007-05-11 20:13:00Z 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  protected:
164
165    ///
166    /// print path in html format (with anchors) to @a os
167    ///
168    void path_anchor(std::ostream& os) const; 
169
170    u_int level_;
171    std::string local_path_; // path from root
172    std::string path_; // absolute path
173    static std::string project_;
174    Stats stats_;
175
176  private:
177    ///
178    /// @brief Copy Constructor, not implemented
179    ///
180    Node(const Node&);
181
182    virtual void print_core(bool verbose=false) const=0;
183
184    ///
185    /// print page for specific user (or all) and specific line_style
186    /// (or total).
187    ///
188    virtual void print_core(const std::string& user, 
189                            const std::string& line_type,
190                            const SVNlog&) const=0; 
191
192    bool binary_;
193    bool svndigest_ignore_;
194    SVNinfo svninfo_;
195  };
196
197  struct NodePtrLess
198  {
199    inline bool operator()(const Node* first, const Node* second) const
200    {   
201      if (first->dir()==second->dir())
202        return first->name()<second->name();
203      return first->dir();
204    }
205  };
206
207}} // end of namespace svndigest and namespace theplu
208
209#endif
Note: See TracBrowser for help on using the repository browser.