source: trunk/lib/Node.h @ 138

Last change on this file since 138 was 138, checked in by Jari Häkkinen, 15 years ago

Fixes #23. No system calls to svn are done anymore.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.3 KB
Line 
1// $Id: Node.h 138 2006-08-03 21:40:15Z jari $
2
3/*
4  Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson
5
6  This file is part of svnstat, http://lev.thep.lu.se/trac/svnstat
7
8  svnstat is free software; you can redistribute it and/or modify it
9  under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  svnstat is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#ifndef _theplu_svnstat_node_
25#define _theplu_svnstat_node_
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 svnstat{
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    std::string author(void) const { return svninfo_.last_changed_author(); }
66
67    ///
68    /// @return true if directory
69    ///
70    virtual bool dir(void) const;
71
72    ///
73    /// @return A properly formatted html link to this node.
74    ///
75    virtual std::string html_link(void) const=0;
76
77    ///
78    ///
79    ///
80    std::string html_tablerow(const std::string&) const;
81
82    ///
83    /// @brief Get the revision number of the latest commit.
84    ///
85    svn_revnum_t last_changed_rev(void) const
86    { return svninfo_.last_changed_rev(); }
87
88    ///
89    /// @return
90    ///
91    inline const std::string& output_name(void) const { return output_name_; }
92
93    ///
94    /// @brief parsing file using svn blame.
95    ///
96    virtual const Stats& parse(const bool verbose=false)=0;
97
98    inline const std::string& path(void) const { return path_; }
99
100    ///
101    /// Function printing HTML in current working directory
102    ///
103    virtual void print(const bool verbose=false) const=0;
104
105  protected:
106
107    ///
108    /// Function returning everything after the last '/'
109    ///
110    /// @return name of node (not full path)
111    ///
112    inline std::string name(void) const { return file_name(path_); }
113
114    ///
115    /// @brief print html footer of page
116    ///
117    void print_footer(std::ostream&) const;
118   
119    ///
120    /// @brief print html header of page
121    ///
122    void print_header(std::ostream&) const;
123
124    u_int level_;
125    std::string output_name_; //without suffix
126    std::string path_;
127    Stats stats_;
128
129  private:
130    ///
131    /// @brief Copy Constructor, not implemented
132    ///
133    Node(const Node&);
134
135    SVNinfo svninfo_;
136  };
137
138  struct NodePtrLess
139  {
140    inline bool operator()(const Node* first, const Node* second) const
141    {   
142      if (first->dir()==second->dir())
143        return first->output_name()<second->output_name();
144      return first->dir();
145    }
146  };
147
148}} // end of namespace svnstat and namespace theplu
149
150#endif
Note: See TracBrowser for help on using the repository browser.