source: trunk/lib/StatsCollection.cc @ 533

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

Adding a BlameStats to the StatsCollection?. Though BlameStats is not yet implemented but goes as a dummie (read ClassicStats?)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.9 KB
Line 
1// $Id: StatsCollection.cc 533 2007-12-26 02:07:46Z 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  const StatsCollection& 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    return *this;
85  }
86
87
88  void StatsCollection::print(std::ostream& os)
89  {
90    for (map::const_iterator i(stats_.begin()); i!=stats_.end(); ++i) {
91      i->second->print(os);
92    }
93  }
94
95
96  void StatsCollection::reset(void)
97  {
98    for (map::const_iterator i(stats_.begin()); i!=stats_.end(); ++i) {
99      i->second->reset();
100    }
101  }
102
103
104  const StatsCollection& StatsCollection::operator+=(const StatsCollection& rhs)
105  {
106    assert(stats_.size()==rhs.stats_.size());
107    for (map::const_iterator i(stats_.begin()); i!=stats_.end(); ++i) {
108      *(i->second) += rhs[i->first];
109    }
110    return *this;
111  }
112
113
114  const Stats& StatsCollection::operator[](const std::string& key) const
115  {
116    map::const_iterator iter = stats_.find(key);
117    if (iter==stats_.end())
118      throw std::runtime_error(key + 
119                               std::string(" not found in StatsCollection"));
120    return *(iter->second);
121  }
122
123
124  Stats& StatsCollection::operator[](const std::string& key)
125  {
126    assert(stats_.find(key)!=stats_.end());
127    return *(stats_[key]);
128  }
129
130
131}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.