source: trunk/lib/Stats.h @ 118

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

fixes #46 #45 #26 #40

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.6 KB
RevLine 
[84]1// $Id: Stats.h 118 2006-07-03 07:44:49Z peter $
[14]2
[84]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
[14]25#ifndef _theplu_svnstat_stats_
26#define _theplu_svnstat_stats_
27
[118]28#include "Parser.h"
29
[60]30#include <iostream>
[14]31#include <map>
[44]32#include <ostream>
[118]33#include <set>
[34]34#include <string>
[14]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
[34]48    ///
[80]49    explicit Stats(const std::string& path);
[34]50
[60]51    ///
[118]52    /// @return set of authors
[112]53    ///
[118]54    inline const std::set<std::string>& authors(void) const { return authors_; }
55
[112]56    ///
[118]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    ///
[112]81    inline u_int last_changed_rev(void) const { return last_changed_rev_; }
82
83    ///
[60]84    /// @return true if file is binary
85    ///
[72]86    bool parse(const std::string&);
[14]87
[23]88    ///
[74]89    /// Create statistics graph.
[23]90    ///
[101]91    std::string plot(const std::string&, const std::string&) const;
[23]92
93    ///
94    /// @brief Clear all statistics
95    ///
[118]96    inline void reset(void) 
97    { code_.clear(); comments_.clear(); total_.clear(); authors_.clear();}
[14]98
[74]99    ///
100    ///
101    ///
[112]102    inline u_int revision(void) const { return revision_; }
103
104    ///
[118]105    ///
[112]106    ///
[118]107    inline u_int lines(void) const { return accumulated(total_).back(); }
108
[112]109    ///
[118]110    ///
111    ///
112    inline u_int lines(const std::string& user) const 
113    { return accumulated(total_, user).back(); }
[74]114
[14]115    ///
116    /// @return resulting Stats
117    ///
118    Stats& operator+=(const Stats&);
119
120  private:
[118]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
[23]126    ///
127    /// Copy constructor (not implemented)
128    ///
[14]129    Stats(const Stats& other);
130
[23]131    ///
132    /// @return accumulated vector of total
133    ///
[118]134    std::vector<u_int> accumulated(const Map_&) const;
[23]135
136    ///
137    /// @return accumulated vector of stats_[user]
138    ///
[118]139    std::vector<u_int> accumulated(const Map_&, 
140                                   const std::string& user) const;
[23]141
[60]142    ///
143    /// @brief adding a line to user from revision to the stats
144    ///
[118]145    void add(const std::string& user, const u_int& revision,
146             const Parser::line_type); 
[60]147
[41]148
[112]149    u_int revision_; // Should be the latest revision for whole project
150    u_int last_changed_rev_; // Should be the latest revision for file
[80]151
[118]152    std::set<std::string> authors_;
153    Map_ code_;
154    Map_ comments_;
155    Map_ total_;
[14]156  };
[71]157}} // end of namespace svnstat end of namespace theplu
[14]158
[71]159#endif
Note: See TracBrowser for help on using the repository browser.