source: trunk/lib/Stats.h @ 528

Last change on this file since 528 was 528, checked in by Peter Johansson, 14 years ago

fixes #280 - keep on refactoring of Stats class

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.4 KB
Line 
1#ifndef _theplu_svndigest_stats_
2#define _theplu_svndigest_stats_
3
4// $Id: Stats.h 528 2007-12-25 10:23:04Z peter $
5
6/*
7  Copyright (C) 2005 Peter Johansson
8  Copyright (C) 2006 Jari Häkkinen, Peter Johansson
9  Copyright (C) 2007 Peter Johansson
10
11  This file is part of svndigest, http://trac.thep.lu.se/svndigest
12
13  svndigest is free software; you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation; either version 2 of the License, or
16  (at your option) any later version.
17
18  svndigest is distributed in the hope that it will be useful, but
19  WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  General Public License for more details.
22
23  You should have received a copy of the GNU General Public License
24  along with this program; if not, write to the Free Software
25  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26  02111-1307, USA.
27*/
28
29#include "Parser.h"
30
31#include <subversion-1/svn_types.h>
32
33#include <map>
34#include <istream>
35#include <set>
36#include <string>
37#include <vector>
38
39namespace theplu{
40namespace svndigest{
41
42  ///
43  /// Class taking care of statistics from svn.
44  ///
45  class Stats
46  {
47  public:
48    ///
49    /// @brief Default Constructor
50    ///
51    explicit Stats(const std::string& path);
52
53    /**
54       \brief Destructor
55    */
56    virtual ~Stats(void);
57
58    ///
59    /// @return set of authors
60    ///
61    const std::set<std::string>& authors(void) const;
62
63    ///
64    ///
65    ///
66    u_int code(const std::string& user="all") const; 
67
68
69    ///
70    ///
71    ///
72    u_int comments(const std::string& user="all") const; 
73
74    ///
75    ///
76    ///
77    u_int empty(const std::string& user="all") const; 
78
79    ///
80    ///
81    ///
82    svn_revnum_t last_changed_rev(void) const;
83
84    ///
85    ///
86    ///
87    u_int lines(const std::string& user="all") const; 
88
89    /**
90       Load object from a stream.
91       
92       \return true if successful
93     */
94    bool load_cache(std::istream&);
95
96    /**
97       Do the parsing
98    */
99    void parse(const std::string&);
100
101    ///
102    /// Create statistics graph.
103    ///
104    std::string plot(const std::string&, const std::string&) const;
105
106    ///
107    /// Plotting code, comment, other, and total in same plot (for
108    /// 'all' not individual authors).
109    ///
110    void plot_summary(const std::string& output) const;
111
112    /**
113       Send Stats to a stream.
114     */
115    void print(std::ostream&) const;
116
117    ///
118    /// @brief Clear all statistics
119    ///
120    void reset(void); 
121
122    ///
123    /// \return latest revision for whole project
124    ///
125    svn_revnum_t revision(void) const { return revision_; }
126
127    /**
128       \return resulting Stats
129    */
130    Stats& operator+=(const Stats&);
131
132
133
134  protected:
135    inline std::string code_cache(void) const {return "CACHE CODE";} 
136    inline std::string comments_cache(void) const {return "CACHE COMMENTS";} 
137    inline std::string other_cache(void) const {return "CACHE EMPTY";} 
138    inline std::string total_cache(void) const {return "CACHE TOTAL";} 
139
140    typedef std::map<std::string, std::vector<u_int> > Author2Vector;
141    typedef Author2Vector::iterator A2VIter;
142    typedef Author2Vector::const_iterator A2VConstIter;
143
144    void add_author(std::string);
145    void add_authors(std::set<std::string>::const_iterator, 
146                     std::set<std::string>::const_iterator);
147
148    /**
149       add range [\a first, \a last) to \a map
150     */
151    void map_add(Author2Vector::const_iterator first, 
152                 Author2Vector::const_iterator last,
153                 Author2Vector& map);
154
155    ///
156    /// Init statistics graph.
157    ///
158    void plot_init(const std::string& output) const;
159
160    Author2Vector total_;
161    Author2Vector code_;
162    Author2Vector comments_;
163    Author2Vector other_;
164    std::set<std::string> authors_;
165
166    const std::vector<u_int>& get_vector(const Author2Vector&, 
167                                         std::string user) const;
168  private:
169    void accumulate(std::vector<u_int>& vec) const;
170    void accumulate_stats(void);
171    virtual bool do_load_cache(std::istream&)=0;
172    virtual void do_parse(const std::string&)=0;
173    virtual std::string do_plot(const std::string&, const std::string&) const=0;
174    virtual void do_print(std::ostream& ) const=0;
175   
176    u_int get_back(const Author2Vector&, std::string user) const;
177
178    svn_revnum_t revision_; // Should be the latest revision for whole project
179    svn_revnum_t last_changed_rev_; // Should be the latest revision for file
180
181
182    // using compiler generated copy constructor
183    //Stats(const Stats&);
184    // no assignment
185    Stats& operator=(const Stats&);
186
187  };
188}} // end of namespace svndigest end of namespace theplu
189
190#endif
Note: See TracBrowser for help on using the repository browser.