Changeset 14 for trunk/lib


Ignore:
Timestamp:
Dec 30, 2005, 3:57:47 PM (16 years ago)
Author:
Peter Johansson
Message:

adding Stats class and removed pointer from node to its mother(dir), which enforced some changes here and there

Location:
trunk/lib
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Directory.cc

    r10 r14  
    5858
    5959
    60   bool Directory::parse(void)
     60  const Stats& Directory::parse(void)
    6161  {
    62     // Jari, where is the include for for_each?
    63     for_each(daughters_.begin(),daughters_.end(), std::mem_fun(&Node::parse));
    64     return true;
     62    // calling svn info;
     63    info();
     64    stats_.reset();
     65
     66    for (size_t i = 0; i<daughters_.size(); i++)
     67      stats_ += daughters_[i]->parse();
     68    return stats_;
    6569  }
    6670
  • trunk/lib/Directory.h

    r10 r14  
    2727    ~Directory(void);
    2828
    29     bool parse(void);
     29    const Stats& parse(void);
    3030
    3131    void print(void);
  • trunk/lib/File.cc

    r10 r14  
    33#include "File.h"
    44#include "Node.h"
     5#include "Stats.h"
    56
    67#include <fstream>
     
    2223  }
    2324
    24   bool File::parse(void)
     25  const Stats& File::parse(void)
    2526  {
     27    // calling svn info
     28    info();
     29    stats_.reset();
    2630    if (binary_){
    27       add(author_,revision_);
    28       return true;
     31      stats_.add(author_,revision_);
     32      return stats_;
    2933    }
    3034
    3135    // Calling svn blame
    3236    if (!blame())
    33       return false;
     37      return stats_;
    3438
    3539    // Check if file is binary
     
    5660      ss >> revision;
    5761      ss >> user;
    58       add(user, revision);
     62      stats_.add(user, revision);
    5963    }
    6064    is.close();
    61     return true;
     65    return stats_;
    6266  }
    6367
  • trunk/lib/File.h

    r10 r14  
    2626    /// @return true if succesful
    2727    ///
    28     bool parse(void);
     28    const Stats& parse(void);
    2929
    3030    void print(void);
  • trunk/lib/Node.cc

    r13 r14  
    1212namespace theplu{
    1313namespace 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   }
    5514
    5615  bool Node::info()
  • trunk/lib/Node.h

    r13 r14  
    33#ifndef _theplu_svnstat_node_
    44#define _theplu_svnstat_node_
     5
     6#include "Stats.h"
    57
    68#include <map>
     
    2830
    2931    ///
    30     /// @return accumulated vector of total
    31     ///
    32     std::vector<u_int> accumulated(void) const;
    33 
    34     ///
    35     /// @return accumulated vector of stats_[user]
    36     ///
    37     std::vector<u_int> accumulated(const std::string& user);
    38 
    39     ///
    40     /// @brief adding a line to user from revision to the stats
    41     ///
    42     void add(const std::string& user, const u_int& revision);
    43 
    44     ///
    4532    /// @brief parsing file using svn blame.
    4633    ///
    47     virtual bool parse(void)=0;
     34    virtual const Stats& parse(void)=0;
    4835
    4936    ///
     
    7057    std::string path_;
    7158    u_int revision_;
    72     // Peter, if the vector is sparse make it a map
    73     std::map<std::string, std::vector<u_int> > stats_;
     59    Stats stats_;
    7460    std::string uuid_;
    7561
  • trunk/lib/utility.h

    r7 r14  
    1313
    1414  ///
    15   /// A resulting vector is calculated as sum of the value of arg
    16   /// and vector sum_so_far. Each element in value of arg is added to the
    17   /// corresponded element in sum_so_far. The size of resulting vector is
    18   /// equal to size of sum_so_far. For elements not having a corresponding
    19   /// element in vector arg, the element in resulting vector is taken to 
    20   /// be equal to element in sum_so_far.
     15  /// Calculating sum of two vectors.
    2116  ///
    2217  /// @return resulting vector
    23   /// @note if size of arg.second is larger than size of sum_so_far, the
    24   /// result is undefined.
    2518  ///
    26   template <class Key, class T >
     19  template <class T >
    2720    struct VectorPlus :
    28   public std::binary_function< std::pair<const Key,std::vector<T> >,
    29     std::vector<T>, std::vector<T> >
    30   {
    31     std::vector<T> operator()
    32       (std::vector<T>& sum_so_far,
    33        const std::pair<const Key, std::vector<T> >& arg) const
     21  public std::binary_function<std::vector<T>,std::vector<T>,std::vector<T> >
    3422    {
    35       std::vector<T> res(sum_so_far.size());
    36       transform(arg.second.begin(),arg.second.end(),sum_so_far.begin(),
    37     res.begin(), std::plus<T>());
    38       if (sum_so_far.size() > arg.second.size())
    39   copy(sum_so_far.begin()+arg.second.size(),sum_so_far.end(),
    40        res.begin()+arg.second.size());
    41       return res;
    42     }
     23      std::vector<T> operator()(const std::vector<T>& u,
     24        const std::vector<T>& v) const
     25      {
     26  if ( u.size() > v.size() ){
     27    std::vector<T> res(u.size());
     28    transform(u.begin(), u.end(), v.begin(), res.begin(), std::plus<T>());
     29    copy(u.begin()+v.size(), u.end(), res.begin()+v.size());
     30    return res;
     31  }
     32 
     33  std::vector<T> res(v.size());
     34  transform(v.begin(), v.end(), u.begin(), res.begin(), std::plus<T>());
     35  if ( v.size() > u.size() )
     36    copy(u.begin()+v.size(), u.end(), res.begin()+v.size());
     37  return res;
     38      }
    4339
    44   };
     40    };
     41
     42  ///
     43  /// @return resulting vector
     44  ///
     45  template <class Key, class T>
     46    struct PairValuePlus :
     47  public std::binary_function<std::vector<T>,
     48    std::pair<const Key, std::vector<T> >,
     49    std::vector<T> >
     50    {
     51      std::vector<T> operator()(const std::vector<T>& sum,
     52        const std::pair<const Key,std::vector<T> >& p)
     53      {
     54  return VectorPlus<T>()(sum, p.second);
     55      }
     56    };
    4557}}
    4658
Note: See TracChangeset for help on using the changeset viewer.