source: trunk/lib/Node.h @ 129

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

Addresses ticket:23. Changed usage of 'svn info' to API calls.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.3 KB
Line 
1// $Id: Node.h 129 2006-08-02 17:56:18Z 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 <sstream>
33#include <stdexcept>
34#include <string>
35
36namespace theplu{
37namespace svnstat{
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    std::string author(void) const { return svninfo_.last_changed_author(); }
67
68    ///
69    /// @return true if directory
70    ///
71    virtual bool dir(void) const;
72
73    ///
74    /// @return A properly formatted html link to this node.
75    ///
76    virtual std::string html_link(void) const=0;
77
78    ///
79    ///
80    ///
81    std::string html_tablerow(const std::string&) const;
82
83    ///
84    /// @brief Get the revision number of the latest commit.
85    ///
86    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    SVNinfo svninfo_;
137  };
138
139  struct NodePtrLess
140  {
141    inline bool operator()(const Node* first, const Node* second) const
142    {   
143      if (first->dir()==second->dir())
144        return first->output_name()<second->output_name();
145      return first->dir();
146    }
147  };
148
149}} // end of namespace svnstat and namespace theplu
150
151#endif
Note: See TracBrowser for help on using the repository browser.