source: trunk/lib/Node.h @ 225

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

copyright based on log is printed to cout refs #36

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