source: trunk/lib/Stats.h @ 198

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

refs #36 optionally a copyright information, based on Stats, can be displayed using --copyright flag. This will flag will be added to usage output when this feature is mature.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.7 KB
Line 
1#ifndef _theplu_svndigest_stats_
2#define _theplu_svndigest_stats_
3
4// $Id: Stats.h 198 2006-09-09 10:04:27Z peter $
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    ///
114    ///
115    inline std::vector<u_int> total(const std::string& user) const 
116    { return accumulated(total_, user); }
117
118    ///
119    /// @return resulting Stats
120    ///
121    Stats& operator+=(const Stats&);
122
123  private:
124    // Peter, if the vector is sparse make it a map
125    typedef std::map<std::string, std::vector<u_int> > Map_;
126    typedef Map_::iterator MapIter_;
127    typedef Map_::const_iterator MapConstIter_;
128
129    ///
130    /// Copy constructor (not implemented)
131    ///
132    Stats(const Stats& other);
133
134    ///
135    /// @return accumulated vector of total
136    ///
137    std::vector<u_int> accumulated(const Map_&) const;
138
139    ///
140    /// @return accumulated vector of stats_[user]
141    ///
142    std::vector<u_int> accumulated(const Map_&, 
143                                   const std::string& user) const;
144
145    ///
146    /// @brief adding a line to user from revision to the stats
147    ///
148    void add(const std::string& user, const u_int& revision,
149             const Parser::line_type&); 
150
151
152    svn_revnum_t revision_; // Should be the latest revision for whole project
153    svn_revnum_t last_changed_rev_; // Should be the latest revision for file
154
155    std::set<std::string> authors_;
156    Map_ code_;
157    Map_ comments_;
158    Map_ total_;
159  };
160}} // end of namespace svndigest end of namespace theplu
161
162#endif
Note: See TracBrowser for help on using the repository browser.