source: trunk/lib/StatsCollection.cc @ 543

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

AddStats - number of added lines is counted - fixes ticket:82

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.9 KB
Line 
1// $Id: StatsCollection.cc 543 2008-01-04 02:10:54Z peter $
2
3/*
4  Copyright (C) 2007 Peter Johansson
5
6  This file is part of svndigest, http://trac.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 2 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 this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#include "StatsCollection.h"
25
26#include "AddStats.h"
27#include "BlameStats.h"
28#include "ClassicStats.h"
29#include "Stats.h"
30
31#include <cassert>
32#include <map>
33#include <stdexcept>
34#include <string>
35
36#include <iostream>
37
38namespace theplu{
39namespace svndigest{
40
41
42  StatsCollection::StatsCollection(const std::string& path)
43    : path_(path)
44  {
45    stats_["classic"] = new ClassicStats(path);
46    stats_["blame"] = new BlameStats(path);
47    stats_["add"] = new AddStats(path);
48  }
49
50
51  StatsCollection::~StatsCollection(void)
52  {
53    for (map::const_iterator i(stats_.begin()); i!=stats_.end(); ++i) {
54      assert(i->second);
55      delete i->second;
56    }
57
58  }
59
60
61  bool StatsCollection::load_cache(std::istream& is)
62  {
63    bool result = true;
64    for (map::const_iterator i(stats_.begin()); i!=stats_.end(); ++i) {
65      if(!i->second->load_cache(is)){
66        result = false;
67        i->second->reset();
68        i->second->parse(path_);
69      }
70    }
71    return result;
72  }
73
74
75  const std::map<std::string, Stats*>& StatsCollection::stats(void) const
76  {
77    return stats_;
78  }
79
80
81  void StatsCollection::parse(const std::string& path)
82  {
83    for (map::iterator i(stats_.begin()); i!=stats_.end(); ++i) {
84      i->second->parse(path);
85    }
86  }
87
88
89  void StatsCollection::print(std::ostream& os)
90  {
91    for (map::const_iterator i(stats_.begin()); i!=stats_.end(); ++i) {
92      i->second->print(os);
93    }
94  }
95
96
97  void StatsCollection::reset(void)
98  {
99    for (map::const_iterator i(stats_.begin()); i!=stats_.end(); ++i) {
100      i->second->reset();
101    }
102  }
103
104
105  const StatsCollection& StatsCollection::operator+=(const StatsCollection& rhs)
106  {
107    assert(stats_.size()==rhs.stats_.size());
108    for (map::const_iterator i(stats_.begin()); i!=stats_.end(); ++i) {
109      *(i->second) += rhs[i->first];
110    }
111    return *this;
112  }
113
114
115  const Stats& StatsCollection::operator[](const std::string& key) const
116  {
117    map::const_iterator iter = stats_.find(key);
118    if (iter==stats_.end())
119      throw std::runtime_error(key + 
120                               std::string(" not found in StatsCollection"));
121    return *(iter->second);
122  }
123
124
125  Stats& StatsCollection::operator[](const std::string& key)
126  {
127    assert(stats_.find(key)!=stats_.end());
128    return *(stats_[key]);
129  }
130
131
132}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.