source: trunk/lib/Stats.h @ 487

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

fixes #272 in trunk and also #211 - split stats class into inherited and base class

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.2 KB
Line 
1#ifndef _theplu_svndigest_stats_
2#define _theplu_svndigest_stats_
3
4// $Id: Stats.h 487 2007-10-13 22:20:17Z 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/trac/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  protected:
128    inline std::string code_cache(void) const {return "CACHE CODE";} 
129    inline std::string comments_cache(void) const {return "CACHE COMMENTS";} 
130    inline std::string empty_cache(void) const {return "CACHE EMPTY";} 
131    inline std::string total_cache(void) const {return "CACHE TOTAL";} 
132
133    typedef std::map<std::string, std::vector<u_int> > v_map;
134
135    void add_author(std::string);
136    void add_authors(std::set<std::string>::const_iterator, 
137                     std::set<std::string>::const_iterator);
138
139    /**
140       Function to be called from children's operator+=
141     */
142    void base_add(const Stats&);
143
144    /**
145       add range [\a first, \a last) to \a map
146     */
147    void base_add(v_map::const_iterator first, v_map::const_iterator last,
148                  v_map& map);
149
150    ///
151    /// Init statistics graph.
152    ///
153    void plot_init(const std::string& output) const;
154    inline bool valid(void) const {return valid_;}
155  private:
156    virtual bool do_load_cache(std::istream&)=0;
157    virtual void do_parse(const std::string&)=0;
158    virtual std::string do_plot(const std::string&, const std::string&) const=0;
159    virtual void do_print(std::ostream& ) const=0;
160    virtual void do_reset(void)=0;
161   
162    const std::vector<u_int>& get_vector(const v_map&, std::string user) const;
163    virtual std::vector<u_int> vector(std::string type, 
164                                      std::string user) const=0;
165    void update_stats(void);
166
167    v_map total_;
168    v_map code_;
169    v_map comments_;
170    v_map other_;
171    bool valid_;
172    svn_revnum_t revision_; // Should be the latest revision for whole project
173    svn_revnum_t last_changed_rev_; // Should be the latest revision for file
174
175    std::set<std::string> authors_;
176  };
177}} // end of namespace svndigest end of namespace theplu
178
179#endif
Note: See TracBrowser for help on using the repository browser.