source: trunk/lib/Stats.h @ 1310

Last change on this file since 1310 was 1310, checked in by Peter Johansson, 11 years ago

remove declarations not used anymore

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 7.0 KB
Line 
1#ifndef _theplu_svndigest_stats_
2#define _theplu_svndigest_stats_
3
4// $Id: Stats.h 1310 2010-11-16 03:41:39Z peter $
5
6/*
7  Copyright (C) 2005 Peter Johansson
8  Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
9  Copyright (C) 2010 Peter Johansson
10
11  This file is part of svndigest, http://dev.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 3 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 svndigest. If not, see <http://www.gnu.org/licenses/>.
25*/
26
27#include "LineTypeParser.h"
28#include "Vector.h"
29
30#include <subversion-1/svn_types.h>
31
32#include <map>
33#include <istream>
34#include <set>
35#include <string>
36#include <vector>
37
38namespace theplu{
39namespace svndigest{
40
41  ///
42  /// Class taking care of statistics from svn.
43  ///
44  class Stats
45  {
46  public:
47    ///
48    /// @brief Default Constructor
49    ///
50    explicit Stats(const std::string& path);
51
52    /**
53       \brief Destructor
54    */
55    virtual ~Stats(void);
56
57    ///
58    /// @return set of authors
59    ///
60    const std::set<std::string>& authors(void) const;
61
62    ///
63    /// \return number of code lines for \a user for latest revision.
64    ///
65    unsigned int code(const std::string& user="all") const; 
66
67
68    ///
69    /// \return number of comments lines for \a user for latest revision.
70    ///
71    unsigned int comments(const std::string& user="all") const; 
72
73    ///
74    /// \return number of empty lines for \a user for latest revision.
75    ///
76    unsigned int empty(const std::string& user="all") const; 
77
78    ///
79    /// \return revison node was modified
80    ///
81    svn_revnum_t last_changed_rev(void) const;
82
83    ///
84    /// \return number of lines for \a user for latest revision
85    ///
86    unsigned int lines(const std::string& user="all") const; 
87
88    /**
89       Load object from a stream.
90
91       \a latest_ver is set to true if cache_file is latest version;
92       otherwise it is set to false.
93
94       \return revision the cache represents - 0 if failed
95     */
96    svn_revnum_t load_cache(std::istream&, bool& latest_ver);
97
98    /**
99       Do the parsing for \a path. Revisions from \a rev will be parsed.
100    */
101    void parse(const std::string& path, svn_revnum_t rev=0);
102
103    /**
104       Send Stats to a stream.
105     */
106    void print(std::ostream&) const;
107
108    ///
109    /// @brief Clear all statistics
110    ///
111    void reset(void); 
112
113    /**
114       set vectors in stats_ to size \a rev
115    */
116    void resize(svn_revnum_t rev);
117
118    ///
119    /// \return latest revision for whole project
120    ///
121    svn_revnum_t revision(void) const;
122
123    /**
124       \return resulting Stats
125    */
126    Stats& operator+=(const Stats&);
127
128    /**
129       \return number of lines for \a author and \a linetype from
130       revision \a rev.
131
132       \throw if \a author does not exist
133     */
134    size_t operator()(int linetype, std::string author, svn_revnum_t rev) const;
135
136  protected:
137    typedef std::map<std::string, SumVector> Author2Vector;
138    typedef Author2Vector::iterator A2VIter;
139    typedef Author2Vector::const_iterator A2VConstIter;
140
141    std::vector<Author2Vector> stats_; // from linetype to a2v
142
143    /**
144     */
145    void add(const std::vector<std::map<std::string, SparseVector> >& data);
146
147    /**
148       Calculate accumalated statistics for fundamental statistics,
149       i.e., code, comment, empty, and copyright for each author.
150       \see accumulate
151     */
152    //    void accumulate_stats(svn_revnum_t rev=1);
153    void add_author(std::string);
154    void add_authors(std::set<std::string>::const_iterator, 
155                     std::set<std::string>::const_iterator);
156
157    // references to data
158    inline Author2Vector& code_stats(void) 
159    { return stats_[LineTypeParser::code]; }
160    inline Author2Vector& comment_stats(void) 
161    { return stats_[LineTypeParser::comment]; }
162    inline Author2Vector& copyright_stats(void) 
163    { return stats_[LineTypeParser::copyright]; }
164    inline Author2Vector& other_stats(void) 
165    { return stats_[LineTypeParser::other]; }
166    inline Author2Vector& comment_or_copy_stats(void) 
167    { return stats_[LineTypeParser::comment_or_copy]; }
168    inline Author2Vector& total_stats(void) 
169    { return stats_[LineTypeParser::total]; }
170
171    // const references to data
172    inline const Author2Vector& code_stats(void) const
173    { return stats_[LineTypeParser::code]; }
174    inline const Author2Vector& comment_stats(void) const
175    { return stats_[LineTypeParser::comment]; }
176    inline const Author2Vector& copyright_stats(void) const
177    { return stats_[LineTypeParser::copyright]; }
178    inline const Author2Vector& other_stats(void) const
179    { return stats_[LineTypeParser::other]; }
180    inline const Author2Vector& comment_or_copy_stats(void) const
181    { return stats_[LineTypeParser::comment_or_copy]; }
182    inline const Author2Vector& total_stats(void) const
183    { return stats_[LineTypeParser::total]; }
184
185    /**
186       add range [\a first, \a last) to \a map
187     */
188    void map_add(Author2Vector::const_iterator first, 
189                 Author2Vector::const_iterator last,
190                 Author2Vector& map);
191
192    std::set<std::string> authors_;
193
194    const SumVector& get_vector(const Author2Vector&, 
195                                const std::string& user) const;
196  private:
197    /// one liner used in cache file to validate that cache file was
198    /// created current configuration
199    std::string config_code_;
200
201    void add(SumVector& vec, svn_revnum_t rev, unsigned int n);
202
203    /**
204       Parse statistics for fundamental categories, i.e., code,
205       comment, empty, and copyright for each author. Ignore revisions
206       earlier than \a first_rev.
207     */
208    virtual void do_parse(const std::string&, svn_revnum_t first_rev)=0;
209   
210    /// load cache file version 7
211    svn_revnum_t load_cache7(std::istream&);
212    /// load cache file version 8
213    svn_revnum_t load_cache8(std::istream&);
214
215    // Change this string if cache format is changed in such a way
216    // that all old cache files are obsolete.
217    inline std::string cache_check_str(void) const 
218    {return "CACHE FILE VERSION 7";} 
219
220    void calc_all(void);
221    void calc_comment_or_copy(void);
222    void calc_total(void);
223    unsigned int get_back(const Author2Vector&, std::string user) const;
224    void load(std::istream& is, Author2Vector& m);
225    /**
226       Finds the largets element by iterating through the entire
227       vector. Inherited classes should implement their own version
228       when it is possible to get the largest element in faster than
229       in linear time.
230
231       \return the largest largest element in \a v.
232    */
233    virtual unsigned int max_element(const SumVector& v) const; 
234
235    void print(std::ostream& os, const Author2Vector& m) const;
236
237    svn_revnum_t revision_; // Should be the latest revision for whole project
238    svn_revnum_t last_changed_rev_; // Should be the latest revision for file
239
240    // using compiler generated copy constructor
241    //Stats(const Stats&);
242    // no assignment
243    Stats& operator=(const Stats&);
244
245    friend class StatsPlotter;
246  };
247}} // end of namespace svndigest end of namespace theplu
248
249#endif
Note: See TracBrowser for help on using the repository browser.