source: trunk/lib/StatsCollection.cc @ 538

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

added ignore-cache option

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