source: trunk/lib/Node.h @ 235

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

added Date class
changed date format on first page
fixed plotting only once (fixes #113)
changed interface to anchor class
more anchors to users
removed anchor to '../' in author summary in dirs
anchors are filtered through HtmlStream?
log messages are truncated and newlines are replaced with spaces

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