source: trunk/lib/Node.h @ 175

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

fixes #53

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.4 KB
Line 
1#ifndef _theplu_svndigest_node_
2#define _theplu_svndigest_node_
3
4// $Id: Node.h 175 2006-09-02 03:22:52Z 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 "Stats.h"
28#include "SVNinfo.h"
29#include "utility.h"
30
31#include <ostream>
32#include <stdexcept>
33#include <string>
34
35namespace theplu{
36namespace svndigest{
37
38  ///
39  /// If something goes wrong in the use of the Node or its derived
40  /// classes, a NodeException is thrown.
41  ///
42  struct NodeException : public std::runtime_error
43  { inline NodeException(const std::string& msg) : runtime_error(msg) {} };
44
45  ///
46  /// Abstract Base Class for files.
47  ///
48  class Node
49  {
50  public:
51
52    ///
53    /// @brief Constructor
54    ///
55    Node(const u_int, const std::string&, const std::string&);
56
57    ///
58    /// @brief Destructor
59    ///
60    virtual inline ~Node(void) {};
61
62    ///
63    /// @brief Get the author of the latest commit.
64    ///
65    inline const std::string& author(void) const
66    { return svninfo_.last_changed_author(); }
67
68    ///
69    /// @return true if directory
70    ///
71    virtual bool dir(void) const;
72
73    ///
74    /// @return href to this node
75    ///
76    virtual std::string href(void) const=0;
77
78    ///
79    ///
80    ///
81    void html_tablerow(std::ostream&, const std::string&) const;
82
83    ///
84    /// @brief Get the revision number of the latest commit.
85    ///
86    inline svn_revnum_t last_changed_rev(void) const
87    { return svninfo_.last_changed_rev(); }
88
89    ///
90    /// @return
91    ///
92    inline const std::string& output_name(void) const { return output_name_; }
93
94    ///
95    /// @brief parsing file using svn blame.
96    ///
97    virtual const Stats& parse(const bool verbose=false)=0;
98
99    inline const std::string& path(void) const { return path_; }
100
101    ///
102    /// Function printing HTML in current working directory
103    ///
104    virtual void print(const bool verbose=false) const=0;
105
106  protected:
107
108    ///
109    /// Function returning everything after the last '/'
110    ///
111    /// @return name of node (not full path)
112    ///
113    inline std::string name(void) const { return file_name(path_); }
114
115    ///
116    /// @brief print html footer of page
117    ///
118    void print_footer(std::ostream&) const;
119   
120    ///
121    /// @brief print html header of page
122    ///
123    void print_header(std::ostream&) const;
124
125    u_int level_;
126    std::string output_name_; //without suffix
127    std::string path_;
128    Stats stats_;
129
130  private:
131    ///
132    /// @brief Copy Constructor, not implemented
133    ///
134    Node(const Node&);
135
136    ///
137    /// print path in html format (with anchors) to @a os
138    ///
139    void path_anchor(std::ostream& os) const; 
140
141    SVNinfo svninfo_;
142  };
143
144  struct NodePtrLess
145  {
146    inline bool operator()(const Node* first, const Node* second) const
147    {   
148      if (first->dir()==second->dir())
149        return first->output_name()<second->output_name();
150      return first->dir();
151    }
152  };
153
154}} // end of namespace svndigest and namespace theplu
155
156#endif
Note: See TracBrowser for help on using the repository browser.