source: trunk/lib/Node.h @ 285

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

moving first page generation to separate file.

  • 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 285 2007-05-06 19:03:28Z 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  ///
43  /// If something goes wrong in the use of the Node or its derived
44  /// classes, a NodeException is thrown.
45  ///
46  struct NodeException : public std::runtime_error
47  { inline NodeException(const std::string& msg) : runtime_error(msg) {} };
48
49  ///
50  /// Abstract Base Class for files.
51  ///
52  class Node
53  {
54  public:
55
56    ///
57    /// @brief Constructor
58    ///
59    Node(const u_int, const std::string&, const std::string&);
60
61    ///
62    /// @brief Destructor
63    ///
64    virtual inline ~Node(void) {};
65
66    ///
67    /// @brief Get the author of the latest commit.
68    ///
69    inline const std::string& author(void) const
70    { return svninfo_.last_changed_author(); }
71
72    /**
73       @brief Check whether node is binary.
74
75       @return True if node is binary.
76    */
77    inline bool binary(void) const { return binary_; }
78
79    ///
80    /// @return true if directory
81    ///
82    virtual bool dir(void) const;
83
84    ///
85    /// @return href to this node
86    ///
87    virtual std::string href(void) const=0;
88
89    void html_tablerow(std::ostream&, const std::string&, 
90                       const std::string& user) const;
91
92    /**
93       @brief Check whether node should be ignored in statistics.
94
95       If a node is to be ignored the statistics implementer should
96       respect this state. Currently binary files and items with
97       property svndigest:ignore are to be ignored by svndigest. If
98       the node is a directory then the direcotry and its siblings
99       should be ignored by statistics.
100
101       @return True of node should be ignored by statistics.
102
103       @see SVNproperty::svndigest_ingorable
104    */
105    inline bool ignore(void) const { return binary_ || svndigest_ignore_; }
106
107    ///
108    /// @brief Get the revision number of the latest commit.
109    ///
110    inline svn_revnum_t last_changed_rev(void) const
111    { return svninfo_.last_changed_rev(); }
112
113    ///
114    /// @return file or directory
115    ///
116    virtual const std::string node_type(void) const=0;
117
118    ///
119    /// @return
120    ///
121    inline const std::string& local_path(void) const { return local_path_; }
122
123    ///
124    /// Function returning everything after the last '/'
125    ///
126    /// @return name of node (not full path)
127    ///
128    inline std::string name(void) const { return file_name(path_); }
129
130    ///
131    /// @brief parsing file using svn blame.
132    ///
133    virtual const Stats& parse(const bool verbose=false)=0;
134
135    ///
136    /// @todo doc
137    ///
138    inline const std::string& path(void) const { return path_; }
139
140    ///
141    /// Function printing HTML in current working directory
142    ///
143    void print(const bool verbose=false) const;
144
145    void print_author_summary(std::ostream&, std::string, const SVNlog&) const; 
146
147    virtual void 
148    print_copyright(std::map<std::string, std::string>&) const=0;
149
150    /**
151       @brief Check if item used to create this object has been
152       assigned property svndigest:ignore.
153
154       Currently files with property svndigest:ignore are to be
155       ignored by svndigest. It is the responsibility of the
156       statistics implementer to obey the ignore state.
157
158       @return True if item property svndigest:ignore was set.
159    */
160    inline bool svndigest_ignore(void) const { return svndigest_ignore_; }
161
162  protected:
163
164    ///
165    /// print path in html format (with anchors) to @a os
166    ///
167    void path_anchor(std::ostream& os) const; 
168
169    u_int level_;
170    std::string local_path_; // path from root
171    std::string path_; // absolute path
172    static std::string project_;
173    Stats stats_;
174
175  private:
176    ///
177    /// @brief Copy Constructor, not implemented
178    ///
179    Node(const Node&);
180
181    virtual void print_core(bool verbose=false) const=0;
182
183    ///
184    /// print page for specific user (or all) and specific line_style
185    /// (or total).
186    ///
187    virtual void print_core(const std::string& user, 
188                            const std::string& line_type,
189                            const SVNlog&) const=0; 
190
191    bool binary_;
192    bool svndigest_ignore_;
193    SVNinfo svninfo_;
194  };
195
196  struct NodePtrLess
197  {
198    inline bool operator()(const Node* first, const Node* second) const
199    {   
200      if (first->dir()==second->dir())
201        return first->name()<second->name();
202      return first->dir();
203    }
204  };
205
206}} // end of namespace svndigest and namespace theplu
207
208#endif
Note: See TracBrowser for help on using the repository browser.