source: trunk/lib/Node.h @ 207

Last change on this file since 207 was 207, checked in by Peter Johansson, 15 years ago

refs #41 and #44. Splitted print function in File and Directory to 2 functions. One public and one private. The private print a page for a specific author (or all) and specific code (or total), and the public calls this private function. Also added total number of commits #refs 87. NOTE the change of file structure forced all local paths to be relative from target/projectname rather than target as before.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.6 KB
Line 
1#ifndef _theplu_svndigest_node_
2#define _theplu_svndigest_node_
3
4// $Id: Node.h 207 2006-09-11 07:08:57Z peter $
5
6/*
7  Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson
8
9  This file is part of svndigest, http://lev.thep.lu.se/trac/svndigest
10
11  svndigest is free software; you can redistribute it and/or modify it
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
16  svndigest is distributed in the hope that it will be useful, but
17  WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
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
27#include "html_utility.h"
28#include "Stats.h"
29#include "SVNinfo.h"
30#include "utility.h"
31
32#include <ostream>
33#include <stdexcept>
34#include <string>
35
36namespace theplu{
37namespace svndigest{
38
39  ///
40  /// If something goes wrong in the use of the Node or its derived
41  /// classes, a NodeException is thrown.
42  ///
43  struct NodeException : public std::runtime_error
44  { inline NodeException(const std::string& msg) : runtime_error(msg) {} };
45
46  ///
47  /// Abstract Base Class for files.
48  ///
49  class Node
50  {
51  public:
52
53    ///
54    /// @brief Constructor
55    ///
56    Node(const u_int, const std::string&, const std::string&);
57
58    ///
59    /// @brief Destructor
60    ///
61    virtual inline ~Node(void) {};
62
63    ///
64    /// @brief Get the author of the latest commit.
65    ///
66    inline const std::string& author(void) const
67    { return svninfo_.last_changed_author(); }
68
69    /**
70       @brief Check whether node is binary.
71
72       @return True if node is binary.
73    */
74    inline bool binary(void) const { return binary_; }
75
76    ///
77    /// @return true if directory
78    ///
79    virtual bool dir(void) const;
80
81    ///
82    /// @return href to this node
83    ///
84    virtual std::string href(void) const=0;
85
86    void html_tablerow(std::ostream&, const std::string&) const;
87
88    /**
89       @brief Check whether node should be ignored in statistics.
90
91       If a node is to be ignored the statistics implementer should
92       respect this state. Currently binary files and items with
93       property svndigest:ignore are to be ignored by svndigest. If
94       the node is a directory then the direcotry and its siblings
95       should be ignored by statistics.
96
97       @return True of node should be ignored by statistics.
98
99       @see SVNproperty::svndigest_ingorable
100    */
101    inline bool ignore(void) const { return binary_ || svndigest_ignore_; }
102
103    ///
104    /// @brief Get the revision number of the latest commit.
105    ///
106    inline svn_revnum_t last_changed_rev(void) const
107    { return svninfo_.last_changed_rev(); }
108
109    ///
110    /// @return file or directory
111    ///
112    virtual const std::string node_type(void) const=0;
113
114    ///
115    /// @return
116    ///
117    inline const std::string& local_path(void) const { return local_path_; }
118
119    ///
120    /// Function returning everything after the last '/'
121    ///
122    /// @return name of node (not full path)
123    ///
124    inline std::string name(void) const { return file_name(path_); }
125
126    ///
127    /// @brief parsing file using svn blame.
128    ///
129    virtual const Stats& parse(const bool verbose=false)=0;
130
131    ///
132    /// @todo doc
133    ///
134    inline const std::string& path(void) const { return path_; }
135
136    ///
137    /// Function printing HTML in current working directory
138    ///
139    virtual void print(const bool verbose=false) const=0;
140
141    virtual void print_copyright(const std::vector<std::string>& dates) const=0;
142
143    /**
144       @brief Check if item used to create this object has been
145       assigned property svndigest:ignore.
146
147       Currently files with property svndigest:ignore are to be
148       ignored by svndigest. It is the responsibility of the
149       statistics implementer to obey the ignore state.
150
151       @return True if item property svndigest:ignore was set.
152    */
153    inline bool svndigest_ignore(void) const { return svndigest_ignore_; }
154
155  protected:
156
157    ///
158    /// print path in html format (with anchors) to @a os
159    ///
160    void path_anchor(std::ostream& os) const; 
161
162    u_int level_;
163    std::string local_path_; // path from root
164    std::string path_; // absolute path
165    static std::string project_;
166    Stats stats_;
167
168  private:
169    ///
170    /// @brief Copy Constructor, not implemented
171    ///
172    Node(const Node&);
173
174    bool binary_;
175    bool svndigest_ignore_;
176    SVNinfo svninfo_;
177  };
178
179  struct NodePtrLess
180  {
181    inline bool operator()(const Node* first, const Node* second) const
182    {   
183      if (first->dir()==second->dir())
184        return first->name()<second->name();
185      return first->dir();
186    }
187  };
188
189}} // end of namespace svndigest and namespace theplu
190
191#endif
Note: See TracBrowser for help on using the repository browser.