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