Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Directory.cc
r10 r14 58 58 59 59 60 boolDirectory::parse(void)60 const Stats& Directory::parse(void) 61 61 { 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_; 65 69 } 66 70 -
trunk/lib/Directory.h
r10 r14 27 27 ~Directory(void); 28 28 29 boolparse(void);29 const Stats& parse(void); 30 30 31 31 void print(void); -
trunk/lib/File.cc
r10 r14 3 3 #include "File.h" 4 4 #include "Node.h" 5 #include "Stats.h" 5 6 6 7 #include <fstream> … … 22 23 } 23 24 24 boolFile::parse(void)25 const Stats& File::parse(void) 25 26 { 27 // calling svn info 28 info(); 29 stats_.reset(); 26 30 if (binary_){ 27 add(author_,revision_);28 return true;31 stats_.add(author_,revision_); 32 return stats_; 29 33 } 30 34 31 35 // Calling svn blame 32 36 if (!blame()) 33 return false;37 return stats_; 34 38 35 39 // Check if file is binary … … 56 60 ss >> revision; 57 61 ss >> user; 58 add(user, revision);62 stats_.add(user, revision); 59 63 } 60 64 is.close(); 61 return true;65 return stats_; 62 66 } 63 67 -
trunk/lib/File.h
r10 r14 26 26 /// @return true if succesful 27 27 /// 28 boolparse(void);28 const Stats& parse(void); 29 29 30 30 void print(void); -
trunk/lib/Node.cc
r13 r14 12 12 namespace theplu{ 13 13 namespace svnstat{ 14 15 std::vector<u_int> Node::accumulated(void) const16 {17 std::vector<u_int> sum(revision_,0);18 if (stats_.empty())19 return sum;20 21 // sum of all users22 sum = std::accumulate(stats_.begin(),stats_.end(), sum,23 VectorPlus<std::string,u_int>());24 25 // calculate accumulated sum26 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 else52 vec[rev]++;53 stats_[user]=vec;54 }55 14 56 15 bool Node::info() -
trunk/lib/Node.h
r13 r14 3 3 #ifndef _theplu_svnstat_node_ 4 4 #define _theplu_svnstat_node_ 5 6 #include "Stats.h" 5 7 6 8 #include <map> … … 28 30 29 31 /// 30 /// @return accumulated vector of total31 ///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 stats41 ///42 void add(const std::string& user, const u_int& revision);43 44 ///45 32 /// @brief parsing file using svn blame. 46 33 /// 47 virtual boolparse(void)=0;34 virtual const Stats& parse(void)=0; 48 35 49 36 /// … … 70 57 std::string path_; 71 58 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_; 74 60 std::string uuid_; 75 61 -
trunk/lib/utility.h
r7 r14 13 13 14 14 /// 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. 21 16 /// 22 17 /// @return resulting vector 23 /// @note if size of arg.second is larger than size of sum_so_far, the24 /// result is undefined.25 18 /// 26 template <class Key, classT >19 template <class T > 27 20 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> > 34 22 { 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 } 43 39 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 }; 45 57 }} 46 58
Note: See TracChangeset
for help on using the changeset viewer.