source: trunk/lib/Stats.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.6 KB
Line 
1// $Id: Stats.h 129 2006-08-02 17:56:18Z jari $
2
3/*
4  Copyright (C) 2005 Peter Johansson
5  Copyright (C) 2006 Jari Häkkinen, Peter Johansson
6
7  This file is part of svnstat, http://lev.thep.lu.se/trac/svnstat
8
9  svnstat is free software; you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or
12  (at your option) any later version.
13
14  svnstat is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22  02111-1307, USA.
23*/
24
25#ifndef _theplu_svnstat_stats_
26#define _theplu_svnstat_stats_
27
28#include "Parser.h"
29
30#include <svn_types.h>
31
32#include <map>
33#include <set>
34#include <string>
35#include <vector>
36
37namespace theplu{
38namespace svnstat{
39
40  ///
41  /// Class taking care of statistics from svn.
42  ///
43  class Stats
44  {
45  public:
46    ///
47    /// @brief Default Constructor
48    ///
49    explicit Stats(const std::string& path);
50
51    ///
52    /// @return set of authors
53    ///
54    inline const std::set<std::string>& authors(void) const { return authors_; }
55
56    ///
57    ///
58    ///
59    inline u_int code(void) const { return accumulated(code_).back(); }
60
61    ///
62    ///
63    ///
64    inline u_int code(const std::string& user) const 
65    { return accumulated(code_, user).back(); }
66
67    ///
68    ///
69    ///
70    inline u_int comments(void) const { return accumulated(comments_).back(); }
71
72    ///
73    ///
74    ///
75    inline u_int comments(const std::string& user) const 
76    { return accumulated(comments_, user).back(); }
77
78    ///
79    ///
80    ///
81    inline u_int last_changed_rev(void) const { return last_changed_rev_; }
82
83    ///
84    /// @return true if file is binary
85    ///
86    bool parse(const std::string&);
87
88    ///
89    /// Create statistics graph.
90    ///
91    std::string plot(const std::string&, const std::string&) const;
92
93    ///
94    /// @brief Clear all statistics
95    ///
96    inline void reset(void) 
97    { code_.clear(); comments_.clear(); total_.clear(); authors_.clear();}
98
99    ///
100    ///
101    ///
102    inline u_int revision(void) const { return revision_; }
103
104    ///
105    ///
106    ///
107    inline u_int lines(void) const { return accumulated(total_).back(); }
108
109    ///
110    ///
111    ///
112    inline u_int lines(const std::string& user) const 
113    { return accumulated(total_, user).back(); }
114
115    ///
116    /// @return resulting Stats
117    ///
118    Stats& operator+=(const Stats&);
119
120  private:
121    // Peter, if the vector is sparse make it a map
122    typedef std::map<std::string, std::vector<u_int> > Map_;
123    typedef Map_::iterator MapIter_;
124    typedef Map_::const_iterator MapConstIter_;
125
126    ///
127    /// Copy constructor (not implemented)
128    ///
129    Stats(const Stats& other);
130
131    ///
132    /// @return accumulated vector of total
133    ///
134    std::vector<u_int> accumulated(const Map_&) const;
135
136    ///
137    /// @return accumulated vector of stats_[user]
138    ///
139    std::vector<u_int> accumulated(const Map_&, 
140                                   const std::string& user) const;
141
142    ///
143    /// @brief adding a line to user from revision to the stats
144    ///
145    void add(const std::string& user, const u_int& revision,
146             const Parser::line_type); 
147
148
149    svn_revnum_t revision_; // Should be the latest revision for whole project
150    svn_revnum_t last_changed_rev_; // Should be the latest revision for file
151
152    std::set<std::string> authors_;
153    Map_ code_;
154    Map_ comments_;
155    Map_ total_;
156  };
157}} // end of namespace svnstat end of namespace theplu
158
159#endif
Note: See TracBrowser for help on using the repository browser.