source: trunk/lib/Node.cc @ 10

Last change on this file since 10 was 9, checked in by Jari Häkkinen, 17 years ago

Started work with reading file structure.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.9 KB
Line 
1// $Id: Node.cc 9 2005-12-30 08:24:00Z jari $
2
3#include "Node.h"
4#include "utility.h"
5
6#include <fstream>
7#include <iostream>
8#include <numeric>
9#include <sstream>
10#include <vector>
11
12namespace theplu{
13namespace svnstat{
14
15  std::vector<u_int> Node::accumulated(void) const
16  {
17    std::vector<u_int> sum(revision_,0);
18    if (stats_.empty())
19      return sum;
20
21    // sum of all users
22    sum = std::accumulate(stats_.begin(),stats_.end(), sum, 
23        VectorPlus<std::string,u_int>());
24
25    // calculate accumulated sum
26    std::vector<u_int> accum(sum.size());
27    std::partial_sum(sum.begin(),sum.end(),accum.begin());   
28    return accum;
29  }
30
31  std::vector<u_int> Node::accumulated(const std::string& user)
32  {
33    std::vector<u_int> vec=stats_[user];
34    if (vec.empty())
35      return vec;
36    std::vector<u_int> accum(vec.size());
37    std::partial_sum(vec.begin(),vec.end(),accum.begin());
38    return accum;
39  }
40
41  void Node::add(const std::string& user, const u_int& rev)
42  {
43    std::vector<u_int> vec = stats_[user];
44    if (vec.size() < rev+1){
45      u_int i=vec.size();
46      vec.resize(rev+1);
47      for (; i<rev; i++)
48        vec[i]=0;
49      vec[rev]=1;
50    }
51    else
52      vec[rev]++;
53    stats_[user]=vec;
54  }
55
56  bool Node::info()
57  {
58    std::string system_call = "svn info " + path_ + " > svnstat.tmp";
59    int system_return = system(system_call.c_str());
60    if (system_return){
61      std::cerr << "Error: svn info " << path_ << std::endl;     
62      return false;
63    }
64    std::ifstream is("svnstat.tmp");
65    std::string line;
66    while (getline(is,line)){
67      std::stringstream ss(line);
68      std::string tag;
69      getline(ss,tag,':');
70      if (tag == std::string("Repository UUID"))
71        ss >> uuid_; 
72      else if (tag == std::string("Last Changed Author"))
73        ss >> author_;
74      else if (tag == std::string("Last Changed Rev"))
75        ss >> revision_;
76    }
77   
78    return true;
79  }
80
81}} // end of namespace svnstat and namespace theplu
Note: See TracBrowser for help on using the repository browser.