source: trunk/lib/TinyStats.cc @ 1256

Last change on this file since 1256 was 1256, checked in by Peter Johansson, 12 years ago

remove debug output, and let test check that there is messages sent to standard error.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.5 KB
Line 
1// $Id: TinyStats.cc 1256 2010-11-01 04:33:42Z 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    size_t max_lt = LineTypeParser::total;
52    typedef std::map<std::string, Stats*> StatsMap;
53    const StatsMap& stats_map = sc.stats();
54    for (StatsMap::const_iterator i = stats_map.begin();i!=stats_map.end();++i){
55      const std::string& stats_type = i->first;
56      const Stats& stats = *(i->second);
57      std::map<std::string, Vector>& m = data_[stats_type];
58      // loop over authors
59      for (std::set<std::string>::const_iterator author=stats.authors().begin();
60           author != stats.authors().end(); ++author) {
61        Vector& v = m[*author];
62        v.resize(max_lt+1, 0);
63        v[LineTypeParser::total] = stats.lines(*author);
64        v[LineTypeParser::code] = stats.code(*author);
65        v[LineTypeParser::comment] = stats.comments(*author);
66        v[LineTypeParser::other] = stats.empty(*author);
67        assert((*this)(stats_type, *author, LineTypeParser::total)==
68               stats.lines(*author));
69      }
70      Vector& v = m["all"];
71      v.resize(max_lt+1, 0);
72      v[LineTypeParser::total] = stats.lines();
73      v[LineTypeParser::code] = stats.code();
74      v[LineTypeParser::comment] = stats.comments();
75      v[LineTypeParser::other] = stats.empty();
76    }
77  }
78
79}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.