source: trunk/lib/TinyStats.cc @ 1234

Last change on this file since 1234 was 1234, checked in by Peter Johansson, 13 years ago

refs #476. Merged visitor branch into trunk. Used 'svn merge /branches/visitor' because --reintegrate did (currently) not work on our repo. Since I could not merge as suggested in subversion manual, I reverted all mergeinfo properties to avoid future confusion by svn-client. This means (I think) that there will be no connection about this commit and the visitor branch, but to svn-client this will look like a large changeset (just like a merge in the old days).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.6 KB
Line 
1// $Id: TinyStats.cc 1234 2010-10-23 16:41:33Z peter $
2
3/*
4  Copyright (C) 2010 Peter Johansson
5
6  This file is part of svndigest, http://dev.thep.lu.se/svndigest
7
8  svndigest is free software; you can redistribute it and/or modify it
9  under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12
13  svndigest is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with svndigest. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include "TinyStats.h"
23
24#include "LineTypeParser.h"
25#include "Stats.h"
26#include "StatsCollection.h"
27
28#include <cassert>
29#include <map>
30#include <string>
31
32namespace theplu{
33namespace svndigest{
34
35  unsigned int TinyStats::operator()(const std::string& stats_type,
36                                     const std::string& user,
37                                     LineTypeParser::line_type lt) const
38  {
39    std::map<std::string, Map>::const_iterator i = data_.find(stats_type);
40    assert (i!=data_.end());
41    Map::const_iterator j = i->second.find(user);
42    if (j==i->second.end())
43      return 0;
44    assert(lt < j->second.size());
45    return j->second[lt];
46  }
47
48
49  void TinyStats::init(const StatsCollection& sc)
50  {
51    std::cerr << "init\n";
52    size_t max_lt = LineTypeParser::total;
53    typedef std::map<std::string, Stats*> StatsMap;
54    const StatsMap& stats_map = sc.stats();
55    for (StatsMap::const_iterator i = stats_map.begin();i!=stats_map.end();++i){
56      const std::string& stats_type = i->first;
57      std::cerr << stats_type << std::endl;
58      const Stats& stats = *(i->second);
59      std::map<std::string, Vector>& m = data_[stats_type];
60      // loop over authors
61      for (std::set<std::string>::const_iterator author=stats.authors().begin();
62           author != stats.authors().end(); ++author) {
63        std::cerr << "author: " << *author << std::endl;
64        Vector& v = m[*author];
65        v.resize(max_lt+1, 0);
66        v[LineTypeParser::total] = stats.lines(*author);
67        v[LineTypeParser::code] = stats.code(*author);
68        v[LineTypeParser::comment] = stats.comments(*author);
69        v[LineTypeParser::other] = stats.empty(*author);
70        assert((*this)(stats_type, *author, LineTypeParser::total)==
71               stats.lines(*author));
72      }
73      Vector& v = m["all"];
74      v.resize(max_lt+1, 0);
75      v[LineTypeParser::total] = stats.lines();
76      v[LineTypeParser::code] = stats.code();
77      v[LineTypeParser::comment] = stats.comments();
78      v[LineTypeParser::other] = stats.empty();
79    }
80  }
81
82}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.