source: trunk/lib/StatsCollection.cc @ 687

Last change on this file since 687 was 687, checked in by Peter Johansson, 13 years ago

Merged patch release 0.6.6 to trunk. Delta 0.6.6 - 0.6.5

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.0 KB
Line 
1// $Id: StatsCollection.cc 687 2008-08-04 19:37:10Z peter $
2
3/*
4  Copyright (C) 2007 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 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      svn_revnum_t cache_rev = i->second->load_cache(is);
66      if (cache_rev < i->second->revision()) {
67        result = false;
68        // reset if load cache failed
69        if (!cache_rev)
70          i->second->reset();
71        i->second->parse(path_, cache_rev);
72      }
73    }
74    return result;
75  }
76
77
78  const std::map<std::string, Stats*>& StatsCollection::stats(void) const
79  {
80    return stats_;
81  }
82
83
84  void StatsCollection::parse(const std::string& path)
85  {
86    for (map::iterator i(stats_.begin()); i!=stats_.end(); ++i) {
87      i->second->parse(path);
88    }
89  }
90
91
92  void StatsCollection::print(std::ostream& os)
93  {
94    for (map::const_iterator i(stats_.begin()); i!=stats_.end(); ++i) {
95      i->second->print(os);
96    }
97  }
98
99
100  void StatsCollection::reset(void)
101  {
102    for (map::const_iterator i(stats_.begin()); i!=stats_.end(); ++i) {
103      i->second->reset();
104    }
105  }
106
107
108  const StatsCollection& StatsCollection::operator+=(const StatsCollection& rhs)
109  {
110    assert(stats_.size()==rhs.stats_.size());
111    for (map::const_iterator i(stats_.begin()); i!=stats_.end(); ++i) {
112      *(i->second) += rhs[i->first];
113    }
114    return *this;
115  }
116
117
118  const Stats& StatsCollection::operator[](const std::string& key) const
119  {
120    map::const_iterator iter = stats_.find(key);
121    if (iter==stats_.end())
122      throw std::runtime_error(key + 
123                               std::string(" not found in StatsCollection"));
124    return *(iter->second);
125  }
126
127
128  Stats& StatsCollection::operator[](const std::string& key)
129  {
130    assert(stats_.find(key)!=stats_.end());
131    return *(stats_[key]);
132  }
133
134
135}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.