source: trunk/lib/Stats.h @ 185

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

Fixes #65 and #60. Added support for svndigest:ignore. Uppdated documentation. Reworked binary file treatment.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.6 KB
Line 
1#ifndef _theplu_svndigest_stats_
2#define _theplu_svndigest_stats_
3
4// $Id: Stats.h 185 2006-09-06 02:39:18Z jari $
5
6/*
7  Copyright (C) 2005 Peter Johansson
8  Copyright (C) 2006 Jari Häkkinen, Peter Johansson
9
10  This file is part of svndigest, http://lev.thep.lu.se/trac/svndigest
11
12  svndigest is free software; you can redistribute it and/or modify it
13  under the terms of the GNU General Public License as published by
14  the Free Software Foundation; either version 2 of the License, or
15  (at your option) any later version.
16
17  svndigest is distributed in the hope that it will be useful, but
18  WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  General Public License for more details.
21
22  You should have received a copy of the GNU General Public License
23  along with this program; if not, write to the Free Software
24  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25  02111-1307, USA.
26*/
27
28#include "Parser.h"
29
30#include <subversion-1/svn_types.h>
31
32#include <map>
33#include <set>
34#include <string>
35#include <vector>
36
37namespace theplu{
38namespace svndigest{
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    void parse(const std::string&);
84
85    ///
86    /// Create statistics graph.
87    ///
88    std::string plot(const std::string&, const std::string&) const;
89
90    ///
91    /// @brief Clear all statistics
92    ///
93    inline void reset(void) 
94    { code_.clear(); comments_.clear(); total_.clear(); authors_.clear();}
95
96    ///
97    ///
98    ///
99    inline u_int revision(void) const { return revision_; }
100
101    ///
102    ///
103    ///
104    inline u_int lines(void) const { return accumulated(total_).back(); }
105
106    ///
107    ///
108    ///
109    inline u_int lines(const std::string& user) const 
110    { return accumulated(total_, user).back(); }
111
112    ///
113    /// @return resulting Stats
114    ///
115    Stats& operator+=(const Stats&);
116
117  private:
118    // Peter, if the vector is sparse make it a map
119    typedef std::map<std::string, std::vector<u_int> > Map_;
120    typedef Map_::iterator MapIter_;
121    typedef Map_::const_iterator MapConstIter_;
122
123    ///
124    /// Copy constructor (not implemented)
125    ///
126    Stats(const Stats& other);
127
128    ///
129    /// @return accumulated vector of total
130    ///
131    std::vector<u_int> accumulated(const Map_&) const;
132
133    ///
134    /// @return accumulated vector of stats_[user]
135    ///
136    std::vector<u_int> accumulated(const Map_&, 
137                                   const std::string& user) const;
138
139    ///
140    /// @brief adding a line to user from revision to the stats
141    ///
142    void add(const std::string& user, const u_int& revision,
143             const Parser::line_type&); 
144
145
146    svn_revnum_t revision_; // Should be the latest revision for whole project
147    svn_revnum_t last_changed_rev_; // Should be the latest revision for file
148
149    std::set<std::string> authors_;
150    Map_ code_;
151    Map_ comments_;
152    Map_ total_;
153  };
154}} // end of namespace svndigest end of namespace theplu
155
156#endif
Note: See TracBrowser for help on using the repository browser.