source: trunk/lib/Node.h @ 182

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

fixes #52 in table output directories are bold whereas files are normal.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.7 KB
Line 
1#ifndef _theplu_svndigest_node_
2#define _theplu_svndigest_node_
3
4// $Id: Node.h 182 2006-09-03 08:46:34Z 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    /// @return true if directory
71    ///
72    virtual bool dir(void) const;
73
74    ///
75    /// @return href to this node
76    ///
77    virtual std::string href(void) const=0;
78
79    ///
80    ///
81    ///
82    void html_tablerow(std::ostream&, const std::string&) const;
83
84    ///
85    /// @brief Get the revision number of the latest commit.
86    ///
87    inline svn_revnum_t last_changed_rev(void) const
88    { return svninfo_.last_changed_rev(); }
89
90    ///
91    /// @return file or directory
92    ///
93    virtual const std::string node_type(void) const=0;
94
95    ///
96    /// @return
97    ///
98    inline const std::string& output_name(void) const { return output_name_; }
99
100    ///
101    /// @brief parsing file using svn blame.
102    ///
103    virtual const Stats& parse(const bool verbose=false)=0;
104
105    ///
106    /// @todo doc
107    ///
108    inline const std::string& path(void) const { return path_; }
109
110    ///
111    /// Function printing HTML in current working directory
112    ///
113    virtual void print(const bool verbose=false) const=0;
114
115  protected:
116
117    ///
118    /// @note Directories are not consider binary.
119    ///
120    virtual bool binary(void) const=0;
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 print html footer of page
131    ///
132    void print_footer(std::ostream&) const;
133   
134    ///
135    /// @brief print html header of page
136    ///
137    void print_header(std::ostream&) const;
138
139    u_int level_;
140    std::string output_name_; //without suffix
141    std::string path_;
142    Stats stats_;
143
144  private:
145    ///
146    /// @brief Copy Constructor, not implemented
147    ///
148    Node(const Node&);
149
150    ///
151    /// print path in html format (with anchors) to @a os
152    ///
153    void path_anchor(std::ostream& os) const; 
154
155    SVNinfo svninfo_;
156  };
157
158  struct NodePtrLess
159  {
160    inline bool operator()(const Node* first, const Node* second) const
161    {   
162      if (first->dir()==second->dir())
163        return first->output_name()<second->output_name();
164      return first->dir();
165    }
166  };
167
168}} // end of namespace svndigest and namespace theplu
169
170#endif
Note: See TracBrowser for help on using the repository browser.