source: trunk/lib/StatsCollection.cc @ 796

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

refs #338 - turning on cache again, but not only for files being up to date. Incomplete caches is ignored and the file is completely re-parsed from svn repo.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.0 KB
Line 
1// $Id: StatsCollection.cc 752 2009-01-14 12:48:18Z 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 3 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 svndigest. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include "StatsCollection.h"
23
24#include "AddStats.h"
25#include "BlameStats.h"
26#include "ClassicStats.h"
27#include "Stats.h"
28
29#include <cassert>
30#include <map>
31#include <stdexcept>
32#include <string>
33
34#include <iostream>
35
36namespace theplu{
37namespace svndigest{
38
39
40  StatsCollection::StatsCollection(const std::string& path)
41    : path_(path)
42  {
43    stats_["classic"] = new ClassicStats(path);
44    stats_["blame"] = new BlameStats(path);
45    stats_["add"] = new AddStats(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      svn_revnum_t cache_rev = i->second->load_cache(is);
64      if (cache_rev < i->second->last_changed_rev()) {
65        cache_rev=0; // tmp hack to avoid partial cache
66        result = false;
67        // reset if load cache failed
68        if (!cache_rev)
69          i->second->reset();
70        i->second->parse(path_, cache_rev+1);
71      }
72    }
73    return result;
74  }
75
76
77  const std::map<std::string, Stats*>& StatsCollection::stats(void) const
78  {
79    return stats_;
80  }
81
82
83  void StatsCollection::parse(const std::string& path)
84  {
85    for (map::iterator i(stats_.begin()); i!=stats_.end(); ++i) {
86      i->second->parse(path);
87    }
88  }
89
90
91  void StatsCollection::print(std::ostream& os)
92  {
93    for (map::const_iterator i(stats_.begin()); i!=stats_.end(); ++i) {
94      i->second->print(os);
95    }
96  }
97
98
99  void StatsCollection::reset(void)
100  {
101    for (map::const_iterator i(stats_.begin()); i!=stats_.end(); ++i) {
102      i->second->reset();
103    }
104  }
105
106
107  const StatsCollection& StatsCollection::operator+=(const StatsCollection& rhs)
108  {
109    assert(stats_.size()==rhs.stats_.size());
110    for (map::const_iterator i(stats_.begin()); i!=stats_.end(); ++i) {
111      *(i->second) += rhs[i->first];
112    }
113    return *this;
114  }
115
116
117  const Stats& StatsCollection::operator[](const std::string& key) const
118  {
119    map::const_iterator iter = stats_.find(key);
120    if (iter==stats_.end())
121      throw std::runtime_error(key + 
122                               std::string(" not found in StatsCollection"));
123    return *(iter->second);
124  }
125
126
127  Stats& StatsCollection::operator[](const std::string& key)
128  {
129    assert(stats_.find(key)!=stats_.end());
130    return *(stats_[key]);
131  }
132
133
134}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.